{"_id":"@ahnopologetic/use-prompt-api","_rev":"2-998d8061437144a3f16d5d9f11823a5f","name":"@ahnopologetic/use-prompt-api","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@ahnopologetic/use-prompt-api","version":"0.1.0","keywords":["chrome","prompt-api","ai","llm","gemini-nano","structured-output","function-calling","agents","react-hooks"],"author":{"name":"ahnopologetic","email":"stahn1995@gmail.com"},"license":"MIT","_id":"@ahnopologetic/use-prompt-api@0.1.0","maintainers":[{"name":"ahnopologetic","email":"stahn1995@gmail.com"}],"homepage":"https://github.com/ahnopologetic/use-prompt-api","dist":{"shasum":"c99d29a34098465379a54a1a65ccbc168fe689bb","tarball":"https://registry.npmjs.org/@ahnopologetic/use-prompt-api/-/use-prompt-api-0.1.0.tgz","fileCount":17,"integrity":"sha512-8j34LqOgrNocpd16Q6EQn4ULq2CgF5ShZjtx+GReX6CFEDF+8x+2qEhHXul1E9OdXt29IRio2QCZAjxbOCbRZA==","signatures":[{"sig":"MEYCIQDpBwCCTDqgoC1QXKO3zqIVzlzPEbwz8V+s5WvTlsc79gIhALX8TOyXzRgZbqzcs3TLJ4cl+wTgR/FoVJ7CUWDpx06P","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":793427},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./react":{"types":"./dist/react.d.ts","import":"./dist/react.js","require":"./dist/react.cjs"}},"gitHead":"a4b26ef372022fe0bc92275d1731e889a446632f","scripts":{"dev":"tsup --watch","lint":"eslint src --ext .ts,.tsx","test":"vitest","build":"tsup","format":"prettier --write \"src/**/*.{ts,tsx}\"","test:ui":"vitest --ui","type-check":"tsc --noEmit"},"_npmUser":{"name":"ahnopologetic","email":"stahn1995@gmail.com"},"_npmVersion":"10.8.2","description":"A TypeScript library for Chrome's built-in Prompt API with structured output, function calling, and agentic workflows","directories":{},"_nodeVersion":"20.19.5","_hasShrinkwrap":false,"packageManager":"pnpm@10.6.5","devDependencies":{"zod":"^3.22.4","tsup":"^8.0.1","jsdom":"^27.0.0","react":"^18.2.0","eslint":"^8.56.0","vitest":"^1.2.2","prettier":"^3.2.5","@vitest/ui":"^3.2.4","typescript":"^5.9.3","@types/node":"^20.11.17","@types/react":"^18.2.55","@testing-library/react":"^14.2.1","@typescript-eslint/parser":"^6.21.0","@testing-library/react-hooks":"^8.0.1","@typescript-eslint/eslint-plugin":"^6.21.0"},"peerDependencies":{"zod":"^3.22.0","react":"^18.0.0 || ^19.0.0"},"peerDependenciesMeta":{"zod":{"optional":true},"react":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/use-prompt-api_0.1.0_1760671429794_0.5870481763985509","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@ahnopologetic/use-prompt-api","version":"0.1.1","description":"A TypeScript library for Chrome's built-in Prompt API with structured output, function calling, and agentic workflows","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./react":{"types":"./dist/react.d.ts","import":"./dist/react.js","require":"./dist/react.cjs"}},"scripts":{"build":"tsup","dev":"tsup --watch","test":"vitest","test:ui":"vitest --ui","type-check":"tsc --noEmit","lint":"eslint src --ext .ts,.tsx","format":"prettier --write \"src/**/*.{ts,tsx}\""},"keywords":["chrome","prompt-api","ai","llm","gemini-nano","structured-output","function-calling","agents","react-hooks"],"author":{"name":"ahnopologetic","email":"stahn1995@gmail.com"},"homepage":"https://github.com/ahnopologetic/use-prompt-api","license":"MIT","packageManager":"pnpm@10.6.5","peerDependencies":{"react":"^18.0.0 || ^19.0.0","zod":"^3.22.0"},"peerDependenciesMeta":{"react":{"optional":true},"zod":{"optional":true}},"devDependencies":{"@testing-library/react":"^14.2.1","@testing-library/react-hooks":"^8.0.1","@types/node":"^20.11.17","@types/react":"^18.2.55","@typescript-eslint/eslint-plugin":"^6.21.0","@typescript-eslint/parser":"^6.21.0","@vitest/ui":"^3.2.4","eslint":"^8.56.0","jsdom":"^27.0.0","prettier":"^3.2.5","react":"^18.2.0","tsup":"^8.0.1","typescript":"^5.9.3","vitest":"^1.2.2","zod":"^3.22.4"},"_id":"@ahnopologetic/use-prompt-api@0.1.1","gitHead":"0ceba532826f17109cb64098a49d369f3ad8bde9","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-OLKMvV6VbSzI6Bk2e25y6TnOYZzQIao8IcmuGUKF3f7UIhR2mt533s1eEMWg/VNp9VAu5K1urbNxNPHlSXp2yg==","shasum":"bde8361d2151eae3c425713e81b960145fe8a7c7","tarball":"https://registry.npmjs.org/@ahnopologetic/use-prompt-api/-/use-prompt-api-0.1.1.tgz","fileCount":17,"unpackedSize":793637,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIES6sQjd+EZwa+YzuobWUGuXFxWF57b1zCG+W19A0TiLAiEA0/j9fHG6+VnSp2GRHDSMICsrl1vMECC76wxdTXMVyxs="}]},"_npmUser":{"name":"ahnopologetic","email":"stahn1995@gmail.com"},"directories":{},"maintainers":[{"name":"ahnopologetic","email":"stahn1995@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/use-prompt-api_0.1.1_1760671904790_0.9244646227279456"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-17T03:23:49.705Z","modified":"2025-10-17T03:31:45.230Z","0.1.0":"2025-10-17T03:23:50.087Z","0.1.1":"2025-10-17T03:31:45.057Z"},"author":{"name":"ahnopologetic","email":"stahn1995@gmail.com"},"license":"MIT","homepage":"https://github.com/ahnopologetic/use-prompt-api","keywords":["chrome","prompt-api","ai","llm","gemini-nano","structured-output","function-calling","agents","react-hooks"],"description":"A TypeScript library for Chrome's built-in Prompt API with structured output, function calling, and agentic workflows","maintainers":[{"name":"ahnopologetic","email":"stahn1995@gmail.com"}],"readme":"# use-prompt-api\n\nA comprehensive TypeScript library for Chrome's built-in Prompt API with advanced features including structured output, function calling, agentic workflows, and React hooks integration.\n\n## Features\n\n- 🎯 **Type-Safe**: Full TypeScript support with strict typing\n- 🔄 **Session Management**: Persistent sessions with localStorage integration\n- 📊 **Structured Output**: Zod schema integration for validated responses\n- 🛠️ **Function Calling**: OpenAI-style function calling support\n- 🤖 **Agentic Workflows**: Multi-turn task execution with planning and reflection\n- ⚛️ **React Hooks**: Seamless React integration\n- 📡 **Streaming**: Full streaming support with custom renderers\n- 💾 **Quota Management**: Smart quota tracking and warnings\n\n## Installation\n\n```bash\nnpm install @ahnopologetic/use-prompt-api zod\n# or\npnpm add @ahnopologetic/use-prompt-api zod\n# or\nyarn add @ahnopologetic/use-prompt-api zod\n```\n\n## Prerequisites\n\nThis library requires Chrome 128+ with the Prompt API origin trial enabled. Learn more at [Chrome AI Documentation](https://developer.chrome.com/docs/ai/prompt-api).\n\n## Quick Start\n\n### Basic Usage\n\n```typescript\nimport { PromptClient } from '@ahnopologetic/use-prompt-api';\n\n// Initialize the client\nconst client = new PromptClient();\nawait client.initialize();\n\n// Create a session\nconst session = await client.createSession({\n  systemPrompt: 'You are a helpful assistant',\n  temperature: 0.7,\n});\n\n// Prompt the model\nconst response = await session.prompt('What is the capital of France?');\nconsole.log(response);\n```\n\n### Streaming Responses\n\n```typescript\nconst stream = session.promptStreaming('Tell me a story');\nconst reader = stream.getReader();\n\nwhile (true) {\n  const { done, value } = await reader.read();\n  if (done) break;\n  console.log(value); // Print each chunk as it arrives\n}\n```\n\n### Structured Output with Zod\n\n```typescript\nimport { z } from 'zod';\nimport { promptWithStructure } from '@ahnopologetic/use-prompt-api';\n\nconst personSchema = z.object({\n  name: z.string(),\n  age: z.number(),\n  email: z.string().email(),\n});\n\nconst result = await promptWithStructure(\n  session,\n  'Extract person info: John Doe, 30 years old, john@example.com',\n  { schema: personSchema }\n);\n\nconsole.log(result); // { name: 'John Doe', age: 30, email: 'john@example.com' }\n```\n\n### Function Calling\n\n```typescript\nimport { FunctionRegistry, createFunctionDefinition } from '@ahnopologetic/use-prompt-api';\n\nconst registry = new FunctionRegistry();\n\nregistry.register(\n  createFunctionDefinition(\n    'getWeather',\n    'Get the current weather for a location',\n    {\n      type: 'object',\n      properties: {\n        location: { type: 'string', description: 'City name' },\n      },\n      required: ['location'],\n    },\n    async ({ location }: { location: string }) => {\n      // Your weather API call here\n      return { temperature: 72, condition: 'sunny' };\n    }\n  )\n);\n```\n\n### Basic Agent\n\n```typescript\nimport { BasicAgent } from '@ahnopologetic/use-prompt-api';\n\nconst agent = new BasicAgent({\n  maxIterations: 10,\n  functions: [weatherFunction, calculatorFunction],\n  systemPrompt: 'You are a helpful assistant',\n  onStep: (step) => console.log('Step:', step.iteration),\n});\n\nconst result = await agent.run('What is the weather in Paris and Tokyo?');\nconsole.log(result.finalAnswer);\n```\n\n### Advanced Agent with Planning\n\n```typescript\nimport { AdvancedAgent } from '@ahnopologetic/use-prompt-api';\n\nconst agent = new AdvancedAgent({\n  maxIterations: 20,\n  functions: [...],\n  enablePlanning: true,\n  maxReflections: 2,\n});\n\nconst result = await agent.runWithPlanning('Research and summarize AI trends in 2024');\n```\n\n## React Integration\n\n### Basic Hook\n\n```tsx\nimport { usePromptAPI } from '@ahnopologetic/use-prompt-api/react';\n\nfunction ChatComponent() {\n  const { prompt, ready, loading, error, quota } = usePromptAPI({\n    systemPrompt: 'You are a helpful assistant',\n  });\n\n  const [response, setResponse] = useState('');\n\n  const handleSubmit = async (message: string) => {\n    const result = await prompt(message);\n    setResponse(result);\n  };\n\n  if (!ready) return <div>Loading AI model...</div>;\n  if (error) return <div>Error: {error.message}</div>;\n\n  return (\n    <div>\n      <QuotaDisplay quota={quota} />\n      <ChatInterface onSubmit={handleSubmit} response={response} />\n    </div>\n  );\n}\n```\n\n### Structured Output Hook\n\n```tsx\nimport { useStructuredPrompt } from '@ahnopologetic/use-prompt-api/react';\nimport { z } from 'zod';\n\nconst taskSchema = z.object({\n  title: z.string(),\n  priority: z.enum(['low', 'medium', 'high']),\n  dueDate: z.string(),\n});\n\nfunction TaskExtractor() {\n  const { prompt, data, loading } = useStructuredPrompt({\n    schema: taskSchema,\n  });\n\n  const extractTask = async (text: string) => {\n    const task = await prompt(`Extract task from: ${text}`);\n    console.log(task); // Fully typed!\n  };\n\n  return <TaskForm onExtract={extractTask} loading={loading} />;\n}\n```\n\n### Function Calling Hook\n\n```tsx\nimport { useFunctionCalling } from '@ahnopologetic/use-prompt-api/react';\n\nfunction AssistantComponent() {\n  const { prompt, results, loading } = useFunctionCalling({\n    functions: [weatherFunction, calculatorFunction],\n    autoExecute: true,\n  });\n\n  return <Assistant onPrompt={prompt} results={results} />;\n}\n```\n\n### Agent Hook\n\n```tsx\nimport { useAgent } from '@ahnopologetic/use-prompt-api/react';\n\nfunction AgentComponent() {\n  const { run, steps, status, progress } = useAgent({\n    maxIterations: 10,\n    functions: [...],\n  });\n\n  return (\n    <div>\n      <button onClick={() => run('Complete this task...')}>Start</button>\n      <Progress value={progress} />\n      <StepsList steps={steps} />\n    </div>\n  );\n}\n```\n\n## API Reference\n\n### Core Classes\n\n#### `PromptClient`\n\nHigh-level client for managing sessions.\n\n```typescript\nconst client = new PromptClient();\nawait client.initialize();\nconst session = await client.createSession(options);\n```\n\n#### `SessionManager`\n\nManages individual conversation sessions.\n\n```typescript\nconst manager = new SessionManager();\nawait manager.create({ systemPrompt: '...' });\nconst response = await manager.prompt('Hello');\n```\n\n### Structured Output\n\n#### `promptWithStructure<T>`\n\nGet structured output validated against a Zod schema.\n\n```typescript\nconst result = await promptWithStructure<PersonType>(session, prompt, {\n  schema: personSchema,\n  maxRetries: 3,\n});\n```\n\n### Function Calling\n\n#### `FunctionRegistry`\n\nManage available functions for the AI.\n\n```typescript\nconst registry = new FunctionRegistry();\nregistry.register(functionDefinition);\nregistry.list(); // Get all functions\n```\n\n### Agents\n\n#### `BasicAgent`\n\nSimple multi-turn task execution.\n\n```typescript\nconst agent = new BasicAgent({\n  maxIterations: 10,\n  functions: [...],\n  onStep: (step) => {...},\n});\n```\n\n#### `AdvancedAgent`\n\nAgent with planning and reflection.\n\n```typescript\nconst agent = new AdvancedAgent({\n  maxIterations: 20,\n  enablePlanning: true,\n  maxReflections: 2,\n});\n```\n\n## Examples\n\nSee the [examples](./examples) directory for complete working examples:\n\n- [Basic Chat](./examples/basic-chat.ts) - Simple conversational interface\n- [Structured Output](./examples/structured-output.ts) - Type-safe data extraction with Zod\n- [Function Calling](./examples/function-calling.ts) - Using custom functions with the AI\n- [Basic Agent](./examples/basic-agent.ts) - Multi-turn task execution\n- [Advanced Agent](./examples/advanced-agent.ts) - Planning and reflection capabilities\n- **[Streaming Agent](./examples/streaming-agent.ts) ⭐ NEW** - Real-time streaming with visual tool calls\n- [React Chatbot](./examples/react-chatbot/) - Full React integration\n\n### Run Examples\n\n```bash\n# TypeScript examples (requires pnpm install)\npnpm example:basic         # Basic chat\npnpm example:functions     # Function calling\npnpm example:agent         # Basic agent\npnpm example:advanced      # Advanced agent\npnpm example:streaming     # Streaming agent ⭐\npnpm example:structured    # Structured output\n\n# Browser examples\n# Open examples/streaming-agent.html in Chrome\n```\n\n## Documentation\n\n- [Session Management](./docs/session-management.md)\n- [Structured Output](./docs/structured-output.md)\n- [Function Calling](./docs/function-calling.md)\n- [Agentic Workflows](./docs/agents.md)\n- [Migration Guide](./docs/migration.md)\n\n## Browser Support\n\n- Chrome 128+ (with Prompt API origin trial enabled)\n- Edge 128+ (with origin trial)\n\n## Contributing\n\nContributions are welcome! Please read our contributing guidelines before submitting PRs.\n\n## License\n\nMIT\n\n## Acknowledgments\n\nBuilt for Chrome's built-in Prompt API. Learn more at [Chrome AI Documentation](https://developer.chrome.com/docs/ai/).\n\n","readmeFilename":"README.md"}