browser-sdk.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * API surface definition for @anthropic-ai/claude-agent-sdk/browser.
  3. *
  4. * This file is the source of truth for the browser export's public types.
  5. * It imports ONLY from agentSdkTypes.ts so the compiled .d.ts has exactly
  6. * one import to rewrite (./agentSdkTypes → ./sdk) for the flat package layout.
  7. *
  8. * Compiled by scripts/build-ant-sdk-typings.sh; see build-agent-sdk.sh for the
  9. * path rewrite and copy into the package.
  10. */
  11. import type { CanUseTool, HookCallbackMatcher, HookEvent, McpServerConfig, Query, SDKUserMessage } from './agentSdkTypes.js';
  12. export type { CanUseTool, HookCallbackMatcher, HookEvent, McpSdkServerConfigWithInstance, McpServerConfig, Query, SDKAssistantMessage, SDKMessage, SDKResultMessage, SDKSystemMessage, SDKUserMessage, } from './agentSdkTypes.js';
  13. export { createSdkMcpServer, tool } from './agentSdkTypes.js';
  14. export type OAuthCredential = {
  15. type: 'oauth';
  16. token: string;
  17. };
  18. export type AuthMessage = {
  19. type: 'auth';
  20. credential: OAuthCredential;
  21. };
  22. export type WebSocketOptions = {
  23. url: string;
  24. headers?: Record<string, string>;
  25. authMessage?: AuthMessage;
  26. };
  27. export type BrowserQueryOptions = {
  28. prompt: AsyncIterable<SDKUserMessage>;
  29. websocket: WebSocketOptions;
  30. abortController?: AbortController;
  31. canUseTool?: CanUseTool;
  32. hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
  33. mcpServers?: Record<string, McpServerConfig>;
  34. jsonSchema?: Record<string, unknown>;
  35. };
  36. /**
  37. * Create a Claude Code query using WebSocket transport in the browser.
  38. *
  39. * @example
  40. * ```typescript
  41. * import { query } from '@anthropic-ai/claude-agent-sdk/browser'
  42. *
  43. * const messages = query({
  44. * prompt: messageStream,
  45. * websocket: { url: 'wss://api.example.com/claude' },
  46. * })
  47. * for await (const message of messages) {
  48. * console.log(message)
  49. * }
  50. * ```
  51. */
  52. export declare function query(options: BrowserQueryOptions): Query;