﻿﻿# GPlay Central AI — Node.js & TypeScript SDK Integration Blueprint

Panduan integrasi resmi GPlay Central AI Engine untuk **Node.js, Express, NestJS, dan TypeScript**.

---

## 1. Instalasi SDK / Axios

```bash
npm install @gplay/ai-sdk axios
```

---

## 2. Konfigurasi Environment (`.env`)

```env
GPLAY_AI_BASE_URL=http://localhost:5000/api/v1
GPLAY_AI_API_KEY=gplay_kunci_api_tenant_anda
```

---

## 3. Official TypeScript Client (`src/services/gplayClient.ts`)

```typescript
import axios, { AxiosInstance } from 'axios';

export interface CodeAssistantOptions {
  sourceCode: string;
  language?: string;
  task?: string;
}

export class GPlayAiClient {
  private client: AxiosInstance;

  constructor(apiKey?: string, baseURL?: string) {
    this.client = axios.create({
      baseURL: baseURL || process.env.GPLAY_AI_BASE_URL || 'http://localhost:5000/api/v1',
      headers: {
        'X-API-KEY': apiKey || process.env.GPLAY_AI_API_KEY || '',
        'Content-Type': 'application/json',
      },
    });
  }

  /**
   * AI Coding Assistant & Code Auditor
   */
  async codeAssistant(options: CodeAssistantOptions) {
    const { data } = await this.client.post('/devops/code-assistant', options);
    return data;
  }

  /**
   * CyberDefense & Threat Intelligence Engine
   */
  async threatAnalyzer(targetEndpoint: string, trafficLog: string, attackVector = 'DDoS_AND_RANSOMWARE') {
    const { data } = await this.client.post('/security/threat-analyzer', {
      targetEndpoint,
      trafficLog,
      attackVector,
    });
    return data;
  }

  /**
   * Multimodal Video Analytics & CCTV Safety Engine
   */
  async analyzeVideoSafety(videoStreamUrl: string, location = 'Factory Floor', safetyRule = 'K3_PPE_FIRE') {
    const { data } = await this.client.post('/vision/analyze-video', {
      videoStreamUrl,
      location,
      safetyRule,
    });
    return data;
  }

  /**
   * Voice Intelligence & Call Center Speech Quality Engine
   */
  async speechIntelligence(audioUrl: string, agentName: string, customerPhone: string, language = 'id-ID') {
    const { data } = await this.client.post('/audio/speech-intelligence', {
      audioUrl,
      agentName,
      customerPhone,
      language,
    });
    return data;
  }

  /**
   * Predictive HR Attrition & Employee Retention AI Engine
   */
  async predictTurnover(employeeId: string, department: string, tenureMonths: number, recentOvertimeHours: number) {
    const { data } = await this.client.post('/hr/predict-turnover', {
      employeeId,
      department,
      tenureMonths,
      recentOvertimeHours,
    });
    return data;
  }

  /**
   * Legal Contract Expiry & Dispute Settlement AI Engine
   */
  async disputeAnalyzer(contractId: string, contractTitle: string, expiryDate: string) {
    const { data } = await this.client.post('/legal/dispute-analyzer', {
      contractId,
      contractTitle,
      expiryDate,
    });
    return data;
  }

  /**
   * AI Content & Plagiarism Detector Engine (Milestone 83)
   */
  async detectAiPlagiarism(text: string, sensitivity = 0.85) {
    const { data } = await this.client.post('/content/detect-ai-plagiarism', {
      text,
      sensitivity,
    });
    return data;
  }

  /**
   * Web3 & Smart Contract Auditor Engine (Milestone 84)
   */
  async auditSmartContract(sourceCode: string, language = 'solidity') {
    const { data } = await this.client.post('/web3/audit-smart-contract', {
      sourceCode,
      language,
    });
    return data;
  }

  /**
   * Enterprise Workspace Slack/Teams AI Alerting (Milestone 85)
   */
  async sendSlackAlert(channel: string, eventTitle: string, alertLevel = 'critical', payload = {}) {
    const { data } = await this.client.post('/workspace/slack-notifier', {
      channel,
      eventTitle,
      alertLevel,
      payload,
    });
    return data;
  }

  /**
   * Real-Time API Usage Anomaly Detector (Milestone 91)
   */
  async detectApiAnomaly(apiKeyId: string, requestRatePerMin: number, endpointTarget = '/api/v1/data/query') {
    const { data } = await this.client.post('/security/api-anomaly-detector', {
      apiKeyId,
      requestRatePerMin,
      endpointTarget,
    });
    return data;
  }

  /**
   * Real-Time Indirect Prompt Injection Shield (Milestone 104)
   */
  async shieldPromptInjection(prompt: string, contextDocuments: string[] = []) {
    const { data } = await this.client.post('/guardrails/prompt-injection-shield', {
      prompt,
      contextDocuments,
    });
    return data;
  }

  /**
   * Deep Document Forgery & Digital Stamp Authenticator (Milestone 114)
   */
  async checkInvoiceTamper(documentHash: string, eMeteraiSerial: string) {
    const { data } = await this.client.post('/finsec/invoice-tamper-check', {
      documentHash,
      eMeteraiSerial,
    });
    return data;
  }

  /**
   * AIDC Power Infrastructure & PUE/Thermal Optimizer (Milestone 115)
   */
  async optimizeAidcPower(itComputeLoadKw: number, coolingFacilityLoadKw: number, coolingMethod = 'DIRECT_LIQUID_COOLING', facilityName = 'Jakarta AIDC') {
    const { data } = await this.client.post('/energy/aidc-power-optimizer', {
      itComputeLoadKw,
      coolingFacilityLoadKw,
      coolingMethod,
      facilityName,
    });
    return data;
  }

  /**
   * Grid-Scale BESS & Smart Micro-Grid EMS Controller (Milestone 116)
   */
  async manageBessMicrogrid(clusterId: string, currentSocPct: number, targetDischargeKw = 0, gridTariffMode = 'PEAK_HOUR') {
    const { data } = await this.client.post('/energy/bess-microgrid-ems', {
      clusterId,
      currentSocPct,
      targetDischargeKw,
      gridTariffMode,
    });
    return data;
  }

  /**
   * Central Bank AI Hardware Supply Chain KB (Milestone 117)
   */
  async getHardwareSupplyChain(queryCategory = 'BESS_BATTERY_STORAGE', includePatents = true) {
    const { data } = await this.client.post('/intel/hardware-supply-chain', {
      queryCategory,
      includePatents,
    });
    return data;
  }

  /**
   * Industrial IoT Edge Power & PVSpectra Dual-Probe Telemetry (Milestone 118 - IMPI No. 5960)
   */
  async ingestPowerTelemetry(deviceId: string, deviceSource = 'PVSPECTRA_SOLAR', voltageV = 480.0, currentA = 84.5, thdNoisePct = 1.8, noiseAttenuationPct = 91.8) {
    const { data } = await this.client.post('/iot/server-power-telemetry', {
      deviceId,
      deviceSource,
      voltageV,
      currentA,
      thdNoisePct,
      noiseAttenuationPct,
    });
    return data;
  }
}
```
