@useviber/shared-types

v1.0.1

Published

Shared TypeScript types for Viber components

Readme

@viber/shared-types

Shared TypeScript types and Zod schemas for all Viber components. This package serves as the single source of truth for all type definitions used across the Viber ecosystem.

Features

  • Single Source of Truth: All shared types in one place
  • Zod Schemas: Runtime validation for all data structures
  • TypeScript Types: Full type safety across all components
  • Zero Dependencies: Lightweight package with minimal dependencies

Installation

npm install @viber/shared-types

Usage

Basic Import

import { 
  Prompt, 
  ElementContext, 
  StatusResponse,
  PromptSchema,
  StatusResponseSchema 
} from '@viber/shared-types';

Schema Validation

import { PromptSchema, StatusResponseSchema } from '@viber/shared-types';

// Validate incoming data
const promptData = PromptSchema.parse({
  userGoal: "Make button red",
  elementContext: {
    tagName: "button",
    className: "submit-btn"
  }
});

// Validate response data
const statusData = StatusResponseSchema.parse({
  status: "completed",
  progress: 100,
  timestamp: new Date()
});

Type Safety

import { Prompt, StatusResponse } from '@viber/shared-types';

function processPrompt(prompt: Prompt): Promise<StatusResponse> {
  // Full type safety guaranteed
  return processPromptInternal(prompt);
}

Available Types

Element Context

interface ElementContext {
  tagName: string;
  className?: string;
  id?: string;
  attributes?: Record<string, string>;
  innerText?: string;
  parentPath?: string;
  computedStyles?: Record<string, string>;
  boundingBox?: {
    x: number;
    y: number;
    width: number;
    height: number;
  };
}

Prompt

interface Prompt {
  userGoal: string;
  elementContext: ElementContext;
  projectContext?: {
    workspacePath?: string;
    currentFile?: string;
    fileStructure?: string[];
  };
}

Status Response

interface StatusResponse {
  status: 'processing' | 'completed' | 'failed' | 'cancelled';
  progress?: number;
  message?: string;
  timestamp: Date;
}

Client Registration

interface ClientRegistration {
  clientType: 'web-client' | 'web-client-agent' | 'extension';
  clientId: string;
  capabilities?: string[];
}

Available Schemas

All types have corresponding Zod schemas for runtime validation:

  • ElementContextSchema
  • PromptSchema
  • PromptResponseSchema
  • StatusResponseSchema
  • ClientRegistrationSchema

Development

Building

npm run build

Development Mode

npm run dev

Clean Build

npm run clean && npm run build

Architecture

This package is used by:

  • @viber/api - Client library
  • communication-agent - Server implementation
  • web-client - React library
  • web-client-agent - Data formatter
  • extension - VS Code extension

All components import from this single source, ensuring type consistency across the entire Viber ecosystem.

License

MIT