{"id":30002937,"url":"https://github.com/zivl/prompt-api-types","last_synced_at":"2025-08-05T06:44:44.275Z","repository":{"id":306736310,"uuid":"1026675478","full_name":"zivl/prompt-api-types","owner":"zivl","description":"google's chrome-prompt-api types","archived":false,"fork":false,"pushed_at":"2025-07-27T08:30:25.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-27T10:25:37.538Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zivl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-26T11:26:38.000Z","updated_at":"2025-07-27T08:29:49.000Z","dependencies_parsed_at":"2025-07-27T10:25:39.352Z","dependency_job_id":"1c20c5bb-b101-4168-a2c3-fa07eceea788","html_url":"https://github.com/zivl/prompt-api-types","commit_stats":null,"previous_names":["zivl/prompt-api-types"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/zivl/prompt-api-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Fprompt-api-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Fprompt-api-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Fprompt-api-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Fprompt-api-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zivl","download_url":"https://codeload.github.com/zivl/prompt-api-types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zivl%2Fprompt-api-types/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268851384,"owners_count":24317323,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-05T06:44:41.812Z","updated_at":"2025-08-05T06:44:44.231Z","avatar_url":"https://github.com/zivl.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prompt-api-types\n\nTypeScript type definitions for Chrome's Prompt API, providing comprehensive types for language models and prompt-related functionality.\n\n## Installation\n\n```bash\nnpm install prompt-api-types\n```\n\n## Usage\n\n### Basic Window Interface Extension\n\nTo use the types in your project, create a type declaration file (e.g., `external-types.d.ts`) and add the reference:\n\n```typescript\n/// \u003creference types=\"prompt-api-types/types\" /\u003e\n\ninterface Window {\n  LanguageModel: LanguageModelType\n}\n```\n\n### Complete Example\n\n```typescript\n/// \u003creference types=\"prompt-api-types/types\" /\u003e\n\ninterface Window {\n  LanguageModel: LanguageModelType\n}\n\n// Example usage in your application\nasync function useLanguageModel() {\n  const model = window.LanguageModel\n\n  // Check availability\n  const availability = await model.availability()\n\n  if (availability === 'available') {\n    // Create a session\n    const session = await model.create({\n      temperature: 0.7,\n      topK: 40\n    })\n\n    // Simple prompt\n    const response = await session.prompt('Hello, how are you?')\n    console.log(response)\n\n    // Advanced prompt with structured content\n    const advancedResponse = await session.prompt([\n      {\n        role: 'system',\n        content: { type: 'text', value: 'You are a helpful assistant.' }\n      },\n      {\n        role: 'user',\n        content: { type: 'text', value: 'What is TypeScript?' }\n      }\n    ])\n    console.log(advancedResponse)\n\n    // Streaming response\n    for await (const chunk of session.promptStreaming('Tell me a story')) {\n      console.log(chunk)\n    }\n  }\n}\n```\n\n## Available Types\n\n### Core Types\n\n- `LanguageModelType` - Main interface with `create()` and `availability()` methods\n- `LanguageModelSession` - Session interface for prompt interactions\n- `LanguageModelOptions` - Configuration options for model requests\n- `Availability` - Model availability status type\n- `LanguageModelPromptResponse` - Response type (string)\n\n### Message and Content Types\n\n- `PromptPayload` - Can be a string or array of `ExpandedPromptPayload`\n- `ExpandedPromptPayload` - Structured message with role and content\n- `PromptMessageContent` - Union type for text, image, or audio content\n- `PromptPayloadOptions` - Options for prompt requests including response constraints\n\n### Advanced Types\n\n- `CreateOptions` - Options for creating language model sessions\n- `LanguageModelTool` - Tool definition for function calling\n- `PromptResponseConstraint` - JSON schema for constraining responses\n- `ExpectedInputOrOutput` - Type definitions for expected inputs/outputs\n- `QuotaExceededError` - Error type for quota violations\n\n### Multimodal Support\n\nThe API supports text, image, and audio content:\n\n```typescript\n// Text content\n{ type: 'text', value: 'Hello world' }\n\n// Image content (supports multiple formats)\n{ type: 'image', value: imageElement } // HTMLImageElement, Canvas, Blob, etc.\n\n// Audio content\n{ type: 'audio', value: audioBlob } // Blob, AudioBuffer, etc.\n```\n\n### Tools and Function Calling\n\n```typescript\nconst session = await model.create({\n  tools: [{\n    name: 'getCurrentWeather',\n    description: 'Get current weather for a location',\n    inputSchema: {\n      type: 'object',\n      properties: {\n        location: { type: 'string', description: 'City name' }\n      },\n      required: ['location']\n    },\n    execute: async (input) =\u003e {\n      // Your implementation\n      return `Weather in ${input.location}: Sunny, 75°F`\n    }\n  }]\n})\n```\n\n### Response Constraints\n\n```typescript\nconst response = await session.prompt('Generate a person object', {\n  responseConstraint: {\n    type: 'object',\n    required: ['name', 'age'],\n    additionalProperties: false,\n    properties: {\n      name: { type: 'string' },\n      age: { type: 'number' }\n    }\n  },\n  omitResponseConstraintInput: false\n})\n```\n\n## Development\n\n```bash\n# Install dependencies\nnpm install\n\n# Build the project\nnpm run build\n\n# Clean generated files\nnpm run clean\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzivl%2Fprompt-api-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzivl%2Fprompt-api-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzivl%2Fprompt-api-types/lists"}