(hookUrl: string, token: string)
| 13 | const PLUGIN_PACKAGE_VERSION = '^1.14.0'; |
| 14 | |
| 15 | function buildPluginSource(hookUrl: string, token: string): string { |
| 16 | const escapedUrl = JSON.stringify(hookUrl); |
| 17 | const escapedToken = JSON.stringify(token); |
| 18 | |
| 19 | return [ |
| 20 | '// Generated by HAPI. Do not edit manually.', |
| 21 | '', |
| 22 | `const DEFAULT_HOOK_URL = ${escapedUrl};`, |
| 23 | `const DEFAULT_HOOK_TOKEN = ${escapedToken};`, |
| 24 | 'const HOOK_URL = process.env.HAPI_OPENCODE_HOOK_URL || DEFAULT_HOOK_URL;', |
| 25 | 'const HOOK_TOKEN = process.env.HAPI_OPENCODE_HOOK_TOKEN || DEFAULT_HOOK_TOKEN;', |
| 26 | '', |
| 27 | 'const EVENT_NAMES = new Set([', |
| 28 | " 'message.updated',", |
| 29 | " 'message.part.updated',", |
| 30 | " 'permission.updated',", |
| 31 | " 'permission.asked',", |
| 32 | " 'permission.replied',", |
| 33 | " 'session.created',", |
| 34 | " 'session.updated',", |
| 35 | " 'tool.execute.before',", |
| 36 | " 'tool.execute.after',", |
| 37 | ']);', |
| 38 | '', |
| 39 | 'function pickString(value) {', |
| 40 | " return typeof value === 'string' && value.length > 0 ? value : null;", |
| 41 | '}', |
| 42 | '', |
| 43 | 'function extractSessionId(value) {', |
| 44 | " if (!value || typeof value !== 'object') return null;", |
| 45 | ' const record = value;', |
| 46 | ' const direct = (', |
| 47 | ' pickString(record.sessionId)', |
| 48 | ' || pickString(record.sessionID)', |
| 49 | ' || pickString(record.session_id)', |
| 50 | ' || (record.session && pickString(record.session.id))', |
| 51 | ' );', |
| 52 | ' if (direct) return direct;', |
| 53 | ' if (record.part && typeof record.part === \'object\') {', |
| 54 | ' const nested = extractSessionId(record.part);', |
| 55 | ' if (nested) return nested;', |
| 56 | ' }', |
| 57 | ' if (record.info && typeof record.info === \'object\') {', |
| 58 | ' const nested = extractSessionId(record.info);', |
| 59 | ' if (nested) return nested;', |
| 60 | ' }', |
| 61 | ' return null;', |
| 62 | '}', |
| 63 | '', |
| 64 | 'function extractSessionIdFromEvent(eventName, payload) {', |
| 65 | ' const direct = extractSessionId(payload);', |
| 66 | ' if (direct) return direct;', |
| 67 | ' if (!payload || typeof payload !== \'object\') return null;', |
| 68 | ' const record = payload;', |
| 69 | ' if (record.info && typeof record.info === \'object\') {', |
| 70 | ' const fromInfo = extractSessionId(record.info);', |
| 71 | ' if (fromInfo) return fromInfo;', |
| 72 | ' if (eventName.startsWith(\'session.\')) {', |
no outgoing calls
no test coverage detected