mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-08 18:45:33 +08:00
fix typescript errors and update dependencies
This commit is contained in:
@@ -10,6 +10,8 @@ interface UpdatesRequestBody {
|
||||
source?: string
|
||||
}
|
||||
|
||||
type NotificationDataEntry = [string, ...unknown[]]
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<UpdatesRequestBody>(event)
|
||||
const email = body.email?.trim().toLowerCase()
|
||||
@@ -38,7 +40,7 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
|
||||
if (result.created) {
|
||||
const dataEntries = [
|
||||
const dataEntries: NotificationDataEntry[] = [
|
||||
['Email', email],
|
||||
['Name', name || null],
|
||||
['Source', source],
|
||||
|
||||
@@ -13,6 +13,8 @@ interface WaitlistRequestBody {
|
||||
wantsProductUpdates?: boolean
|
||||
}
|
||||
|
||||
type NotificationDataEntry = [string, ...unknown[]]
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<WaitlistRequestBody>(event)
|
||||
const email = body.email?.trim().toLowerCase()
|
||||
@@ -57,7 +59,7 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
|
||||
if (!previouslyWantedUpdates && updateResult.created) {
|
||||
const dataEntries = [
|
||||
const dataEntries: NotificationDataEntry[] = [
|
||||
['Email', email],
|
||||
]
|
||||
if (name) {
|
||||
@@ -107,7 +109,7 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
}
|
||||
|
||||
const dataEntries = [
|
||||
const dataEntries: NotificationDataEntry[] = [
|
||||
['Email', email],
|
||||
]
|
||||
if (name) {
|
||||
@@ -132,4 +134,3 @@ export default defineEventHandler(async (event) => {
|
||||
joinedAt: entry.joinedAt,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineEventHandler } from 'h3'
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
return await $fetch('https://data.vatsim.net/v3/vatsim-data.json')
|
||||
const fetcher = (globalThis as any).$fetch as (url: string, options?: Record<string, unknown>) => Promise<unknown>
|
||||
return await fetcher('https://data.vatsim.net/v3/vatsim-data.json')
|
||||
})
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import {defineEventHandler, getRouterParam} from 'h3'
|
||||
import { createError, defineEventHandler, getQuery } from 'h3'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const {cid} = getQuery(event)
|
||||
if (!cid) throw createError({statusCode: 400, statusMessage: 'cid required'})
|
||||
const query = getQuery(event)
|
||||
const rawCid = Array.isArray(query.cid) ? query.cid[0] : query.cid
|
||||
if (rawCid === undefined || rawCid === null) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'cid required' })
|
||||
}
|
||||
const cid = String(rawCid).trim()
|
||||
if (!cid) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'cid required' })
|
||||
}
|
||||
|
||||
const url = `https://api.vatsim.net/v2/members/${encodeURIComponent(cid)}/flightplans`
|
||||
return await $fetch(url, {method: 'GET'})
|
||||
const fetcher = (globalThis as any).$fetch as (target: string, options?: Record<string, unknown>) => Promise<unknown>
|
||||
return await fetcher(url, { method: 'GET' })
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ import type {
|
||||
|
||||
export interface DecisionNodeDocument
|
||||
extends mongoose.Document,
|
||||
Omit<DecisionNodeModel, 'stateId' | 'transitions'> {
|
||||
Omit<DecisionNodeModel, 'stateId' | 'transitions' | 'createdAt' | 'updatedAt'> {
|
||||
flow: mongoose.Types.ObjectId
|
||||
stateId: string
|
||||
transitions: DecisionNodeTransition[]
|
||||
@@ -175,7 +175,7 @@ const decisionNodeSchema = new mongoose.Schema<DecisionNodeDocument>(
|
||||
elseSayTemplate: { type: String },
|
||||
readbackRequired: { type: [String], default: () => [] },
|
||||
autoBehavior: { type: String },
|
||||
actions: { type: [mongoose.Schema.Types.Mixed], default: () => [] },
|
||||
actions: { type: [mongoose.Schema.Types.Mixed], default: () => [] } as any,
|
||||
handoff: {
|
||||
type: new mongoose.Schema(
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
DecisionFlowModel,
|
||||
DecisionFlowSummary,
|
||||
DecisionNodeModel,
|
||||
DecisionNodeRole,
|
||||
DecisionNodeTransition,
|
||||
RuntimeDecisionAutoTransition,
|
||||
RuntimeDecisionState,
|
||||
@@ -12,6 +13,10 @@ import type {
|
||||
RuntimeDecisionSystem,
|
||||
} from '~~/shared/types/decision'
|
||||
|
||||
const DECISION_NODE_ROLES: DecisionNodeRole[] = ['pilot', 'atc', 'system']
|
||||
const isDecisionNodeRole = (value: unknown): value is DecisionNodeRole =>
|
||||
typeof value === 'string' && DECISION_NODE_ROLES.includes(value as DecisionNodeRole)
|
||||
|
||||
export function serializeFlowDocument(doc: DecisionFlowDocument, nodeCount = 0): DecisionFlowModel {
|
||||
return {
|
||||
id: String(doc._id),
|
||||
@@ -25,7 +30,7 @@ export function serializeFlowDocument(doc: DecisionFlowDocument, nodeCount = 0):
|
||||
flags: doc.flags || {},
|
||||
policies: doc.policies || {},
|
||||
hooks: doc.hooks || {},
|
||||
roles: Array.isArray(doc.roles) ? doc.roles : [],
|
||||
roles: Array.isArray(doc.roles) ? doc.roles.filter(isDecisionNodeRole) : [],
|
||||
phases: Array.isArray(doc.phases) ? doc.phases : [],
|
||||
layout: doc.layout || undefined,
|
||||
metadata: doc.metadata || undefined,
|
||||
@@ -206,7 +211,7 @@ async function buildRuntimeTreeForDoc(
|
||||
flags: flowDoc.flags || {},
|
||||
policies: flowDoc.policies || {},
|
||||
hooks: flowDoc.hooks || {},
|
||||
roles: Array.isArray(flowDoc.roles) ? flowDoc.roles : [],
|
||||
roles: Array.isArray(flowDoc.roles) ? flowDoc.roles.filter(isDecisionNodeRole) : [],
|
||||
phases: Array.isArray(flowDoc.phases) ? flowDoc.phases : [],
|
||||
states,
|
||||
entry_mode: flowDoc.isMain ? 'main' : flowDoc.entryMode || 'parallel',
|
||||
|
||||
@@ -203,7 +203,8 @@ export function sanitizeAutoTrigger(raw: any): DecisionNodeAutoTrigger | undefin
|
||||
} else if (normalizedType === 'variable') {
|
||||
trigger.variable = asTrimmedString(payload.variable) ?? ''
|
||||
trigger.operator = asComparisonOperatorValue(payload.operator)
|
||||
trigger.value = asVariableValue(payload.value, '')
|
||||
const variableValue = asVariableValue(payload.value, '')
|
||||
trigger.value = typeof variableValue === 'boolean' ? String(variableValue) : variableValue
|
||||
}
|
||||
|
||||
trigger.once = asBoolean(payload.once, true)
|
||||
|
||||
@@ -42,7 +42,7 @@ const ACK = createState({
|
||||
name: 'Acknowledge',
|
||||
summary: 'Acknowledge pilot readback',
|
||||
triggers: [
|
||||
{ type: 'regex', pattern: 'roger', patternFlags: 'i' },
|
||||
{ id: 'ack-regex', type: 'regex', pattern: 'roger', patternFlags: 'i' },
|
||||
],
|
||||
})
|
||||
|
||||
@@ -50,7 +50,7 @@ const TAXI = createState({
|
||||
name: 'Taxi clearance',
|
||||
summary: 'Pilot requesting taxi clearance',
|
||||
triggers: [
|
||||
{ type: 'regex', pattern: 'request', patternFlags: 'i' },
|
||||
{ id: 'taxi-regex', type: 'regex', pattern: 'request', patternFlags: 'i' },
|
||||
],
|
||||
})
|
||||
|
||||
@@ -58,7 +58,7 @@ const HOLD = createState({
|
||||
name: 'Hold position',
|
||||
summary: 'Pilot requesting hold position',
|
||||
triggers: [
|
||||
{ type: 'regex', pattern: 'request', patternFlags: 'i' },
|
||||
{ id: 'hold-regex', type: 'regex', pattern: 'request', patternFlags: 'i' },
|
||||
],
|
||||
})
|
||||
|
||||
@@ -74,7 +74,16 @@ const runtimeSystem: RuntimeDecisionSystem = {
|
||||
flows: {
|
||||
main: {
|
||||
slug: 'main',
|
||||
schema_version: '1.0',
|
||||
name: 'Main Flow',
|
||||
start_state: 'START',
|
||||
end_states: [],
|
||||
variables: {},
|
||||
flags: {},
|
||||
policies: {},
|
||||
hooks: {},
|
||||
roles: ['pilot', 'atc', 'system'],
|
||||
phases: ['ground'],
|
||||
entry_mode: 'main',
|
||||
states: {
|
||||
START,
|
||||
@@ -126,7 +135,18 @@ describe('routeDecision', () => {
|
||||
],
|
||||
}
|
||||
|
||||
const result = await routeDecision(input)
|
||||
const previousApiKey = process.env.OPENAI_API_KEY
|
||||
process.env.OPENAI_API_KEY = ''
|
||||
let result: Awaited<ReturnType<typeof routeDecision>>
|
||||
try {
|
||||
result = await routeDecision(input)
|
||||
} finally {
|
||||
if (previousApiKey === undefined) {
|
||||
delete process.env.OPENAI_API_KEY
|
||||
} else {
|
||||
process.env.OPENAI_API_KEY = previousApiKey
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(result.trace?.calls.length, 1)
|
||||
assert.ok(result.trace?.calls[0]?.error)
|
||||
@@ -135,4 +155,3 @@ describe('routeDecision', () => {
|
||||
assert.equal(result.pilot_intent ?? null, null)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -17,15 +17,6 @@ import {getServerRuntimeConfig} from './runtimeConfig'
|
||||
let openaiClient: OpenAI | null = null
|
||||
let cachedModel: string | null = null
|
||||
|
||||
import https from 'node:https'
|
||||
|
||||
const httpsAgent = new https.Agent({
|
||||
keepAlive: true,
|
||||
maxSockets: 50, // bei Bedarf anpassen
|
||||
maxFreeSockets: 10,
|
||||
timeout: 0 // keine Socket-Idle-Timeouts durch Node
|
||||
})
|
||||
|
||||
function ensureOpenAI(): OpenAI {
|
||||
if (!openaiClient) {
|
||||
const {openaiKey, openaiProject, openaiBaseUrl, llmModel} = getServerRuntimeConfig()
|
||||
@@ -34,7 +25,6 @@ function ensureOpenAI(): OpenAI {
|
||||
}
|
||||
const clientOptions: ConstructorParameters<typeof OpenAI>[0] = {apiKey: openaiKey,
|
||||
defaultHeaders: { 'Connection': 'keep-alive' },
|
||||
defaultHttpAgent: httpsAgent
|
||||
}
|
||||
if (openaiProject) {
|
||||
clientOptions.project = openaiProject
|
||||
@@ -1055,7 +1045,7 @@ export async function routeDecision(input: LLMDecisionInput): Promise<LLMDecisio
|
||||
JSON.stringify(optimizedInput, null, 2),
|
||||
].join('\n')
|
||||
|
||||
const callEntry = {
|
||||
const callEntry: LLMDecisionTrace['calls'][number] = {
|
||||
stage: 'decision' as const,
|
||||
request: {
|
||||
systemPrompt,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { execFile } from "node:child_process";
|
||||
export async function applyRadioEffect(input: string, output: string) {
|
||||
const filter="[0:a]highpass=f=300,lowpass=f=3400,compand=attacks=0.02:decays=0.25:points=-80/-900|-70/-20|0/-10|20/-8:gain=6,volume=1.2[a];anoisesrc=color=white:amplitude=0.02[ns];[a][ns]amix=inputs=2:weights=1 0.25:duration=shortest,volume=1.0,aecho=0.6:0.7:8:0.08,acompressor=threshold=0.6:ratio=6:attack=20:release=200";
|
||||
await new Promise((res,rej)=>
|
||||
await new Promise<void>((res,rej)=>
|
||||
execFile("ffmpeg",["-y","-i",input,"-filter_complex",filter,"-ar","16000",output],
|
||||
(err,_,stderr)=>err?rej(new Error(stderr)):res())
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { UpdateSubscriber, UpdateSubscriberDocument } from '../models/UpdateSubscriber'
|
||||
import { UpdateSubscriber } from '../models/UpdateSubscriber'
|
||||
import type { UpdateSubscriberDocument } from '../models/UpdateSubscriber'
|
||||
|
||||
interface RegisterSubscriberOptions {
|
||||
email: string
|
||||
|
||||
Reference in New Issue
Block a user