import { createPermissionMap, HAIPServer, HAIPTool } from "@haip/server";
import {
  HAIPEventType,
  HAIPMessage,
  HAIPSessionTransaction,
  HAIPToolSchema,
} from "haip";
import OpenAI from "openai";
const server = new HAIPServer({
  port: 8080,
  host: "0.0.0.0",
  jwtSecret: "CHANGE_THIS_TO_A_SECRET_STRING",
  enableCORS: true,
  enableLogging: true,
  flowControl: {
    enabled: true,
    minCredits: 100,
    maxCredits: 10000,
    creditThreshold: 200,
    backPressureThreshold: 0.8,
    adaptiveAdjustment: true,
  },
});
server.authenticate((req) => {
  // Here you should validate your with your auth system
  // Hardcoded check here
  if (req.token === "Bearer TOKEN") {
    return {
      id: "user123",
      permissions: createPermissionMap({ MESSAGE: ["*"] }),
      credits: 1000,
    };
  }
  return null;
});
server.start();