mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: consolidate utility functions into shared package
Move duplicate isObject, asString, asNumber, and safeStringify functions from multiple modules into a centralized shared/src/utils.ts module and update imports across cli, server, and web packages. This eliminates code duplication and improves maintainability.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { AgentMessage, PlanItem } from '@/agent/types';
|
||||
import { asString, deriveToolName, isObject } from '@/agent/utils';
|
||||
import { asString, isObject } from '@hapi/protocol';
|
||||
import { deriveToolName } from '@/agent/utils';
|
||||
import { ACP_SESSION_UPDATE_TYPES } from './constants';
|
||||
|
||||
function normalizeStatus(status: unknown): 'pending' | 'in_progress' | 'completed' | 'failed' {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AgentBackend, AgentMessage, AgentSessionConfig, PermissionRequest, PermissionResponse, PromptContent } from '@/agent/types';
|
||||
import { asString, isObject } from '@/agent/utils';
|
||||
import { asString, isObject } from '@hapi/protocol';
|
||||
import { AcpStdioTransport, type AcpStderrError } from './AcpStdioTransport';
|
||||
import { AcpMessageHandler } from './AcpMessageHandler';
|
||||
import { logger } from '@/ui/logger';
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
export function isObject(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === 'object';
|
||||
}
|
||||
|
||||
export function asString(value: unknown): string | null {
|
||||
return typeof value === 'string' ? value : null;
|
||||
}
|
||||
import { isObject } from '@hapi/protocol';
|
||||
|
||||
export function deriveToolName(input: {
|
||||
title?: string | null;
|
||||
|
||||
@@ -15,6 +15,7 @@ import { getToolName } from "./getToolName";
|
||||
import { EnhancedMode, PermissionMode } from "../loop";
|
||||
import { getToolDescriptor } from "./getToolDescriptor";
|
||||
import { delay } from "@/utils/time";
|
||||
import { isObject } from "@hapi/protocol";
|
||||
import {
|
||||
BasePermissionHandler,
|
||||
type PendingPermissionRequest,
|
||||
@@ -33,10 +34,6 @@ interface PermissionResponse {
|
||||
|
||||
const PLAN_EXIT_MODES: PermissionMode[] = ['default', 'acceptEdits', 'bypassPermissions'];
|
||||
|
||||
function isObject(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === 'object';
|
||||
}
|
||||
|
||||
function isAskUserQuestionToolName(toolName: string): boolean {
|
||||
return toolName === 'AskUserQuestion' || toolName === 'ask_user_question';
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
||||
import { isObject } from '@hapi/protocol';
|
||||
import { logger } from '@/ui/logger';
|
||||
import { isProcessAlive, killProcess } from '@/utils/process';
|
||||
import type { CodexSessionConfig, CodexToolResponse } from './types';
|
||||
@@ -20,10 +21,6 @@ type ElicitRequestedSchema = {
|
||||
required?: string[];
|
||||
};
|
||||
|
||||
function isObject(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === 'object';
|
||||
}
|
||||
|
||||
function extractRequestedSchema(params: Record<string, unknown>): ElicitRequestedSchema | null {
|
||||
const raw = params.requestedSchema;
|
||||
if (!isObject(raw)) return null;
|
||||
|
||||
Reference in New Issue
Block a user