@pear-protocol/agent-sdk
Advanced tools
| import { z } from 'zod'; | ||
| interface AgentChatClientConfig { | ||
| baseUrl: string; | ||
| getToken: () => string | Promise<string>; | ||
| tokenVersion?: "v2" | "v3"; | ||
| fetch?: typeof fetch; | ||
| } | ||
| declare const TokenEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const ThinkingEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const StatusEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const SourcesEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| declare const ErrorEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const AgentWireEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>], "type">; | ||
| type AgentWireEvent = z.infer<typeof AgentWireEventSchema>; | ||
| declare const ChatResultSchema: z.ZodObject<{ | ||
| finalText: z.ZodString; | ||
| sessionId: z.ZodOptional<z.ZodString>; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodDefault<z.ZodArray<z.ZodString>>; | ||
| suggestedAction: z.ZodCatch<z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| type ChatResult = z.infer<typeof ChatResultSchema>; | ||
| type AgentEvent = AgentWireEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }; | ||
| declare const LinkStatusSchema: z.ZodObject<{ | ||
| linked: z.ZodBoolean; | ||
| walletAddress: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type LinkStatus = z.infer<typeof LinkStatusSchema>; | ||
| declare const SelfLinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<true>; | ||
| created: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>; | ||
| declare const SelfUnlinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<false>; | ||
| }, z.core.$strip>; | ||
| type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>; | ||
| declare const SessionListItemSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type SessionListItem = z.infer<typeof SessionListItemSchema>; | ||
| declare const SessionSummarySchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| firstUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessageAt: z.ZodOptional<z.ZodString>; | ||
| lastAssistantMessageAt: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SessionSummary = z.infer<typeof SessionSummarySchema>; | ||
| declare const SessionSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| userId: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type Session = z.infer<typeof SessionSchema>; | ||
| declare const AgentChatMessageSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| role: z.ZodString; | ||
| content: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| researchAnnotations: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$loose>; | ||
| type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>; | ||
| declare const TradeLinkSchema: z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TradeLink = z.infer<typeof TradeLinkSchema>; | ||
| declare const TwitterSourceSchema: z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TwitterSource = z.infer<typeof TwitterSourceSchema>; | ||
| declare const CitationSourceSchema: z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>; | ||
| type CitationSource = z.infer<typeof CitationSourceSchema>; | ||
| declare const SuggestedActionSchema: z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SuggestedAction = z.infer<typeof SuggestedActionSchema>; | ||
| declare const ChatModeSchema: z.ZodEnum<{ | ||
| standard: "standard"; | ||
| advanced: "advanced"; | ||
| }>; | ||
| type ChatMode = z.infer<typeof ChatModeSchema>; | ||
| declare const ChatSurfaceSchema: z.ZodEnum<{ | ||
| pear_v3: "pear_v3"; | ||
| pear_pro: "pear_pro"; | ||
| base_mini: "base_mini"; | ||
| web: "web"; | ||
| }>; | ||
| type ChatSurface = z.infer<typeof ChatSurfaceSchema>; | ||
| declare const TicketActionSchema: z.ZodEnum<{ | ||
| open_position: "open_position"; | ||
| close_position: "close_position"; | ||
| close_all_positions: "close_all_positions"; | ||
| adjust_position: "adjust_position"; | ||
| adjust_advance_position: "adjust_advance_position"; | ||
| reverse_position: "reverse_position"; | ||
| rebalance_position: "rebalance_position"; | ||
| set_risk_parameters: "set_risk_parameters"; | ||
| }>; | ||
| type TicketAction = z.infer<typeof TicketActionSchema>; | ||
| declare const TicketStatusSchema: z.ZodEnum<{ | ||
| PENDING: "PENDING"; | ||
| EXECUTING: "EXECUTING"; | ||
| EXECUTED: "EXECUTED"; | ||
| CANCELLED: "CANCELLED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| type TicketStatus = z.infer<typeof TicketStatusSchema>; | ||
| declare const PendingActionSchema: z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type PendingAction = z.infer<typeof PendingActionSchema>; | ||
| declare const ConfirmResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| status: z.ZodEnum<{ | ||
| EXECUTED: "EXECUTED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| result: z.ZodOptional<z.ZodUnknown>; | ||
| positionsSnapshot: z.ZodOptional<z.ZodUnknown>; | ||
| images: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$loose>; | ||
| type ConfirmResult = z.infer<typeof ConfirmResultSchema>; | ||
| declare const CancelResultSchema: z.ZodObject<{ | ||
| ok: z.ZodLiteral<true>; | ||
| status: z.ZodLiteral<"CANCELLED">; | ||
| }, z.core.$strip>; | ||
| type CancelResult = z.infer<typeof CancelResultSchema>; | ||
| declare const SetConfirmationsResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetConfirmationsResult = z.infer<typeof SetConfirmationsResultSchema>; | ||
| declare const TradeSettingsSchema: z.ZodObject<{ | ||
| executionEnabled: z.ZodBoolean; | ||
| confirmationsEnabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type TradeSettings = z.infer<typeof TradeSettingsSchema>; | ||
| declare const SetExecutionResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>; | ||
| type StreamEvent = (Extract<AgentWireEvent, { | ||
| type: "token"; | ||
| }> & { | ||
| delta: string; | ||
| }) | (Extract<AgentWireEvent, { | ||
| type: "thinking"; | ||
| }> & { | ||
| delta: string; | ||
| }) | Exclude<AgentWireEvent, { | ||
| type: "token" | "thinking"; | ||
| }>; | ||
| declare class AgentChatClient { | ||
| private readonly http; | ||
| constructor(config: AgentChatClientConfig); | ||
| listSessions(): Promise<SessionListItem[]>; | ||
| listSessionSummaries(): Promise<SessionSummary[]>; | ||
| createSession(): Promise<{ | ||
| id: string; | ||
| }>; | ||
| getSession(sessionId: string): Promise<Session>; | ||
| deleteSession(sessionId: string): Promise<void>; | ||
| getMessages(sessionId: string, opts?: { | ||
| limit?: number; | ||
| before?: string; | ||
| }): Promise<AgentChatMessage[]>; | ||
| streamChat(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| signal?: AbortSignal; | ||
| cta?: { | ||
| previousText: string; | ||
| question: string; | ||
| selectedOption: string; | ||
| }; | ||
| }): AsyncGenerator<StreamEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }>; | ||
| sendMessage(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| }): Promise<ChatResult>; | ||
| confirmTicket(ticketId: string): Promise<ConfirmResult>; | ||
| cancelTicket(ticketId: string): Promise<CancelResult>; | ||
| setTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult>; | ||
| getTradeSettings(): Promise<TradeSettings>; | ||
| setTradeExecution(enabled: boolean): Promise<SetExecutionResult>; | ||
| getLinkStatus(): Promise<LinkStatus>; | ||
| linkWallet(opts?: { | ||
| force?: boolean; | ||
| code?: string; | ||
| }): Promise<SelfLinkResult>; | ||
| unlinkWallet(): Promise<SelfUnlinkResult>; | ||
| } | ||
| export { type TwitterSource as $, AgentChatClient as A, type SessionSummary as B, type CancelResult as C, SessionSummarySchema as D, ErrorEventSchema as E, type SetConfirmationsResult as F, SetConfirmationsResultSchema as G, type SetExecutionResult as H, SetExecutionResultSchema as I, SourcesEventSchema as J, StatusEventSchema as K, type LinkStatus as L, type StreamEvent as M, type SuggestedAction as N, SuggestedActionSchema as O, type PendingAction as P, type TicketAction as Q, TicketActionSchema as R, type SelfLinkResult as S, ThinkingEventSchema as T, type TicketStatus as U, TicketStatusSchema as V, TokenEventSchema as W, type TradeLink as X, TradeLinkSchema as Y, type TradeSettings as Z, TradeSettingsSchema as _, type AgentChatClientConfig as a, TwitterSourceSchema as a0, type AgentChatMessage as b, AgentChatMessageSchema as c, type AgentEvent as d, type AgentWireEvent as e, AgentWireEventSchema as f, CancelResultSchema as g, type ChatMode as h, ChatModeSchema as i, type ChatResult as j, ChatResultSchema as k, type ChatSurface as l, ChatSurfaceSchema as m, type CitationSource as n, CitationSourceSchema as o, type ConfirmResult as p, ConfirmResultSchema as q, LinkStatusSchema as r, PendingActionSchema as s, SelfLinkResultSchema as t, type SelfUnlinkResult as u, SelfUnlinkResultSchema as v, type Session as w, type SessionListItem as x, SessionListItemSchema as y, SessionSchema as z }; |
| import { z } from 'zod'; | ||
| interface AgentChatClientConfig { | ||
| baseUrl: string; | ||
| getToken: () => string | Promise<string>; | ||
| tokenVersion?: "v2" | "v3"; | ||
| fetch?: typeof fetch; | ||
| } | ||
| declare const TokenEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const ThinkingEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const StatusEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const SourcesEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| declare const ErrorEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const AgentWireEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>], "type">; | ||
| type AgentWireEvent = z.infer<typeof AgentWireEventSchema>; | ||
| declare const ChatResultSchema: z.ZodObject<{ | ||
| finalText: z.ZodString; | ||
| sessionId: z.ZodOptional<z.ZodString>; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodDefault<z.ZodArray<z.ZodString>>; | ||
| suggestedAction: z.ZodCatch<z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| type ChatResult = z.infer<typeof ChatResultSchema>; | ||
| type AgentEvent = AgentWireEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }; | ||
| declare const LinkStatusSchema: z.ZodObject<{ | ||
| linked: z.ZodBoolean; | ||
| walletAddress: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type LinkStatus = z.infer<typeof LinkStatusSchema>; | ||
| declare const SelfLinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<true>; | ||
| created: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>; | ||
| declare const SelfUnlinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<false>; | ||
| }, z.core.$strip>; | ||
| type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>; | ||
| declare const SessionListItemSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type SessionListItem = z.infer<typeof SessionListItemSchema>; | ||
| declare const SessionSummarySchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| firstUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessageAt: z.ZodOptional<z.ZodString>; | ||
| lastAssistantMessageAt: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SessionSummary = z.infer<typeof SessionSummarySchema>; | ||
| declare const SessionSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| userId: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type Session = z.infer<typeof SessionSchema>; | ||
| declare const AgentChatMessageSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| role: z.ZodString; | ||
| content: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| researchAnnotations: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$loose>; | ||
| type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>; | ||
| declare const TradeLinkSchema: z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TradeLink = z.infer<typeof TradeLinkSchema>; | ||
| declare const TwitterSourceSchema: z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TwitterSource = z.infer<typeof TwitterSourceSchema>; | ||
| declare const CitationSourceSchema: z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>; | ||
| type CitationSource = z.infer<typeof CitationSourceSchema>; | ||
| declare const SuggestedActionSchema: z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SuggestedAction = z.infer<typeof SuggestedActionSchema>; | ||
| declare const ChatModeSchema: z.ZodEnum<{ | ||
| standard: "standard"; | ||
| advanced: "advanced"; | ||
| }>; | ||
| type ChatMode = z.infer<typeof ChatModeSchema>; | ||
| declare const ChatSurfaceSchema: z.ZodEnum<{ | ||
| pear_v3: "pear_v3"; | ||
| pear_pro: "pear_pro"; | ||
| base_mini: "base_mini"; | ||
| web: "web"; | ||
| }>; | ||
| type ChatSurface = z.infer<typeof ChatSurfaceSchema>; | ||
| declare const TicketActionSchema: z.ZodEnum<{ | ||
| open_position: "open_position"; | ||
| close_position: "close_position"; | ||
| close_all_positions: "close_all_positions"; | ||
| adjust_position: "adjust_position"; | ||
| adjust_advance_position: "adjust_advance_position"; | ||
| reverse_position: "reverse_position"; | ||
| rebalance_position: "rebalance_position"; | ||
| set_risk_parameters: "set_risk_parameters"; | ||
| }>; | ||
| type TicketAction = z.infer<typeof TicketActionSchema>; | ||
| declare const TicketStatusSchema: z.ZodEnum<{ | ||
| PENDING: "PENDING"; | ||
| EXECUTING: "EXECUTING"; | ||
| EXECUTED: "EXECUTED"; | ||
| CANCELLED: "CANCELLED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| type TicketStatus = z.infer<typeof TicketStatusSchema>; | ||
| declare const PendingActionSchema: z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type PendingAction = z.infer<typeof PendingActionSchema>; | ||
| declare const ConfirmResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| status: z.ZodEnum<{ | ||
| EXECUTED: "EXECUTED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| result: z.ZodOptional<z.ZodUnknown>; | ||
| positionsSnapshot: z.ZodOptional<z.ZodUnknown>; | ||
| images: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$loose>; | ||
| type ConfirmResult = z.infer<typeof ConfirmResultSchema>; | ||
| declare const CancelResultSchema: z.ZodObject<{ | ||
| ok: z.ZodLiteral<true>; | ||
| status: z.ZodLiteral<"CANCELLED">; | ||
| }, z.core.$strip>; | ||
| type CancelResult = z.infer<typeof CancelResultSchema>; | ||
| declare const SetConfirmationsResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetConfirmationsResult = z.infer<typeof SetConfirmationsResultSchema>; | ||
| declare const TradeSettingsSchema: z.ZodObject<{ | ||
| executionEnabled: z.ZodBoolean; | ||
| confirmationsEnabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type TradeSettings = z.infer<typeof TradeSettingsSchema>; | ||
| declare const SetExecutionResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>; | ||
| type StreamEvent = (Extract<AgentWireEvent, { | ||
| type: "token"; | ||
| }> & { | ||
| delta: string; | ||
| }) | (Extract<AgentWireEvent, { | ||
| type: "thinking"; | ||
| }> & { | ||
| delta: string; | ||
| }) | Exclude<AgentWireEvent, { | ||
| type: "token" | "thinking"; | ||
| }>; | ||
| declare class AgentChatClient { | ||
| private readonly http; | ||
| constructor(config: AgentChatClientConfig); | ||
| listSessions(): Promise<SessionListItem[]>; | ||
| listSessionSummaries(): Promise<SessionSummary[]>; | ||
| createSession(): Promise<{ | ||
| id: string; | ||
| }>; | ||
| getSession(sessionId: string): Promise<Session>; | ||
| deleteSession(sessionId: string): Promise<void>; | ||
| getMessages(sessionId: string, opts?: { | ||
| limit?: number; | ||
| before?: string; | ||
| }): Promise<AgentChatMessage[]>; | ||
| streamChat(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| signal?: AbortSignal; | ||
| cta?: { | ||
| previousText: string; | ||
| question: string; | ||
| selectedOption: string; | ||
| }; | ||
| }): AsyncGenerator<StreamEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }>; | ||
| sendMessage(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| }): Promise<ChatResult>; | ||
| confirmTicket(ticketId: string): Promise<ConfirmResult>; | ||
| cancelTicket(ticketId: string): Promise<CancelResult>; | ||
| setTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult>; | ||
| getTradeSettings(): Promise<TradeSettings>; | ||
| setTradeExecution(enabled: boolean): Promise<SetExecutionResult>; | ||
| getLinkStatus(): Promise<LinkStatus>; | ||
| linkWallet(opts?: { | ||
| force?: boolean; | ||
| code?: string; | ||
| }): Promise<SelfLinkResult>; | ||
| unlinkWallet(): Promise<SelfUnlinkResult>; | ||
| } | ||
| export { type TwitterSource as $, AgentChatClient as A, type SessionSummary as B, type CancelResult as C, SessionSummarySchema as D, ErrorEventSchema as E, type SetConfirmationsResult as F, SetConfirmationsResultSchema as G, type SetExecutionResult as H, SetExecutionResultSchema as I, SourcesEventSchema as J, StatusEventSchema as K, type LinkStatus as L, type StreamEvent as M, type SuggestedAction as N, SuggestedActionSchema as O, type PendingAction as P, type TicketAction as Q, TicketActionSchema as R, type SelfLinkResult as S, ThinkingEventSchema as T, type TicketStatus as U, TicketStatusSchema as V, TokenEventSchema as W, type TradeLink as X, TradeLinkSchema as Y, type TradeSettings as Z, TradeSettingsSchema as _, type AgentChatClientConfig as a, TwitterSourceSchema as a0, type AgentChatMessage as b, AgentChatMessageSchema as c, type AgentEvent as d, type AgentWireEvent as e, AgentWireEventSchema as f, CancelResultSchema as g, type ChatMode as h, ChatModeSchema as i, type ChatResult as j, ChatResultSchema as k, type ChatSurface as l, ChatSurfaceSchema as m, type CitationSource as n, CitationSourceSchema as o, type ConfirmResult as p, ConfirmResultSchema as q, LinkStatusSchema as r, PendingActionSchema as s, SelfLinkResultSchema as t, type SelfUnlinkResult as u, SelfUnlinkResultSchema as v, type Session as w, type SessionListItem as x, SessionListItemSchema as y, SessionSchema as z }; |
+0
-2
@@ -102,4 +102,2 @@ 'use strict'; | ||
| "base_mini", | ||
| "tg_dm", | ||
| "tg_group", | ||
| "web" | ||
@@ -106,0 +104,0 @@ ]); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/protocol/primitives.ts","../src/protocol/tickets.ts","../src/protocol/events.ts","../src/protocol/link.ts","../src/protocol/messages.ts","../src/stream.ts","../src/client.ts"],"names":["z"],"mappings":";;;;;AAAO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EAChC,MAAA;AAAA,EACA,IAAA;AAAA,EACT,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAiB,IAAA,EAAe;AAC5D,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,OAAO,GAAA,CAAA,MAAA,CAAW,IAAA;AACvB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AACD;AAEO,IAAM,SAAA,GAAN,cAAwB,cAAA,CAAe;AAAC;AACxC,IAAM,cAAA,GAAN,cAA6B,cAAA,CAAe;AAAC;AAC7C,IAAM,aAAA,GAAN,cAA4B,cAAA,CAAe;AAAC;AAC5C,IAAM,kBAAA,GAAN,cAAiC,cAAA,CAAe;AAAC;AACjD,IAAM,cAAA,GAAN,cAA6B,cAAA,CAAe;AAAC;AAC7C,IAAM,WAAA,GAAN,cAA0B,cAAA,CAAe;AAAC;AAE1C,SAAS,eAAA,CAAgB,QAAgB,IAAA,EAA8B;AAC7E,EAAA,MAAM,GAAA,GAAM,CAAA,gBAAA,EAAmB,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,CAAA;AAC9C,EAAA,IAAI,WAAW,GAAA,EAAK,OAAO,IAAI,SAAA,CAAU,GAAA,EAAK,QAAQ,IAAI,CAAA;AAC1D,EAAA,IAAI,WAAW,GAAA,EAAK,OAAO,IAA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,CAC7D,KAAK,CAAC,GAAA,KAAQ,wBAAA,CAAyB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EACpD;AAAA;AAAA;AAAA,EAIA,aAAA,GAAqC;AACpC,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,KAAA,EAAO,wBAAwB,CAAA,CAC7C,IAAA,CAAK,CAAC,GAAA,KAAQ,gBAAA,CAAiB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW,IAAA,EAGiB;AAC3B,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,MAAA,EAAQ,0BAA0B,IAAA,IAAQ,EAAE,CAAA,CAC1D,KAAK,CAAC,GAAA,KAAQ,oBAAA,CAAqB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAChD;AAAA;AAAA,EAGA,YAAA,GAA0C;AACzC,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,QAAA,EAAU,wBAAwB,CAAA,CAChD,IAAA,CAAK,CAAC,GAAA,KAAQ,sBAAA,CAAuB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAClD;AACD","file":"index.cjs","sourcesContent":["export class AgentChatError extends Error {\n\treadonly status?: number;\n\treadonly body?: string;\n\tconstructor(message: string, status?: number, body?: string) {\n\t\tsuper(message);\n\t\tthis.name = new.target.name;\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class AuthError extends AgentChatError {}\nexport class ForbiddenError extends AgentChatError {}\nexport class ConflictError extends AgentChatError {}\nexport class TicketExpiredError extends AgentChatError {}\nexport class RateLimitError extends AgentChatError {}\nexport class ServerError extends AgentChatError {}\n\nexport function errorFromStatus(status: number, body: string): AgentChatError {\n\tconst msg = `Agent API error ${status}: ${body}`;\n\tif (status === 401) return new AuthError(msg, status, body);\n\tif (status === 403) return new ForbiddenError(msg, status, body);\n\tif (status === 409) return new ConflictError(msg, status, body);\n\tif (status === 410) return new TicketExpiredError(msg, status, body);\n\tif (status === 429) return new RateLimitError(msg, status, body);\n\tif (status >= 500) return new ServerError(msg, status, body);\n\treturn new AgentChatError(msg, status, body);\n}\n","import { errorFromStatus } from \"./errors\";\n\nexport interface AgentChatClientConfig {\n\t/** Base URL of the agent API, e.g. https://hl-v2-agent.pearprotocol.io */\n\tbaseUrl: string;\n\t/** Returns the freshest auth token (handles rotation). Required. */\n\tgetToken: () => string | Promise<string>;\n\t/** Sent as `X-Auth-Token-Version`. Defaults to \"v2\". */\n\ttokenVersion?: \"v2\" | \"v3\";\n\t/** Optional fetch override (SSR / tests). Defaults to global fetch. */\n\tfetch?: typeof fetch;\n}\n\nexport interface Http {\n\tbuildUrl: (path: string) => string;\n\tauthHeaders: () => Promise<Record<string, string>>;\n\t/** The resolved fetch — the single authoritative one (JSON + SSE share it). */\n\tfetch: typeof fetch;\n\tjson: <T>(method: string, path: string, body?: unknown) => Promise<T>;\n}\n\nexport function createHttp(config: AgentChatClientConfig): Http {\n\tconst baseUrl = config.baseUrl.replace(/\\/+$/, \"\");\n\tconst tokenVersion = config.tokenVersion ?? \"v2\";\n\tconst rawFetch = config.fetch ?? globalThis.fetch;\n\tif (!rawFetch) {\n\t\tthrow new Error(\"No fetch available — pass `fetch` in the client config\");\n\t}\n\t// Bind to globalThis. `fetch` is exposed on the Http object and the SSE path\n\t// invokes it as `http.fetch(...)` — called as a method, the browser's native\n\t// fetch runs with `this === the http object` and throws \"Illegal invocation\".\n\t// The JSON path calls it as a bare `doFetch(...)` (this === undefined), which\n\t// is why createSession worked but streamChat didn't. Binding pins `this`.\n\tconst doFetch: typeof fetch = rawFetch.bind(globalThis);\n\n\tconst buildUrl = (path: string): string =>\n\t\t`${baseUrl}${path.startsWith(\"/\") ? path : `/${path}`}`;\n\n\tconst authHeaders = async (): Promise<Record<string, string>> => {\n\t\tconst token = await config.getToken();\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\"X-Auth-Token-Version\": tokenVersion,\n\t\t};\n\t};\n\n\tconst json = async <T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> => {\n\t\tconst headers = await authHeaders();\n\t\tif (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n\t\tconst res = await doFetch(buildUrl(path), {\n\t\t\tmethod,\n\t\t\theaders,\n\t\t\tbody: body !== undefined ? JSON.stringify(body) : undefined,\n\t\t});\n\t\tif (!res.ok) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\t\tif (res.status === 204) return undefined as T;\n\t\tconst text = await res.text();\n\t\treturn (text ? JSON.parse(text) : undefined) as T;\n\t};\n\n\treturn { buildUrl, authHeaders, fetch: doFetch, json };\n}\n","import { z } from \"zod\";\n\n/** A Pear trade link surfaced with an agent reply. `platform` is left an open\n * string (not an enum) so a new venue doesn't break older SDK consumers. */\nexport const TradeLinkSchema = z.object({\n\tlink: z.string(),\n\tplatform: z.string(),\n\tlabel: z.string(),\n});\nexport type TradeLink = z.infer<typeof TradeLinkSchema>;\n\nexport const TwitterSourceSchema = z.object({\n\tauthor: z.string(),\n\ttweetUrl: z.string(),\n\tpublishedAt: z.string(),\n});\nexport type TwitterSource = z.infer<typeof TwitterSourceSchema>;\n\n/** Research web-citation. The research node emits a bare URL **string** on the\n * wire (research/agent.ts maps annotations -> `url_citation.url`); a future\n * object form is also accepted and normalized to `{ url, ... }`. */\nconst CitationObjectSchema = z.object({\n\turl: z.string(),\n\tstart_index: z.number().optional(),\n\tend_index: z.number().optional(),\n\ttitle: z.string().optional(),\n});\nexport const CitationSourceSchema = z.union([\n\tz.string().transform((url) => ({ url })),\n\tCitationObjectSchema,\n]);\nexport type CitationSource = z.infer<typeof CitationSourceSchema>;\n\nexport const SuggestedActionSchema = z.object({\n\tquestion: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type SuggestedAction = z.infer<typeof SuggestedActionSchema>;\n\nexport const ChatModeSchema = z.enum([\"standard\", \"advanced\"]);\nexport type ChatMode = z.infer<typeof ChatModeSchema>;\n\n/** The Pear client surface a chat request is from. Drives per-surface behavior\n * server-side (analysis universe / execution policy). Optional on the wire —\n * when omitted the server falls back to the sessionId-derived value. */\nexport const ChatSurfaceSchema = z.enum([\n\t\"pear_v3\",\n\t\"pear_pro\",\n\t\"base_mini\",\n\t\"tg_dm\",\n\t\"tg_group\",\n\t\"web\",\n]);\nexport type ChatSurface = z.infer<typeof ChatSurfaceSchema>;\n","import { z } from \"zod\";\n\n/** Known ticket actions. Used for typing; the wire `action` field is parsed\n * permissively (plain string) elsewhere for forward-compat. */\nexport const TicketActionSchema = z.enum([\n\t\"open_position\",\n\t\"close_position\",\n\t\"close_all_positions\",\n\t\"adjust_position\",\n\t\"adjust_advance_position\",\n\t\"reverse_position\",\n\t\"rebalance_position\",\n\t\"set_risk_parameters\",\n]);\nexport type TicketAction = z.infer<typeof TicketActionSchema>;\n\nexport const TicketStatusSchema = z.enum([\n\t\"PENDING\",\n\t\"EXECUTING\",\n\t\"EXECUTED\",\n\t\"CANCELLED\",\n\t\"FAILED\",\n]);\nexport type TicketStatus = z.infer<typeof TicketStatusSchema>;\n\n/** Surfaced on a turn when a money-moving write was FROZEN (nothing executed).\n * `action` is a plain string (forward-compatible); compare against\n * `TicketActionSchema.options` if you need to switch on known actions. */\nexport const PendingActionSchema = z.object({\n\tticketId: z.string(),\n\taction: z.string(),\n\tconsequence: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type PendingAction = z.infer<typeof PendingActionSchema>;\n\n/** Response of POST /trade/tickets/:id/confirm. Strict on the money fields,\n * loose (passthrough) on the action-specific `result` payload. `status` is\n * intentionally narrowed to the two TERMINAL confirm outcomes this endpoint\n * returns; widen to `TicketStatusSchema` if the BE can ever return another. */\nexport const ConfirmResultSchema = z.looseObject({\n\tok: z.boolean(),\n\tstatus: z.enum([\"EXECUTED\", \"FAILED\"]),\n\t// `.optional()` is load-bearing: in zod v4 `z.unknown()` is NO LONGER\n\t// implicitly optional, so dropping it would make these fields required.\n\tresult: z.unknown().optional(),\n\tpositionsSnapshot: z.unknown().optional(),\n\timages: z.array(z.string()).optional(),\n});\nexport type ConfirmResult = z.infer<typeof ConfirmResultSchema>;\n\nexport const CancelResultSchema = z.object({\n\tok: z.literal(true),\n\tstatus: z.literal(\"CANCELLED\"),\n});\nexport type CancelResult = z.infer<typeof CancelResultSchema>;\n\nexport const SetConfirmationsResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetConfirmationsResult = z.infer<\n\ttypeof SetConfirmationsResultSchema\n>;\n\n/** Response of GET /trade/tickets/settings — the caller's two independent trade\n * toggles. `executionEnabled` is the master execution switch (any write at all);\n * `confirmationsEnabled` is the confirm-before-write preference. */\nexport const TradeSettingsSchema = z.object({\n\texecutionEnabled: z.boolean(),\n\tconfirmationsEnabled: z.boolean(),\n});\nexport type TradeSettings = z.infer<typeof TradeSettingsSchema>;\n\n/** Response of POST /trade/tickets/execution — the new master-switch state. */\nexport const SetExecutionResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\nimport { PendingActionSchema } from \"./tickets\";\n\nexport const TokenEventSchema = z.object({\n\ttype: z.literal(\"token\"),\n\ttext: z.string(),\n});\n// `thinking` is emitted by ADVANCED mode only (the standard pipeline doesn't).\nexport const ThinkingEventSchema = z.object({\n\ttype: z.literal(\"thinking\"),\n\ttext: z.string(),\n});\nexport const StatusEventSchema = z.object({\n\ttype: z.literal(\"status\"),\n\ttext: z.string(),\n\tphase: z.enum([\"start\", \"end\"]).optional(),\n\tnode: z.string().optional(),\n});\nexport const SourcesEventSchema = z.object({\n\ttype: z.literal(\"sources\"),\n\t// `.catch` on every NON-critical field so a malformed metadata array can\n\t// never sink the whole event — `pendingAction` (a staged money-moving trade)\n\t// rides on this same frame and MUST always survive.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).catch([]).optional(), // resolved URL strings\n\tsuggestedAction: SuggestedActionSchema.nullish().catch(null),\n\t// pendingAction is deliberately NOT `.catch`-ed: a corrupt ticket must reject,\n\t// never be fabricated.\n\tpendingAction: PendingActionSchema.nullish(),\n});\nexport const ErrorEventSchema = z.object({\n\ttype: z.literal(\"error\"),\n\tmessage: z.string().optional(),\n});\n\n/** The discriminated union of events the SSE wire delivers. Parse each event\n * with `.safeParse`; on failure (unknown/legacy `cycle` etc.) IGNORE it — do\n * not throw. */\nexport const AgentWireEventSchema = z.discriminatedUnion(\"type\", [\n\tTokenEventSchema,\n\tThinkingEventSchema,\n\tStatusEventSchema,\n\tSourcesEventSchema,\n\tErrorEventSchema,\n]);\nexport type AgentWireEvent = z.infer<typeof AgentWireEventSchema>;\n\n/** Final assembled turn — the shape of `POST /chat` AND the SDK's synthetic\n * `done` event (the SSE wire has no `done` frame; the SDK assembles it). */\nexport const ChatResultSchema = z.object({\n\tfinalText: z.string(),\n\tsessionId: z.string().optional(),\n\t// Same money-path guard as SourcesEventSchema: metadata degrades to [] / null\n\t// on drift so a hard `.parse` can never throw away a real `pendingAction`.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).default([]),\n\tsuggestedAction: SuggestedActionSchema.nullable().default(null).catch(null),\n\tpendingAction: PendingActionSchema.nullable().default(null),\n});\nexport type ChatResult = z.infer<typeof ChatResultSchema>;\n\n/** The RAW wire union plus a synthetic terminal `done`. NOTE: the SDK actually\n * emits a NORMALIZED `StreamEvent` (token/thinking carry a `delta`) defined in\n * the SDK's stream module; this `AgentEvent` is the pre-normalization shape. */\nexport type AgentEvent = AgentWireEvent | { type: \"done\"; result: ChatResult };\n","import { z } from \"zod\";\n\n/** Response of GET /auth/link-wallet/self — whether the caller's wallet has a\n * WalletLink (i.e. the agent holds an API key and can execute trades). */\nexport const LinkStatusSchema = z.object({\n\tlinked: z.boolean(),\n\twalletAddress: z.string(),\n});\nexport type LinkStatus = z.infer<typeof LinkStatusSchema>;\n\n/** Response of POST /auth/link-wallet/self. `created` is true only when this\n * call minted a new key (false on the idempotent already-linked path). */\nexport const SelfLinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(true),\n\tcreated: z.boolean(),\n});\nexport type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>;\n\n/** Response of DELETE /auth/link-wallet/self. */\nexport const SelfUnlinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(false),\n});\nexport type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\n\nexport const SessionListItemSchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(), // ISO (Date serialized over the wire)\n});\nexport type SessionListItem = z.infer<typeof SessionListItemSchema>;\n\nexport const SessionSummarySchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n\tfirstUserMessage: z.string().optional(),\n\tlastUserMessage: z.string().optional(),\n\tlastUserMessageAt: z.string().optional(),\n\tlastAssistantMessageAt: z.string().optional(),\n});\nexport type SessionSummary = z.infer<typeof SessionSummarySchema>;\n\nexport const SessionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n});\nexport type Session = z.infer<typeof SessionSchema>;\n\n/** A persisted chat message (history). `images` are pre-resolved URL strings.\n * `z.looseObject` keeps unknown future fields instead of stripping them. */\nexport const AgentChatMessageSchema = z.looseObject({\n\tid: z.string(),\n\trole: z.string(),\n\tcontent: z.string(),\n\tcreatedAt: z.string(),\n\tresearchAnnotations: z.array(CitationSourceSchema).nullish(),\n\ttwitterSources: z.array(TwitterSourceSchema).nullish(),\n\ttradeLinks: z.array(TradeLinkSchema).nullish(),\n\timages: z.array(z.string()).nullish(),\n\tsuggestedAction: SuggestedActionSchema.nullish(),\n});\nexport type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>;\n","import { type AgentWireEvent, AgentWireEventSchema } from \"./protocol\";\n\n/** A token/thinking event normalized to expose an incremental `delta`. This\n * backend is DELTA-only on every path, so `delta === text` — there is no\n * cumulative reconciliation (a `startsWith` heuristic corrupts real output). */\nexport type StreamEvent =\n\t| (Extract<AgentWireEvent, { type: \"token\" }> & { delta: string })\n\t| (Extract<AgentWireEvent, { type: \"thinking\" }> & { delta: string })\n\t| Exclude<AgentWireEvent, { type: \"token\" | \"thinking\" }>;\n\nexport async function* parseSseStream(\n\tbody: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent> {\n\tconst reader = body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\t\t// Drain every complete `\\n\\n`-delimited frame in the buffer. `const idx`\n\t\t\t// is recomputed each iteration (no assignment-in-`while`-head: that trips\n\t\t\t// biome `noAssignInExpressions`, a non-auto-fixable CI error).\n\t\t\twhile (true) {\n\t\t\t\tconst idx = buffer.indexOf(\"\\n\\n\");\n\t\t\t\tif (idx < 0) break;\n\t\t\t\tconst rawEvent = buffer.slice(0, idx);\n\t\t\t\tbuffer = buffer.slice(idx + 2);\n\n\t\t\t\tconst lines = rawEvent.split(\"\\n\");\n\t\t\t\tconst eventLine = lines.find((l) => l.startsWith(\"event:\"));\n\t\t\t\tconst dataLine = lines.find((l) => l.startsWith(\"data:\"));\n\t\t\t\tif (!dataLine) continue;\n\t\t\t\tconst payloadText = dataLine.replace(/^data:\\s?/, \"\");\n\n\t\t\t\t// NestJS surfaces stream errors as `event: error\\ndata: <plain string>`\n\t\t\t\t// (NON-JSON). Detect it BEFORE JSON.parse so it isn't swallowed.\n\t\t\t\tif (eventLine?.replace(/^event:\\s?/, \"\") === \"error\") {\n\t\t\t\t\tyield { type: \"error\", message: payloadText };\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet json: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tjson = JSON.parse(payloadText);\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst parsed = AgentWireEventSchema.safeParse(json);\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\t// Never SILENTLY drop a money-path frame: if it looks like a sources\n\t\t\t\t\t// event carrying pendingAction, fail loud instead of losing a trade.\n\t\t\t\t\tif (\n\t\t\t\t\t\t(json as { type?: string })?.type === \"sources\" &&\n\t\t\t\t\t\t(json as { pendingAction?: unknown })?.pendingAction\n\t\t\t\t\t) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tmessage: \"malformed sources frame with pendingAction\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst ev = parsed.data;\n\t\t\t\tif (ev.type === \"token\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else if (ev.type === \"thinking\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else {\n\t\t\t\t\tyield ev;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} finally {\n\t\treader.cancel().catch(() => undefined);\n\t}\n}\n","import { AgentChatError, errorFromStatus } from \"./errors\";\nimport { type AgentChatClientConfig, createHttp, type Http } from \"./http\";\nimport {\n\ttype AgentChatMessage,\n\ttype CancelResult,\n\tCancelResultSchema,\n\ttype ChatMode,\n\ttype ChatResult,\n\tChatResultSchema,\n\ttype ChatSurface,\n\ttype ConfirmResult,\n\tConfirmResultSchema,\n\ttype LinkStatus,\n\tLinkStatusSchema,\n\tPendingActionSchema,\n\ttype SelfLinkResult,\n\tSelfLinkResultSchema,\n\ttype SelfUnlinkResult,\n\tSelfUnlinkResultSchema,\n\ttype Session,\n\ttype SessionListItem,\n\ttype SessionSummary,\n\ttype SetConfirmationsResult,\n\tSetConfirmationsResultSchema,\n\ttype SetExecutionResult,\n\tSetExecutionResultSchema,\n\ttype TradeSettings,\n\tTradeSettingsSchema,\n} from \"./protocol\";\nimport { parseSseStream, type StreamEvent } from \"./stream\";\n\n/** Parse a ChatResult but NEVER throw away a real `pendingAction` on metadata\n * drift: on a parse failure, fall back to a minimal result that preserves\n * `finalText` + `pendingAction` rather than rejecting the whole turn. */\nfunction parseChatResult(raw: unknown): ChatResult {\n\tconst parsed = ChatResultSchema.safeParse(raw);\n\tif (parsed.success) return parsed.data;\n\tconst r = raw as { finalText?: unknown; pendingAction?: unknown };\n\t// Salvage finalText, but NEVER fabricate a ticket: keep pendingAction only if\n\t// it INDEPENDENTLY validates — a corrupt ticket is dropped, never handed to\n\t// confirmTicket() (the money endpoint).\n\tconst pa = PendingActionSchema.safeParse(r?.pendingAction);\n\treturn {\n\t\tfinalText: typeof r?.finalText === \"string\" ? r.finalText : \"\",\n\t\timages: [],\n\t\tsuggestedAction: null,\n\t\tpendingAction: pa.success ? pa.data : null,\n\t};\n}\n\nfunction assembleResult(\n\tsessionId: string,\n\tfinalText: string,\n\tsources: Extract<StreamEvent, { type: \"sources\" }> | undefined,\n): ChatResult {\n\treturn parseChatResult({\n\t\tfinalText,\n\t\tsessionId,\n\t\tresearchAnnotations: sources?.researchAnnotations,\n\t\ttwitterSources: sources?.twitterSources,\n\t\ttradeLinks: sources?.tradeLinks,\n\t\timages: sources?.images ?? [],\n\t\tsuggestedAction: sources?.suggestedAction ?? null,\n\t\tpendingAction: sources?.pendingAction ?? null,\n\t});\n}\n\nexport class AgentChatClient {\n\tprivate readonly http: Http;\n\n\tconstructor(config: AgentChatClientConfig) {\n\t\tthis.http = createHttp(config);\n\t}\n\n\tlistSessions(): Promise<SessionListItem[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions\");\n\t}\n\n\tlistSessionSummaries(): Promise<SessionSummary[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions/summary\");\n\t}\n\n\tcreateSession(): Promise<{ id: string }> {\n\t\treturn this.http.json(\"POST\", \"/chat/sessions\");\n\t}\n\n\tgetSession(sessionId: string): Promise<Session> {\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tasync deleteSession(sessionId: string): Promise<void> {\n\t\tawait this.http.json(\n\t\t\t\"DELETE\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tgetMessages(\n\t\tsessionId: string,\n\t\topts?: { limit?: number; before?: string },\n\t): Promise<AgentChatMessage[]> {\n\t\tconst params = new URLSearchParams();\n\t\tif (opts?.limit !== undefined) params.set(\"limit\", String(opts.limit));\n\t\tif (opts?.before) params.set(\"before\", opts.before);\n\t\tconst qs = params.toString();\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : \"\"}`,\n\t\t);\n\t}\n\n\t/** Stream a turn. Yields token/thinking/status/sources events, then a\n\t * synthetic `{type:'done', result}` assembled from accumulated token deltas +\n\t * the final `sources` payload (the SSE wire has no `done` frame). Throws an\n\t * `AgentChatError` if the backend emits a mid-stream `error` frame. */\n\tasync *streamChat(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Declares the client surface (pear_v3 / pear_pro / base_mini / …). Required —\n\t\t * the API rejects requests without a valid surface. Drives per-surface behavior. */\n\t\tsurface: ChatSurface;\n\t\tsignal?: AbortSignal;\n\t\t/** CTA callback — set when the user clicks a suggested-action option; the\n\t\t * agent rebuilds the turn from this context server-side. */\n\t\tcta?: { previousText: string; question: string; selectedOption: string };\n\t}): AsyncGenerator<StreamEvent | { type: \"done\"; result: ChatResult }> {\n\t\tconst params = new URLSearchParams({\n\t\t\tmessage: args.message,\n\t\t\tsessionId: args.sessionId,\n\t\t\tmode: args.mode ?? \"standard\",\n\t\t});\n\t\tparams.set(\"surface\", args.surface);\n\t\tif (args.cta) {\n\t\t\tparams.set(\"suggestedActionPreviousText\", args.cta.previousText);\n\t\t\tparams.set(\"suggestedActionQuestion\", args.cta.question);\n\t\t\tparams.set(\"suggestedActionSelectedOption\", args.cta.selectedOption);\n\t\t}\n\t\tconst headers = await this.http.authHeaders();\n\t\theaders.Accept = \"text/event-stream\";\n\t\tconst res = await this.http.fetch(\n\t\t\tthis.http.buildUrl(`/chat/stream?${params.toString()}`),\n\t\t\t{ method: \"GET\", headers, signal: args.signal },\n\t\t);\n\t\tif (!res.ok || !res.body) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\n\t\tlet finalText = \"\";\n\t\tlet sources: Extract<StreamEvent, { type: \"sources\" }> | undefined;\n\t\tfor await (const ev of parseSseStream(res.body)) {\n\t\t\tif (ev.type === \"error\") {\n\t\t\t\tthrow new AgentChatError(ev.message ?? \"Agent stream error\");\n\t\t\t}\n\t\t\tif (ev.type === \"token\") finalText += ev.delta;\n\t\t\tif (ev.type === \"sources\") sources = ev;\n\t\t\tyield ev;\n\t\t}\n\n\t\tyield {\n\t\t\ttype: \"done\",\n\t\t\tresult: assembleResult(args.sessionId, finalText, sources),\n\t\t};\n\t}\n\n\t/** Sync send (POST /chat). Prefer `streamChat` for UX. */\n\tsendMessage(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Required — the API rejects requests without a valid surface. */\n\t\tsurface: ChatSurface;\n\t}): Promise<ChatResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/chat\", {\n\t\t\t\tmessage: args.message,\n\t\t\t\tsessionId: args.sessionId,\n\t\t\t\tmode: args.mode ?? \"standard\",\n\t\t\t\tsurface: args.surface,\n\t\t\t})\n\t\t\t.then(parseChatResult);\n\t}\n\n\tconfirmTicket(ticketId: string): Promise<ConfirmResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/confirm`,\n\t\t\t)\n\t\t\t.then((raw) => ConfirmResultSchema.parse(raw));\n\t}\n\n\tcancelTicket(ticketId: string): Promise<CancelResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/cancel`,\n\t\t\t)\n\t\t\t.then((raw) => CancelResultSchema.parse(raw));\n\t}\n\n\tsetTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/settings\", { enabled })\n\t\t\t.then((raw) => SetConfirmationsResultSchema.parse(raw));\n\t}\n\n\t/** Read both trade toggles for the caller wallet: the master execution switch\n\t * and the confirm-before-write preference. */\n\tgetTradeSettings(): Promise<TradeSettings> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/trade/tickets/settings\")\n\t\t\t.then((raw) => TradeSettingsSchema.parse(raw));\n\t}\n\n\t/** Flip the caller's master execution switch. `false` opts the wallet out of\n\t * all money-moving writes; `true` restores the default-ON state. */\n\tsetTradeExecution(enabled: boolean): Promise<SetExecutionResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/execution\", { enabled })\n\t\t\t.then((raw) => SetExecutionResultSchema.parse(raw));\n\t}\n\n\t/** Whether the caller's wallet is linked to the agent (i.e. the agent can\n\t * execute trades for it). Backend-verified — don't cache this locally. */\n\tgetLinkStatus(): Promise<LinkStatus> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => LinkStatusSchema.parse(raw));\n\t}\n\n\t/** Link the caller's wallet: the agent mints a Pear API key server-side AS\n\t * the caller (their token is forwarded) — the key never exists client-side.\n\t * Idempotent when already linked; `force` re-mints (recovery), `code` binds\n\t * a Telegram identity (replaces the legacy secret-based flow). */\n\tlinkWallet(opts?: {\n\t\tforce?: boolean;\n\t\tcode?: string;\n\t}): Promise<SelfLinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/auth/link-wallet/self\", opts ?? {})\n\t\t\t.then((raw) => SelfLinkResultSchema.parse(raw));\n\t}\n\n\t/** Unlink the caller's wallet — the agent loses trade authority. */\n\tunlinkWallet(): Promise<SelfUnlinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"DELETE\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => SelfUnlinkResultSchema.parse(raw));\n\t}\n}\n"]} | ||
| {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/protocol/primitives.ts","../src/protocol/tickets.ts","../src/protocol/events.ts","../src/protocol/link.ts","../src/protocol/messages.ts","../src/stream.ts","../src/client.ts"],"names":["z"],"mappings":";;;;;AAAO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EAChC,MAAA;AAAA,EACA,IAAA;AAAA,EACT,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAiB,IAAA,EAAe;AAC5D,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,OAAO,GAAA,CAAA,MAAA,CAAW,IAAA;AACvB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA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U,wBAAwB,CAAA,CAChD,IAAA,CAAK,CAAC,GAAA,KAAQ,sBAAA,CAAuB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAClD;AACD","file":"index.cjs","sourcesContent":["export class AgentChatError extends Error {\n\treadonly status?: number;\n\treadonly body?: string;\n\tconstructor(message: string, status?: number, body?: string) {\n\t\tsuper(message);\n\t\tthis.name = new.target.name;\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class AuthError extends AgentChatError {}\nexport class ForbiddenError extends AgentChatError {}\nexport class ConflictError extends AgentChatError {}\nexport class TicketExpiredError extends AgentChatError {}\nexport class RateLimitError extends AgentChatError {}\nexport class ServerError extends AgentChatError {}\n\nexport function errorFromStatus(status: number, body: string): AgentChatError {\n\tconst msg = `Agent API error ${status}: ${body}`;\n\tif (status === 401) return new AuthError(msg, status, body);\n\tif (status === 403) return new ForbiddenError(msg, status, body);\n\tif (status === 409) return new ConflictError(msg, status, body);\n\tif (status === 410) return new TicketExpiredError(msg, status, body);\n\tif (status === 429) return new RateLimitError(msg, status, body);\n\tif (status >= 500) return new ServerError(msg, status, body);\n\treturn new AgentChatError(msg, status, body);\n}\n","import { errorFromStatus } from \"./errors\";\n\nexport interface AgentChatClientConfig {\n\t/** Base URL of the agent API, e.g. https://hl-v2-agent.pearprotocol.io */\n\tbaseUrl: string;\n\t/** Returns the freshest auth token (handles rotation). Required. */\n\tgetToken: () => string | Promise<string>;\n\t/** Sent as `X-Auth-Token-Version`. Defaults to \"v2\". */\n\ttokenVersion?: \"v2\" | \"v3\";\n\t/** Optional fetch override (SSR / tests). Defaults to global fetch. */\n\tfetch?: typeof fetch;\n}\n\nexport interface Http {\n\tbuildUrl: (path: string) => string;\n\tauthHeaders: () => Promise<Record<string, string>>;\n\t/** The resolved fetch — the single authoritative one (JSON + SSE share it). */\n\tfetch: typeof fetch;\n\tjson: <T>(method: string, path: string, body?: unknown) => Promise<T>;\n}\n\nexport function createHttp(config: AgentChatClientConfig): Http {\n\tconst baseUrl = config.baseUrl.replace(/\\/+$/, \"\");\n\tconst tokenVersion = config.tokenVersion ?? \"v2\";\n\tconst rawFetch = config.fetch ?? globalThis.fetch;\n\tif (!rawFetch) {\n\t\tthrow new Error(\"No fetch available — pass `fetch` in the client config\");\n\t}\n\t// Bind to globalThis. `fetch` is exposed on the Http object and the SSE path\n\t// invokes it as `http.fetch(...)` — called as a method, the browser's native\n\t// fetch runs with `this === the http object` and throws \"Illegal invocation\".\n\t// The JSON path calls it as a bare `doFetch(...)` (this === undefined), which\n\t// is why createSession worked but streamChat didn't. Binding pins `this`.\n\tconst doFetch: typeof fetch = rawFetch.bind(globalThis);\n\n\tconst buildUrl = (path: string): string =>\n\t\t`${baseUrl}${path.startsWith(\"/\") ? path : `/${path}`}`;\n\n\tconst authHeaders = async (): Promise<Record<string, string>> => {\n\t\tconst token = await config.getToken();\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\"X-Auth-Token-Version\": tokenVersion,\n\t\t};\n\t};\n\n\tconst json = async <T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> => {\n\t\tconst headers = await authHeaders();\n\t\tif (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n\t\tconst res = await doFetch(buildUrl(path), {\n\t\t\tmethod,\n\t\t\theaders,\n\t\t\tbody: body !== undefined ? JSON.stringify(body) : undefined,\n\t\t});\n\t\tif (!res.ok) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\t\tif (res.status === 204) return undefined as T;\n\t\tconst text = await res.text();\n\t\treturn (text ? JSON.parse(text) : undefined) as T;\n\t};\n\n\treturn { buildUrl, authHeaders, fetch: doFetch, json };\n}\n","import { z } from \"zod\";\n\n/** A Pear trade link surfaced with an agent reply. `platform` is left an open\n * string (not an enum) so a new venue doesn't break older SDK consumers. */\nexport const TradeLinkSchema = z.object({\n\tlink: z.string(),\n\tplatform: z.string(),\n\tlabel: z.string(),\n});\nexport type TradeLink = z.infer<typeof TradeLinkSchema>;\n\nexport const TwitterSourceSchema = z.object({\n\tauthor: z.string(),\n\ttweetUrl: z.string(),\n\tpublishedAt: z.string(),\n});\nexport type TwitterSource = z.infer<typeof TwitterSourceSchema>;\n\n/** Research web-citation. The research node emits a bare URL **string** on the\n * wire (research/agent.ts maps annotations -> `url_citation.url`); a future\n * object form is also accepted and normalized to `{ url, ... }`. */\nconst CitationObjectSchema = z.object({\n\turl: z.string(),\n\tstart_index: z.number().optional(),\n\tend_index: z.number().optional(),\n\ttitle: z.string().optional(),\n});\nexport const CitationSourceSchema = z.union([\n\tz.string().transform((url) => ({ url })),\n\tCitationObjectSchema,\n]);\nexport type CitationSource = z.infer<typeof CitationSourceSchema>;\n\nexport const SuggestedActionSchema = z.object({\n\tquestion: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type SuggestedAction = z.infer<typeof SuggestedActionSchema>;\n\nexport const ChatModeSchema = z.enum([\"standard\", \"advanced\"]);\nexport type ChatMode = z.infer<typeof ChatModeSchema>;\n\n/** The Pear client surface a chat request declares — drives per-surface behavior\n * server-side (analysis universe / execution policy). REQUIRED on the wire. The\n * Telegram surfaces (tg_dm / tg_group) are resolved server-side from the TG\n * session and are NOT client-declarable, so they're intentionally absent here. */\nexport const ChatSurfaceSchema = z.enum([\n\t\"pear_v3\",\n\t\"pear_pro\",\n\t\"base_mini\",\n\t\"web\",\n]);\nexport type ChatSurface = z.infer<typeof ChatSurfaceSchema>;\n","import { z } from \"zod\";\n\n/** Known ticket actions. Used for typing; the wire `action` field is parsed\n * permissively (plain string) elsewhere for forward-compat. */\nexport const TicketActionSchema = z.enum([\n\t\"open_position\",\n\t\"close_position\",\n\t\"close_all_positions\",\n\t\"adjust_position\",\n\t\"adjust_advance_position\",\n\t\"reverse_position\",\n\t\"rebalance_position\",\n\t\"set_risk_parameters\",\n]);\nexport type TicketAction = z.infer<typeof TicketActionSchema>;\n\nexport const TicketStatusSchema = z.enum([\n\t\"PENDING\",\n\t\"EXECUTING\",\n\t\"EXECUTED\",\n\t\"CANCELLED\",\n\t\"FAILED\",\n]);\nexport type TicketStatus = z.infer<typeof TicketStatusSchema>;\n\n/** Surfaced on a turn when a money-moving write was FROZEN (nothing executed).\n * `action` is a plain string (forward-compatible); compare against\n * `TicketActionSchema.options` if you need to switch on known actions. */\nexport const PendingActionSchema = z.object({\n\tticketId: z.string(),\n\taction: z.string(),\n\tconsequence: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type PendingAction = z.infer<typeof PendingActionSchema>;\n\n/** Response of POST /trade/tickets/:id/confirm. Strict on the money fields,\n * loose (passthrough) on the action-specific `result` payload. `status` is\n * intentionally narrowed to the two TERMINAL confirm outcomes this endpoint\n * returns; widen to `TicketStatusSchema` if the BE can ever return another. */\nexport const ConfirmResultSchema = z.looseObject({\n\tok: z.boolean(),\n\tstatus: z.enum([\"EXECUTED\", \"FAILED\"]),\n\t// `.optional()` is load-bearing: in zod v4 `z.unknown()` is NO LONGER\n\t// implicitly optional, so dropping it would make these fields required.\n\tresult: z.unknown().optional(),\n\tpositionsSnapshot: z.unknown().optional(),\n\timages: z.array(z.string()).optional(),\n});\nexport type ConfirmResult = z.infer<typeof ConfirmResultSchema>;\n\nexport const CancelResultSchema = z.object({\n\tok: z.literal(true),\n\tstatus: z.literal(\"CANCELLED\"),\n});\nexport type CancelResult = z.infer<typeof CancelResultSchema>;\n\nexport const SetConfirmationsResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetConfirmationsResult = z.infer<\n\ttypeof SetConfirmationsResultSchema\n>;\n\n/** Response of GET /trade/tickets/settings — the caller's two independent trade\n * toggles. `executionEnabled` is the master execution switch (any write at all);\n * `confirmationsEnabled` is the confirm-before-write preference. */\nexport const TradeSettingsSchema = z.object({\n\texecutionEnabled: z.boolean(),\n\tconfirmationsEnabled: z.boolean(),\n});\nexport type TradeSettings = z.infer<typeof TradeSettingsSchema>;\n\n/** Response of POST /trade/tickets/execution — the new master-switch state. */\nexport const SetExecutionResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\nimport { PendingActionSchema } from \"./tickets\";\n\nexport const TokenEventSchema = z.object({\n\ttype: z.literal(\"token\"),\n\ttext: z.string(),\n});\n// `thinking` is emitted by ADVANCED mode only (the standard pipeline doesn't).\nexport const ThinkingEventSchema = z.object({\n\ttype: z.literal(\"thinking\"),\n\ttext: z.string(),\n});\nexport const StatusEventSchema = z.object({\n\ttype: z.literal(\"status\"),\n\ttext: z.string(),\n\tphase: z.enum([\"start\", \"end\"]).optional(),\n\tnode: z.string().optional(),\n});\nexport const SourcesEventSchema = z.object({\n\ttype: z.literal(\"sources\"),\n\t// `.catch` on every NON-critical field so a malformed metadata array can\n\t// never sink the whole event — `pendingAction` (a staged money-moving trade)\n\t// rides on this same frame and MUST always survive.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).catch([]).optional(), // resolved URL strings\n\tsuggestedAction: SuggestedActionSchema.nullish().catch(null),\n\t// pendingAction is deliberately NOT `.catch`-ed: a corrupt ticket must reject,\n\t// never be fabricated.\n\tpendingAction: PendingActionSchema.nullish(),\n});\nexport const ErrorEventSchema = z.object({\n\ttype: z.literal(\"error\"),\n\tmessage: z.string().optional(),\n});\n\n/** The discriminated union of events the SSE wire delivers. Parse each event\n * with `.safeParse`; on failure (unknown/legacy `cycle` etc.) IGNORE it — do\n * not throw. */\nexport const AgentWireEventSchema = z.discriminatedUnion(\"type\", [\n\tTokenEventSchema,\n\tThinkingEventSchema,\n\tStatusEventSchema,\n\tSourcesEventSchema,\n\tErrorEventSchema,\n]);\nexport type AgentWireEvent = z.infer<typeof AgentWireEventSchema>;\n\n/** Final assembled turn — the shape of `POST /chat` AND the SDK's synthetic\n * `done` event (the SSE wire has no `done` frame; the SDK assembles it). */\nexport const ChatResultSchema = z.object({\n\tfinalText: z.string(),\n\tsessionId: z.string().optional(),\n\t// Same money-path guard as SourcesEventSchema: metadata degrades to [] / null\n\t// on drift so a hard `.parse` can never throw away a real `pendingAction`.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).default([]),\n\tsuggestedAction: SuggestedActionSchema.nullable().default(null).catch(null),\n\tpendingAction: PendingActionSchema.nullable().default(null),\n});\nexport type ChatResult = z.infer<typeof ChatResultSchema>;\n\n/** The RAW wire union plus a synthetic terminal `done`. NOTE: the SDK actually\n * emits a NORMALIZED `StreamEvent` (token/thinking carry a `delta`) defined in\n * the SDK's stream module; this `AgentEvent` is the pre-normalization shape. */\nexport type AgentEvent = AgentWireEvent | { type: \"done\"; result: ChatResult };\n","import { z } from \"zod\";\n\n/** Response of GET /auth/link-wallet/self — whether the caller's wallet has a\n * WalletLink (i.e. the agent holds an API key and can execute trades). */\nexport const LinkStatusSchema = z.object({\n\tlinked: z.boolean(),\n\twalletAddress: z.string(),\n});\nexport type LinkStatus = z.infer<typeof LinkStatusSchema>;\n\n/** Response of POST /auth/link-wallet/self. `created` is true only when this\n * call minted a new key (false on the idempotent already-linked path). */\nexport const SelfLinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(true),\n\tcreated: z.boolean(),\n});\nexport type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>;\n\n/** Response of DELETE /auth/link-wallet/self. */\nexport const SelfUnlinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(false),\n});\nexport type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\n\nexport const SessionListItemSchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(), // ISO (Date serialized over the wire)\n});\nexport type SessionListItem = z.infer<typeof SessionListItemSchema>;\n\nexport const SessionSummarySchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n\tfirstUserMessage: z.string().optional(),\n\tlastUserMessage: z.string().optional(),\n\tlastUserMessageAt: z.string().optional(),\n\tlastAssistantMessageAt: z.string().optional(),\n});\nexport type SessionSummary = z.infer<typeof SessionSummarySchema>;\n\nexport const SessionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n});\nexport type Session = z.infer<typeof SessionSchema>;\n\n/** A persisted chat message (history). `images` are pre-resolved URL strings.\n * `z.looseObject` keeps unknown future fields instead of stripping them. */\nexport const AgentChatMessageSchema = z.looseObject({\n\tid: z.string(),\n\trole: z.string(),\n\tcontent: z.string(),\n\tcreatedAt: z.string(),\n\tresearchAnnotations: z.array(CitationSourceSchema).nullish(),\n\ttwitterSources: z.array(TwitterSourceSchema).nullish(),\n\ttradeLinks: z.array(TradeLinkSchema).nullish(),\n\timages: z.array(z.string()).nullish(),\n\tsuggestedAction: SuggestedActionSchema.nullish(),\n});\nexport type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>;\n","import { type AgentWireEvent, AgentWireEventSchema } from \"./protocol\";\n\n/** A token/thinking event normalized to expose an incremental `delta`. This\n * backend is DELTA-only on every path, so `delta === text` — there is no\n * cumulative reconciliation (a `startsWith` heuristic corrupts real output). */\nexport type StreamEvent =\n\t| (Extract<AgentWireEvent, { type: \"token\" }> & { delta: string })\n\t| (Extract<AgentWireEvent, { type: \"thinking\" }> & { delta: string })\n\t| Exclude<AgentWireEvent, { type: \"token\" | \"thinking\" }>;\n\nexport async function* parseSseStream(\n\tbody: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent> {\n\tconst reader = body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\t\t// Drain every complete `\\n\\n`-delimited frame in the buffer. `const idx`\n\t\t\t// is recomputed each iteration (no assignment-in-`while`-head: that trips\n\t\t\t// biome `noAssignInExpressions`, a non-auto-fixable CI error).\n\t\t\twhile (true) {\n\t\t\t\tconst idx = buffer.indexOf(\"\\n\\n\");\n\t\t\t\tif (idx < 0) break;\n\t\t\t\tconst rawEvent = buffer.slice(0, idx);\n\t\t\t\tbuffer = buffer.slice(idx + 2);\n\n\t\t\t\tconst lines = rawEvent.split(\"\\n\");\n\t\t\t\tconst eventLine = lines.find((l) => l.startsWith(\"event:\"));\n\t\t\t\tconst dataLine = lines.find((l) => l.startsWith(\"data:\"));\n\t\t\t\tif (!dataLine) continue;\n\t\t\t\tconst payloadText = dataLine.replace(/^data:\\s?/, \"\");\n\n\t\t\t\t// NestJS surfaces stream errors as `event: error\\ndata: <plain string>`\n\t\t\t\t// (NON-JSON). Detect it BEFORE JSON.parse so it isn't swallowed.\n\t\t\t\tif (eventLine?.replace(/^event:\\s?/, \"\") === \"error\") {\n\t\t\t\t\tyield { type: \"error\", message: payloadText };\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet json: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tjson = JSON.parse(payloadText);\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst parsed = AgentWireEventSchema.safeParse(json);\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\t// Never SILENTLY drop a money-path frame: if it looks like a sources\n\t\t\t\t\t// event carrying pendingAction, fail loud instead of losing a trade.\n\t\t\t\t\tif (\n\t\t\t\t\t\t(json as { type?: string })?.type === \"sources\" &&\n\t\t\t\t\t\t(json as { pendingAction?: unknown })?.pendingAction\n\t\t\t\t\t) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tmessage: \"malformed sources frame with pendingAction\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst ev = parsed.data;\n\t\t\t\tif (ev.type === \"token\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else if (ev.type === \"thinking\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else {\n\t\t\t\t\tyield ev;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} finally {\n\t\treader.cancel().catch(() => undefined);\n\t}\n}\n","import { AgentChatError, errorFromStatus } from \"./errors\";\nimport { type AgentChatClientConfig, createHttp, type Http } from \"./http\";\nimport {\n\ttype AgentChatMessage,\n\ttype CancelResult,\n\tCancelResultSchema,\n\ttype ChatMode,\n\ttype ChatResult,\n\tChatResultSchema,\n\ttype ChatSurface,\n\ttype ConfirmResult,\n\tConfirmResultSchema,\n\ttype LinkStatus,\n\tLinkStatusSchema,\n\tPendingActionSchema,\n\ttype SelfLinkResult,\n\tSelfLinkResultSchema,\n\ttype SelfUnlinkResult,\n\tSelfUnlinkResultSchema,\n\ttype Session,\n\ttype SessionListItem,\n\ttype SessionSummary,\n\ttype SetConfirmationsResult,\n\tSetConfirmationsResultSchema,\n\ttype SetExecutionResult,\n\tSetExecutionResultSchema,\n\ttype TradeSettings,\n\tTradeSettingsSchema,\n} from \"./protocol\";\nimport { parseSseStream, type StreamEvent } from \"./stream\";\n\n/** Parse a ChatResult but NEVER throw away a real `pendingAction` on metadata\n * drift: on a parse failure, fall back to a minimal result that preserves\n * `finalText` + `pendingAction` rather than rejecting the whole turn. */\nfunction parseChatResult(raw: unknown): ChatResult {\n\tconst parsed = ChatResultSchema.safeParse(raw);\n\tif (parsed.success) return parsed.data;\n\tconst r = raw as { finalText?: unknown; pendingAction?: unknown };\n\t// Salvage finalText, but NEVER fabricate a ticket: keep pendingAction only if\n\t// it INDEPENDENTLY validates — a corrupt ticket is dropped, never handed to\n\t// confirmTicket() (the money endpoint).\n\tconst pa = PendingActionSchema.safeParse(r?.pendingAction);\n\treturn {\n\t\tfinalText: typeof r?.finalText === \"string\" ? r.finalText : \"\",\n\t\timages: [],\n\t\tsuggestedAction: null,\n\t\tpendingAction: pa.success ? pa.data : null,\n\t};\n}\n\nfunction assembleResult(\n\tsessionId: string,\n\tfinalText: string,\n\tsources: Extract<StreamEvent, { type: \"sources\" }> | undefined,\n): ChatResult {\n\treturn parseChatResult({\n\t\tfinalText,\n\t\tsessionId,\n\t\tresearchAnnotations: sources?.researchAnnotations,\n\t\ttwitterSources: sources?.twitterSources,\n\t\ttradeLinks: sources?.tradeLinks,\n\t\timages: sources?.images ?? [],\n\t\tsuggestedAction: sources?.suggestedAction ?? null,\n\t\tpendingAction: sources?.pendingAction ?? null,\n\t});\n}\n\nexport class AgentChatClient {\n\tprivate readonly http: Http;\n\n\tconstructor(config: AgentChatClientConfig) {\n\t\tthis.http = createHttp(config);\n\t}\n\n\tlistSessions(): Promise<SessionListItem[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions\");\n\t}\n\n\tlistSessionSummaries(): Promise<SessionSummary[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions/summary\");\n\t}\n\n\tcreateSession(): Promise<{ id: string }> {\n\t\treturn this.http.json(\"POST\", \"/chat/sessions\");\n\t}\n\n\tgetSession(sessionId: string): Promise<Session> {\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tasync deleteSession(sessionId: string): Promise<void> {\n\t\tawait this.http.json(\n\t\t\t\"DELETE\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tgetMessages(\n\t\tsessionId: string,\n\t\topts?: { limit?: number; before?: string },\n\t): Promise<AgentChatMessage[]> {\n\t\tconst params = new URLSearchParams();\n\t\tif (opts?.limit !== undefined) params.set(\"limit\", String(opts.limit));\n\t\tif (opts?.before) params.set(\"before\", opts.before);\n\t\tconst qs = params.toString();\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : \"\"}`,\n\t\t);\n\t}\n\n\t/** Stream a turn. Yields token/thinking/status/sources events, then a\n\t * synthetic `{type:'done', result}` assembled from accumulated token deltas +\n\t * the final `sources` payload (the SSE wire has no `done` frame). Throws an\n\t * `AgentChatError` if the backend emits a mid-stream `error` frame. */\n\tasync *streamChat(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Declares the client surface (pear_v3 / pear_pro / base_mini / …). Required —\n\t\t * the API rejects requests without a valid surface. Drives per-surface behavior. */\n\t\tsurface: ChatSurface;\n\t\tsignal?: AbortSignal;\n\t\t/** CTA callback — set when the user clicks a suggested-action option; the\n\t\t * agent rebuilds the turn from this context server-side. */\n\t\tcta?: { previousText: string; question: string; selectedOption: string };\n\t}): AsyncGenerator<StreamEvent | { type: \"done\"; result: ChatResult }> {\n\t\tconst params = new URLSearchParams({\n\t\t\tmessage: args.message,\n\t\t\tsessionId: args.sessionId,\n\t\t\tmode: args.mode ?? \"standard\",\n\t\t});\n\t\tparams.set(\"surface\", args.surface);\n\t\tif (args.cta) {\n\t\t\tparams.set(\"suggestedActionPreviousText\", args.cta.previousText);\n\t\t\tparams.set(\"suggestedActionQuestion\", args.cta.question);\n\t\t\tparams.set(\"suggestedActionSelectedOption\", args.cta.selectedOption);\n\t\t}\n\t\tconst headers = await this.http.authHeaders();\n\t\theaders.Accept = \"text/event-stream\";\n\t\tconst res = await this.http.fetch(\n\t\t\tthis.http.buildUrl(`/chat/stream?${params.toString()}`),\n\t\t\t{ method: \"GET\", headers, signal: args.signal },\n\t\t);\n\t\tif (!res.ok || !res.body) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\n\t\tlet finalText = \"\";\n\t\tlet sources: Extract<StreamEvent, { type: \"sources\" }> | undefined;\n\t\tfor await (const ev of parseSseStream(res.body)) {\n\t\t\tif (ev.type === \"error\") {\n\t\t\t\tthrow new AgentChatError(ev.message ?? \"Agent stream error\");\n\t\t\t}\n\t\t\tif (ev.type === \"token\") finalText += ev.delta;\n\t\t\tif (ev.type === \"sources\") sources = ev;\n\t\t\tyield ev;\n\t\t}\n\n\t\tyield {\n\t\t\ttype: \"done\",\n\t\t\tresult: assembleResult(args.sessionId, finalText, sources),\n\t\t};\n\t}\n\n\t/** Sync send (POST /chat). Prefer `streamChat` for UX. */\n\tsendMessage(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Required — the API rejects requests without a valid surface. */\n\t\tsurface: ChatSurface;\n\t}): Promise<ChatResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/chat\", {\n\t\t\t\tmessage: args.message,\n\t\t\t\tsessionId: args.sessionId,\n\t\t\t\tmode: args.mode ?? \"standard\",\n\t\t\t\tsurface: args.surface,\n\t\t\t})\n\t\t\t.then(parseChatResult);\n\t}\n\n\tconfirmTicket(ticketId: string): Promise<ConfirmResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/confirm`,\n\t\t\t)\n\t\t\t.then((raw) => ConfirmResultSchema.parse(raw));\n\t}\n\n\tcancelTicket(ticketId: string): Promise<CancelResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/cancel`,\n\t\t\t)\n\t\t\t.then((raw) => CancelResultSchema.parse(raw));\n\t}\n\n\tsetTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/settings\", { enabled })\n\t\t\t.then((raw) => SetConfirmationsResultSchema.parse(raw));\n\t}\n\n\t/** Read both trade toggles for the caller wallet: the master execution switch\n\t * and the confirm-before-write preference. */\n\tgetTradeSettings(): Promise<TradeSettings> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/trade/tickets/settings\")\n\t\t\t.then((raw) => TradeSettingsSchema.parse(raw));\n\t}\n\n\t/** Flip the caller's master execution switch. `false` opts the wallet out of\n\t * all money-moving writes; `true` restores the default-ON state. */\n\tsetTradeExecution(enabled: boolean): Promise<SetExecutionResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/execution\", { enabled })\n\t\t\t.then((raw) => SetExecutionResultSchema.parse(raw));\n\t}\n\n\t/** Whether the caller's wallet is linked to the agent (i.e. the agent can\n\t * execute trades for it). Backend-verified — don't cache this locally. */\n\tgetLinkStatus(): Promise<LinkStatus> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => LinkStatusSchema.parse(raw));\n\t}\n\n\t/** Link the caller's wallet: the agent mints a Pear API key server-side AS\n\t * the caller (their token is forwarded) — the key never exists client-side.\n\t * Idempotent when already linked; `force` re-mints (recovery), `code` binds\n\t * a Telegram identity (replaces the legacy secret-based flow). */\n\tlinkWallet(opts?: {\n\t\tforce?: boolean;\n\t\tcode?: string;\n\t}): Promise<SelfLinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/auth/link-wallet/self\", opts ?? {})\n\t\t\t.then((raw) => SelfLinkResultSchema.parse(raw));\n\t}\n\n\t/** Unlink the caller's wallet — the agent loses trade authority. */\n\tunlinkWallet(): Promise<SelfUnlinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"DELETE\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => SelfUnlinkResultSchema.parse(raw));\n\t}\n}\n"]} |
+1
-1
@@ -1,2 +0,2 @@ | ||
| export { A as AgentChatClient, a as AgentChatClientConfig, b as AgentChatMessage, c as AgentChatMessageSchema, d as AgentEvent, e as AgentWireEvent, f as AgentWireEventSchema, C as CancelResult, g as CancelResultSchema, h as ChatMode, i as ChatModeSchema, j as ChatResult, k as ChatResultSchema, l as ChatSurface, m as ChatSurfaceSchema, n as CitationSource, o as CitationSourceSchema, p as ConfirmResult, q as ConfirmResultSchema, E as ErrorEventSchema, L as LinkStatus, r as LinkStatusSchema, P as PendingAction, s as PendingActionSchema, S as SelfLinkResult, t as SelfLinkResultSchema, u as SelfUnlinkResult, v as SelfUnlinkResultSchema, w as Session, x as SessionListItem, y as SessionListItemSchema, z as SessionSchema, B as SessionSummary, D as SessionSummarySchema, F as SetConfirmationsResult, G as SetConfirmationsResultSchema, H as SetExecutionResult, I as SetExecutionResultSchema, J as SourcesEventSchema, K as StatusEventSchema, M as StreamEvent, N as SuggestedAction, O as SuggestedActionSchema, T as ThinkingEventSchema, Q as TicketAction, R as TicketActionSchema, U as TicketStatus, V as TicketStatusSchema, W as TokenEventSchema, X as TradeLink, Y as TradeLinkSchema, Z as TradeSettings, _ as TradeSettingsSchema, $ as TwitterSource, a0 as TwitterSourceSchema } from './client-CJNmyV0P.cjs'; | ||
| export { A as AgentChatClient, a as AgentChatClientConfig, b as AgentChatMessage, c as AgentChatMessageSchema, d as AgentEvent, e as AgentWireEvent, f as AgentWireEventSchema, C as CancelResult, g as CancelResultSchema, h as ChatMode, i as ChatModeSchema, j as ChatResult, k as ChatResultSchema, l as ChatSurface, m as ChatSurfaceSchema, n as CitationSource, o as CitationSourceSchema, p as ConfirmResult, q as ConfirmResultSchema, E as ErrorEventSchema, L as LinkStatus, r as LinkStatusSchema, P as PendingAction, s as PendingActionSchema, S as SelfLinkResult, t as SelfLinkResultSchema, u as SelfUnlinkResult, v as SelfUnlinkResultSchema, w as Session, x as SessionListItem, y as SessionListItemSchema, z as SessionSchema, B as SessionSummary, D as SessionSummarySchema, F as SetConfirmationsResult, G as SetConfirmationsResultSchema, H as SetExecutionResult, I as SetExecutionResultSchema, J as SourcesEventSchema, K as StatusEventSchema, M as StreamEvent, N as SuggestedAction, O as SuggestedActionSchema, T as ThinkingEventSchema, Q as TicketAction, R as TicketActionSchema, U as TicketStatus, V as TicketStatusSchema, W as TokenEventSchema, X as TradeLink, Y as TradeLinkSchema, Z as TradeSettings, _ as TradeSettingsSchema, $ as TwitterSource, a0 as TwitterSourceSchema } from './client-BSUkCr7k.cjs'; | ||
| import 'zod'; | ||
@@ -3,0 +3,0 @@ |
+1
-1
@@ -1,2 +0,2 @@ | ||
| export { A as AgentChatClient, a as AgentChatClientConfig, b as AgentChatMessage, c as AgentChatMessageSchema, d as AgentEvent, e as AgentWireEvent, f as AgentWireEventSchema, C as CancelResult, g as CancelResultSchema, h as ChatMode, i as ChatModeSchema, j as ChatResult, k as ChatResultSchema, l as ChatSurface, m as ChatSurfaceSchema, n as CitationSource, o as CitationSourceSchema, p as ConfirmResult, q as ConfirmResultSchema, E as ErrorEventSchema, L as LinkStatus, r as LinkStatusSchema, P as PendingAction, s as PendingActionSchema, S as SelfLinkResult, t as SelfLinkResultSchema, u as SelfUnlinkResult, v as SelfUnlinkResultSchema, w as Session, x as SessionListItem, y as SessionListItemSchema, z as SessionSchema, B as SessionSummary, D as SessionSummarySchema, F as SetConfirmationsResult, G as SetConfirmationsResultSchema, H as SetExecutionResult, I as SetExecutionResultSchema, J as SourcesEventSchema, K as StatusEventSchema, M as StreamEvent, N as SuggestedAction, O as SuggestedActionSchema, T as ThinkingEventSchema, Q as TicketAction, R as TicketActionSchema, U as TicketStatus, V as TicketStatusSchema, W as TokenEventSchema, X as TradeLink, Y as TradeLinkSchema, Z as TradeSettings, _ as TradeSettingsSchema, $ as TwitterSource, a0 as TwitterSourceSchema } from './client-CJNmyV0P.js'; | ||
| export { A as AgentChatClient, a as AgentChatClientConfig, b as AgentChatMessage, c as AgentChatMessageSchema, d as AgentEvent, e as AgentWireEvent, f as AgentWireEventSchema, C as CancelResult, g as CancelResultSchema, h as ChatMode, i as ChatModeSchema, j as ChatResult, k as ChatResultSchema, l as ChatSurface, m as ChatSurfaceSchema, n as CitationSource, o as CitationSourceSchema, p as ConfirmResult, q as ConfirmResultSchema, E as ErrorEventSchema, L as LinkStatus, r as LinkStatusSchema, P as PendingAction, s as PendingActionSchema, S as SelfLinkResult, t as SelfLinkResultSchema, u as SelfUnlinkResult, v as SelfUnlinkResultSchema, w as Session, x as SessionListItem, y as SessionListItemSchema, z as SessionSchema, B as SessionSummary, D as SessionSummarySchema, F as SetConfirmationsResult, G as SetConfirmationsResultSchema, H as SetExecutionResult, I as SetExecutionResultSchema, J as SourcesEventSchema, K as StatusEventSchema, M as StreamEvent, N as SuggestedAction, O as SuggestedActionSchema, T as ThinkingEventSchema, Q as TicketAction, R as TicketActionSchema, U as TicketStatus, V as TicketStatusSchema, W as TokenEventSchema, X as TradeLink, Y as TradeLinkSchema, Z as TradeSettings, _ as TradeSettingsSchema, $ as TwitterSource, a0 as TwitterSourceSchema } from './client-BSUkCr7k.js'; | ||
| import 'zod'; | ||
@@ -3,0 +3,0 @@ |
+0
-2
@@ -100,4 +100,2 @@ import { z } from 'zod'; | ||
| "base_mini", | ||
| "tg_dm", | ||
| "tg_group", | ||
| "web" | ||
@@ -104,0 +102,0 @@ ]); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/protocol/primitives.ts","../src/protocol/tickets.ts","../src/protocol/events.ts","../src/protocol/link.ts","../src/protocol/messages.ts","../src/stream.ts","../src/client.ts"],"names":["z"],"mappings":";;;AAAO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EAChC,M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CACV,IAAA,CAAc,MAAA,EAAQ,0BAA0B,IAAA,IAAQ,EAAE,CAAA,CAC1D,KAAK,CAAC,GAAA,KAAQ,oBAAA,CAAqB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAChD;AAAA;AAAA,EAGA,YAAA,GAA0C;AACzC,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,QAAA,EAAU,wBAAwB,CAAA,CAChD,IAAA,CAAK,CAAC,GAAA,KAAQ,sBAAA,CAAuB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAClD;AACD","file":"index.js","sourcesContent":["export class AgentChatError extends Error {\n\treadonly status?: number;\n\treadonly body?: string;\n\tconstructor(message: string, status?: number, body?: string) {\n\t\tsuper(message);\n\t\tthis.name = new.target.name;\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class AuthError extends AgentChatError {}\nexport class ForbiddenError extends AgentChatError {}\nexport class ConflictError extends AgentChatError {}\nexport class TicketExpiredError extends AgentChatError {}\nexport class RateLimitError extends AgentChatError {}\nexport class ServerError extends AgentChatError {}\n\nexport function errorFromStatus(status: number, body: string): AgentChatError {\n\tconst msg = `Agent API error ${status}: ${body}`;\n\tif (status === 401) return new AuthError(msg, status, body);\n\tif (status === 403) return new ForbiddenError(msg, status, body);\n\tif (status === 409) return new ConflictError(msg, status, body);\n\tif (status === 410) return new TicketExpiredError(msg, status, body);\n\tif (status === 429) return new RateLimitError(msg, status, body);\n\tif (status >= 500) return new ServerError(msg, status, body);\n\treturn new AgentChatError(msg, status, body);\n}\n","import { errorFromStatus } from \"./errors\";\n\nexport interface AgentChatClientConfig {\n\t/** Base URL of the agent API, e.g. https://hl-v2-agent.pearprotocol.io */\n\tbaseUrl: string;\n\t/** Returns the freshest auth token (handles rotation). Required. */\n\tgetToken: () => string | Promise<string>;\n\t/** Sent as `X-Auth-Token-Version`. Defaults to \"v2\". */\n\ttokenVersion?: \"v2\" | \"v3\";\n\t/** Optional fetch override (SSR / tests). Defaults to global fetch. */\n\tfetch?: typeof fetch;\n}\n\nexport interface Http {\n\tbuildUrl: (path: string) => string;\n\tauthHeaders: () => Promise<Record<string, string>>;\n\t/** The resolved fetch — the single authoritative one (JSON + SSE share it). */\n\tfetch: typeof fetch;\n\tjson: <T>(method: string, path: string, body?: unknown) => Promise<T>;\n}\n\nexport function createHttp(config: AgentChatClientConfig): Http {\n\tconst baseUrl = config.baseUrl.replace(/\\/+$/, \"\");\n\tconst tokenVersion = config.tokenVersion ?? \"v2\";\n\tconst rawFetch = config.fetch ?? globalThis.fetch;\n\tif (!rawFetch) {\n\t\tthrow new Error(\"No fetch available — pass `fetch` in the client config\");\n\t}\n\t// Bind to globalThis. `fetch` is exposed on the Http object and the SSE path\n\t// invokes it as `http.fetch(...)` — called as a method, the browser's native\n\t// fetch runs with `this === the http object` and throws \"Illegal invocation\".\n\t// The JSON path calls it as a bare `doFetch(...)` (this === undefined), which\n\t// is why createSession worked but streamChat didn't. Binding pins `this`.\n\tconst doFetch: typeof fetch = rawFetch.bind(globalThis);\n\n\tconst buildUrl = (path: string): string =>\n\t\t`${baseUrl}${path.startsWith(\"/\") ? path : `/${path}`}`;\n\n\tconst authHeaders = async (): Promise<Record<string, string>> => {\n\t\tconst token = await config.getToken();\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\"X-Auth-Token-Version\": tokenVersion,\n\t\t};\n\t};\n\n\tconst json = async <T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> => {\n\t\tconst headers = await authHeaders();\n\t\tif (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n\t\tconst res = await doFetch(buildUrl(path), {\n\t\t\tmethod,\n\t\t\theaders,\n\t\t\tbody: body !== undefined ? JSON.stringify(body) : undefined,\n\t\t});\n\t\tif (!res.ok) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\t\tif (res.status === 204) return undefined as T;\n\t\tconst text = await res.text();\n\t\treturn (text ? JSON.parse(text) : undefined) as T;\n\t};\n\n\treturn { buildUrl, authHeaders, fetch: doFetch, json };\n}\n","import { z } from \"zod\";\n\n/** A Pear trade link surfaced with an agent reply. `platform` is left an open\n * string (not an enum) so a new venue doesn't break older SDK consumers. */\nexport const TradeLinkSchema = z.object({\n\tlink: z.string(),\n\tplatform: z.string(),\n\tlabel: z.string(),\n});\nexport type TradeLink = z.infer<typeof TradeLinkSchema>;\n\nexport const TwitterSourceSchema = z.object({\n\tauthor: z.string(),\n\ttweetUrl: z.string(),\n\tpublishedAt: z.string(),\n});\nexport type TwitterSource = z.infer<typeof TwitterSourceSchema>;\n\n/** Research web-citation. The research node emits a bare URL **string** on the\n * wire (research/agent.ts maps annotations -> `url_citation.url`); a future\n * object form is also accepted and normalized to `{ url, ... }`. */\nconst CitationObjectSchema = z.object({\n\turl: z.string(),\n\tstart_index: z.number().optional(),\n\tend_index: z.number().optional(),\n\ttitle: z.string().optional(),\n});\nexport const CitationSourceSchema = z.union([\n\tz.string().transform((url) => ({ url })),\n\tCitationObjectSchema,\n]);\nexport type CitationSource = z.infer<typeof CitationSourceSchema>;\n\nexport const SuggestedActionSchema = z.object({\n\tquestion: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type SuggestedAction = z.infer<typeof SuggestedActionSchema>;\n\nexport const ChatModeSchema = z.enum([\"standard\", \"advanced\"]);\nexport type ChatMode = z.infer<typeof ChatModeSchema>;\n\n/** The Pear client surface a chat request is from. Drives per-surface behavior\n * server-side (analysis universe / execution policy). Optional on the wire —\n * when omitted the server falls back to the sessionId-derived value. */\nexport const ChatSurfaceSchema = z.enum([\n\t\"pear_v3\",\n\t\"pear_pro\",\n\t\"base_mini\",\n\t\"tg_dm\",\n\t\"tg_group\",\n\t\"web\",\n]);\nexport type ChatSurface = z.infer<typeof ChatSurfaceSchema>;\n","import { z } from \"zod\";\n\n/** Known ticket actions. Used for typing; the wire `action` field is parsed\n * permissively (plain string) elsewhere for forward-compat. */\nexport const TicketActionSchema = z.enum([\n\t\"open_position\",\n\t\"close_position\",\n\t\"close_all_positions\",\n\t\"adjust_position\",\n\t\"adjust_advance_position\",\n\t\"reverse_position\",\n\t\"rebalance_position\",\n\t\"set_risk_parameters\",\n]);\nexport type TicketAction = z.infer<typeof TicketActionSchema>;\n\nexport const TicketStatusSchema = z.enum([\n\t\"PENDING\",\n\t\"EXECUTING\",\n\t\"EXECUTED\",\n\t\"CANCELLED\",\n\t\"FAILED\",\n]);\nexport type TicketStatus = z.infer<typeof TicketStatusSchema>;\n\n/** Surfaced on a turn when a money-moving write was FROZEN (nothing executed).\n * `action` is a plain string (forward-compatible); compare against\n * `TicketActionSchema.options` if you need to switch on known actions. */\nexport const PendingActionSchema = z.object({\n\tticketId: z.string(),\n\taction: z.string(),\n\tconsequence: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type PendingAction = z.infer<typeof PendingActionSchema>;\n\n/** Response of POST /trade/tickets/:id/confirm. Strict on the money fields,\n * loose (passthrough) on the action-specific `result` payload. `status` is\n * intentionally narrowed to the two TERMINAL confirm outcomes this endpoint\n * returns; widen to `TicketStatusSchema` if the BE can ever return another. */\nexport const ConfirmResultSchema = z.looseObject({\n\tok: z.boolean(),\n\tstatus: z.enum([\"EXECUTED\", \"FAILED\"]),\n\t// `.optional()` is load-bearing: in zod v4 `z.unknown()` is NO LONGER\n\t// implicitly optional, so dropping it would make these fields required.\n\tresult: z.unknown().optional(),\n\tpositionsSnapshot: z.unknown().optional(),\n\timages: z.array(z.string()).optional(),\n});\nexport type ConfirmResult = z.infer<typeof ConfirmResultSchema>;\n\nexport const CancelResultSchema = z.object({\n\tok: z.literal(true),\n\tstatus: z.literal(\"CANCELLED\"),\n});\nexport type CancelResult = z.infer<typeof CancelResultSchema>;\n\nexport const SetConfirmationsResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetConfirmationsResult = z.infer<\n\ttypeof SetConfirmationsResultSchema\n>;\n\n/** Response of GET /trade/tickets/settings — the caller's two independent trade\n * toggles. `executionEnabled` is the master execution switch (any write at all);\n * `confirmationsEnabled` is the confirm-before-write preference. */\nexport const TradeSettingsSchema = z.object({\n\texecutionEnabled: z.boolean(),\n\tconfirmationsEnabled: z.boolean(),\n});\nexport type TradeSettings = z.infer<typeof TradeSettingsSchema>;\n\n/** Response of POST /trade/tickets/execution — the new master-switch state. */\nexport const SetExecutionResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\nimport { PendingActionSchema } from \"./tickets\";\n\nexport const TokenEventSchema = z.object({\n\ttype: z.literal(\"token\"),\n\ttext: z.string(),\n});\n// `thinking` is emitted by ADVANCED mode only (the standard pipeline doesn't).\nexport const ThinkingEventSchema = z.object({\n\ttype: z.literal(\"thinking\"),\n\ttext: z.string(),\n});\nexport const StatusEventSchema = z.object({\n\ttype: z.literal(\"status\"),\n\ttext: z.string(),\n\tphase: z.enum([\"start\", \"end\"]).optional(),\n\tnode: z.string().optional(),\n});\nexport const SourcesEventSchema = z.object({\n\ttype: z.literal(\"sources\"),\n\t// `.catch` on every NON-critical field so a malformed metadata array can\n\t// never sink the whole event — `pendingAction` (a staged money-moving trade)\n\t// rides on this same frame and MUST always survive.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).catch([]).optional(), // resolved URL strings\n\tsuggestedAction: SuggestedActionSchema.nullish().catch(null),\n\t// pendingAction is deliberately NOT `.catch`-ed: a corrupt ticket must reject,\n\t// never be fabricated.\n\tpendingAction: PendingActionSchema.nullish(),\n});\nexport const ErrorEventSchema = z.object({\n\ttype: z.literal(\"error\"),\n\tmessage: z.string().optional(),\n});\n\n/** The discriminated union of events the SSE wire delivers. Parse each event\n * with `.safeParse`; on failure (unknown/legacy `cycle` etc.) IGNORE it — do\n * not throw. */\nexport const AgentWireEventSchema = z.discriminatedUnion(\"type\", [\n\tTokenEventSchema,\n\tThinkingEventSchema,\n\tStatusEventSchema,\n\tSourcesEventSchema,\n\tErrorEventSchema,\n]);\nexport type AgentWireEvent = z.infer<typeof AgentWireEventSchema>;\n\n/** Final assembled turn — the shape of `POST /chat` AND the SDK's synthetic\n * `done` event (the SSE wire has no `done` frame; the SDK assembles it). */\nexport const ChatResultSchema = z.object({\n\tfinalText: z.string(),\n\tsessionId: z.string().optional(),\n\t// Same money-path guard as SourcesEventSchema: metadata degrades to [] / null\n\t// on drift so a hard `.parse` can never throw away a real `pendingAction`.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).default([]),\n\tsuggestedAction: SuggestedActionSchema.nullable().default(null).catch(null),\n\tpendingAction: PendingActionSchema.nullable().default(null),\n});\nexport type ChatResult = z.infer<typeof ChatResultSchema>;\n\n/** The RAW wire union plus a synthetic terminal `done`. NOTE: the SDK actually\n * emits a NORMALIZED `StreamEvent` (token/thinking carry a `delta`) defined in\n * the SDK's stream module; this `AgentEvent` is the pre-normalization shape. */\nexport type AgentEvent = AgentWireEvent | { type: \"done\"; result: ChatResult };\n","import { z } from \"zod\";\n\n/** Response of GET /auth/link-wallet/self — whether the caller's wallet has a\n * WalletLink (i.e. the agent holds an API key and can execute trades). */\nexport const LinkStatusSchema = z.object({\n\tlinked: z.boolean(),\n\twalletAddress: z.string(),\n});\nexport type LinkStatus = z.infer<typeof LinkStatusSchema>;\n\n/** Response of POST /auth/link-wallet/self. `created` is true only when this\n * call minted a new key (false on the idempotent already-linked path). */\nexport const SelfLinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(true),\n\tcreated: z.boolean(),\n});\nexport type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>;\n\n/** Response of DELETE /auth/link-wallet/self. */\nexport const SelfUnlinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(false),\n});\nexport type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\n\nexport const SessionListItemSchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(), // ISO (Date serialized over the wire)\n});\nexport type SessionListItem = z.infer<typeof SessionListItemSchema>;\n\nexport const SessionSummarySchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n\tfirstUserMessage: z.string().optional(),\n\tlastUserMessage: z.string().optional(),\n\tlastUserMessageAt: z.string().optional(),\n\tlastAssistantMessageAt: z.string().optional(),\n});\nexport type SessionSummary = z.infer<typeof SessionSummarySchema>;\n\nexport const SessionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n});\nexport type Session = z.infer<typeof SessionSchema>;\n\n/** A persisted chat message (history). `images` are pre-resolved URL strings.\n * `z.looseObject` keeps unknown future fields instead of stripping them. */\nexport const AgentChatMessageSchema = z.looseObject({\n\tid: z.string(),\n\trole: z.string(),\n\tcontent: z.string(),\n\tcreatedAt: z.string(),\n\tresearchAnnotations: z.array(CitationSourceSchema).nullish(),\n\ttwitterSources: z.array(TwitterSourceSchema).nullish(),\n\ttradeLinks: z.array(TradeLinkSchema).nullish(),\n\timages: z.array(z.string()).nullish(),\n\tsuggestedAction: SuggestedActionSchema.nullish(),\n});\nexport type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>;\n","import { type AgentWireEvent, AgentWireEventSchema } from \"./protocol\";\n\n/** A token/thinking event normalized to expose an incremental `delta`. This\n * backend is DELTA-only on every path, so `delta === text` — there is no\n * cumulative reconciliation (a `startsWith` heuristic corrupts real output). */\nexport type StreamEvent =\n\t| (Extract<AgentWireEvent, { type: \"token\" }> & { delta: string })\n\t| (Extract<AgentWireEvent, { type: \"thinking\" }> & { delta: string })\n\t| Exclude<AgentWireEvent, { type: \"token\" | \"thinking\" }>;\n\nexport async function* parseSseStream(\n\tbody: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent> {\n\tconst reader = body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\t\t// Drain every complete `\\n\\n`-delimited frame in the buffer. `const idx`\n\t\t\t// is recomputed each iteration (no assignment-in-`while`-head: that trips\n\t\t\t// biome `noAssignInExpressions`, a non-auto-fixable CI error).\n\t\t\twhile (true) {\n\t\t\t\tconst idx = buffer.indexOf(\"\\n\\n\");\n\t\t\t\tif (idx < 0) break;\n\t\t\t\tconst rawEvent = buffer.slice(0, idx);\n\t\t\t\tbuffer = buffer.slice(idx + 2);\n\n\t\t\t\tconst lines = rawEvent.split(\"\\n\");\n\t\t\t\tconst eventLine = lines.find((l) => l.startsWith(\"event:\"));\n\t\t\t\tconst dataLine = lines.find((l) => l.startsWith(\"data:\"));\n\t\t\t\tif (!dataLine) continue;\n\t\t\t\tconst payloadText = dataLine.replace(/^data:\\s?/, \"\");\n\n\t\t\t\t// NestJS surfaces stream errors as `event: error\\ndata: <plain string>`\n\t\t\t\t// (NON-JSON). Detect it BEFORE JSON.parse so it isn't swallowed.\n\t\t\t\tif (eventLine?.replace(/^event:\\s?/, \"\") === \"error\") {\n\t\t\t\t\tyield { type: \"error\", message: payloadText };\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet json: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tjson = JSON.parse(payloadText);\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst parsed = AgentWireEventSchema.safeParse(json);\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\t// Never SILENTLY drop a money-path frame: if it looks like a sources\n\t\t\t\t\t// event carrying pendingAction, fail loud instead of losing a trade.\n\t\t\t\t\tif (\n\t\t\t\t\t\t(json as { type?: string })?.type === \"sources\" &&\n\t\t\t\t\t\t(json as { pendingAction?: unknown })?.pendingAction\n\t\t\t\t\t) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tmessage: \"malformed sources frame with pendingAction\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst ev = parsed.data;\n\t\t\t\tif (ev.type === \"token\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else if (ev.type === \"thinking\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else {\n\t\t\t\t\tyield ev;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} finally {\n\t\treader.cancel().catch(() => undefined);\n\t}\n}\n","import { AgentChatError, errorFromStatus } from \"./errors\";\nimport { type AgentChatClientConfig, createHttp, type Http } from \"./http\";\nimport {\n\ttype AgentChatMessage,\n\ttype CancelResult,\n\tCancelResultSchema,\n\ttype ChatMode,\n\ttype ChatResult,\n\tChatResultSchema,\n\ttype ChatSurface,\n\ttype ConfirmResult,\n\tConfirmResultSchema,\n\ttype LinkStatus,\n\tLinkStatusSchema,\n\tPendingActionSchema,\n\ttype SelfLinkResult,\n\tSelfLinkResultSchema,\n\ttype SelfUnlinkResult,\n\tSelfUnlinkResultSchema,\n\ttype Session,\n\ttype SessionListItem,\n\ttype SessionSummary,\n\ttype SetConfirmationsResult,\n\tSetConfirmationsResultSchema,\n\ttype SetExecutionResult,\n\tSetExecutionResultSchema,\n\ttype TradeSettings,\n\tTradeSettingsSchema,\n} from \"./protocol\";\nimport { parseSseStream, type StreamEvent } from \"./stream\";\n\n/** Parse a ChatResult but NEVER throw away a real `pendingAction` on metadata\n * drift: on a parse failure, fall back to a minimal result that preserves\n * `finalText` + `pendingAction` rather than rejecting the whole turn. */\nfunction parseChatResult(raw: unknown): ChatResult {\n\tconst parsed = ChatResultSchema.safeParse(raw);\n\tif (parsed.success) return parsed.data;\n\tconst r = raw as { finalText?: unknown; pendingAction?: unknown };\n\t// Salvage finalText, but NEVER fabricate a ticket: keep pendingAction only if\n\t// it INDEPENDENTLY validates — a corrupt ticket is dropped, never handed to\n\t// confirmTicket() (the money endpoint).\n\tconst pa = PendingActionSchema.safeParse(r?.pendingAction);\n\treturn {\n\t\tfinalText: typeof r?.finalText === \"string\" ? r.finalText : \"\",\n\t\timages: [],\n\t\tsuggestedAction: null,\n\t\tpendingAction: pa.success ? pa.data : null,\n\t};\n}\n\nfunction assembleResult(\n\tsessionId: string,\n\tfinalText: string,\n\tsources: Extract<StreamEvent, { type: \"sources\" }> | undefined,\n): ChatResult {\n\treturn parseChatResult({\n\t\tfinalText,\n\t\tsessionId,\n\t\tresearchAnnotations: sources?.researchAnnotations,\n\t\ttwitterSources: sources?.twitterSources,\n\t\ttradeLinks: sources?.tradeLinks,\n\t\timages: sources?.images ?? [],\n\t\tsuggestedAction: sources?.suggestedAction ?? null,\n\t\tpendingAction: sources?.pendingAction ?? null,\n\t});\n}\n\nexport class AgentChatClient {\n\tprivate readonly http: Http;\n\n\tconstructor(config: AgentChatClientConfig) {\n\t\tthis.http = createHttp(config);\n\t}\n\n\tlistSessions(): Promise<SessionListItem[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions\");\n\t}\n\n\tlistSessionSummaries(): Promise<SessionSummary[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions/summary\");\n\t}\n\n\tcreateSession(): Promise<{ id: string }> {\n\t\treturn this.http.json(\"POST\", \"/chat/sessions\");\n\t}\n\n\tgetSession(sessionId: string): Promise<Session> {\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tasync deleteSession(sessionId: string): Promise<void> {\n\t\tawait this.http.json(\n\t\t\t\"DELETE\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tgetMessages(\n\t\tsessionId: string,\n\t\topts?: { limit?: number; before?: string },\n\t): Promise<AgentChatMessage[]> {\n\t\tconst params = new URLSearchParams();\n\t\tif (opts?.limit !== undefined) params.set(\"limit\", String(opts.limit));\n\t\tif (opts?.before) params.set(\"before\", opts.before);\n\t\tconst qs = params.toString();\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : \"\"}`,\n\t\t);\n\t}\n\n\t/** Stream a turn. Yields token/thinking/status/sources events, then a\n\t * synthetic `{type:'done', result}` assembled from accumulated token deltas +\n\t * the final `sources` payload (the SSE wire has no `done` frame). Throws an\n\t * `AgentChatError` if the backend emits a mid-stream `error` frame. */\n\tasync *streamChat(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Declares the client surface (pear_v3 / pear_pro / base_mini / …). Required —\n\t\t * the API rejects requests without a valid surface. Drives per-surface behavior. */\n\t\tsurface: ChatSurface;\n\t\tsignal?: AbortSignal;\n\t\t/** CTA callback — set when the user clicks a suggested-action option; the\n\t\t * agent rebuilds the turn from this context server-side. */\n\t\tcta?: { previousText: string; question: string; selectedOption: string };\n\t}): AsyncGenerator<StreamEvent | { type: \"done\"; result: ChatResult }> {\n\t\tconst params = new URLSearchParams({\n\t\t\tmessage: args.message,\n\t\t\tsessionId: args.sessionId,\n\t\t\tmode: args.mode ?? \"standard\",\n\t\t});\n\t\tparams.set(\"surface\", args.surface);\n\t\tif (args.cta) {\n\t\t\tparams.set(\"suggestedActionPreviousText\", args.cta.previousText);\n\t\t\tparams.set(\"suggestedActionQuestion\", args.cta.question);\n\t\t\tparams.set(\"suggestedActionSelectedOption\", args.cta.selectedOption);\n\t\t}\n\t\tconst headers = await this.http.authHeaders();\n\t\theaders.Accept = \"text/event-stream\";\n\t\tconst res = await this.http.fetch(\n\t\t\tthis.http.buildUrl(`/chat/stream?${params.toString()}`),\n\t\t\t{ method: \"GET\", headers, signal: args.signal },\n\t\t);\n\t\tif (!res.ok || !res.body) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\n\t\tlet finalText = \"\";\n\t\tlet sources: Extract<StreamEvent, { type: \"sources\" }> | undefined;\n\t\tfor await (const ev of parseSseStream(res.body)) {\n\t\t\tif (ev.type === \"error\") {\n\t\t\t\tthrow new AgentChatError(ev.message ?? \"Agent stream error\");\n\t\t\t}\n\t\t\tif (ev.type === \"token\") finalText += ev.delta;\n\t\t\tif (ev.type === \"sources\") sources = ev;\n\t\t\tyield ev;\n\t\t}\n\n\t\tyield {\n\t\t\ttype: \"done\",\n\t\t\tresult: assembleResult(args.sessionId, finalText, sources),\n\t\t};\n\t}\n\n\t/** Sync send (POST /chat). Prefer `streamChat` for UX. */\n\tsendMessage(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Required — the API rejects requests without a valid surface. */\n\t\tsurface: ChatSurface;\n\t}): Promise<ChatResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/chat\", {\n\t\t\t\tmessage: args.message,\n\t\t\t\tsessionId: args.sessionId,\n\t\t\t\tmode: args.mode ?? \"standard\",\n\t\t\t\tsurface: args.surface,\n\t\t\t})\n\t\t\t.then(parseChatResult);\n\t}\n\n\tconfirmTicket(ticketId: string): Promise<ConfirmResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/confirm`,\n\t\t\t)\n\t\t\t.then((raw) => ConfirmResultSchema.parse(raw));\n\t}\n\n\tcancelTicket(ticketId: string): Promise<CancelResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/cancel`,\n\t\t\t)\n\t\t\t.then((raw) => CancelResultSchema.parse(raw));\n\t}\n\n\tsetTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/settings\", { enabled })\n\t\t\t.then((raw) => SetConfirmationsResultSchema.parse(raw));\n\t}\n\n\t/** Read both trade toggles for the caller wallet: the master execution switch\n\t * and the confirm-before-write preference. */\n\tgetTradeSettings(): Promise<TradeSettings> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/trade/tickets/settings\")\n\t\t\t.then((raw) => TradeSettingsSchema.parse(raw));\n\t}\n\n\t/** Flip the caller's master execution switch. `false` opts the wallet out of\n\t * all money-moving writes; `true` restores the default-ON state. */\n\tsetTradeExecution(enabled: boolean): Promise<SetExecutionResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/execution\", { enabled })\n\t\t\t.then((raw) => SetExecutionResultSchema.parse(raw));\n\t}\n\n\t/** Whether the caller's wallet is linked to the agent (i.e. the agent can\n\t * execute trades for it). Backend-verified — don't cache this locally. */\n\tgetLinkStatus(): Promise<LinkStatus> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => LinkStatusSchema.parse(raw));\n\t}\n\n\t/** Link the caller's wallet: the agent mints a Pear API key server-side AS\n\t * the caller (their token is forwarded) — the key never exists client-side.\n\t * Idempotent when already linked; `force` re-mints (recovery), `code` binds\n\t * a Telegram identity (replaces the legacy secret-based flow). */\n\tlinkWallet(opts?: {\n\t\tforce?: boolean;\n\t\tcode?: string;\n\t}): Promise<SelfLinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/auth/link-wallet/self\", opts ?? {})\n\t\t\t.then((raw) => SelfLinkResultSchema.parse(raw));\n\t}\n\n\t/** Unlink the caller's wallet — the agent loses trade authority. */\n\tunlinkWallet(): Promise<SelfUnlinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"DELETE\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => SelfUnlinkResultSchema.parse(raw));\n\t}\n}\n"]} | ||
| {"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/protocol/primitives.ts","../src/protocol/tickets.ts","../src/protocol/events.ts","../src/protocol/link.ts","../src/protocol/messages.ts","../src/stream.ts","../src/client.ts"],"names":["z"],"mappings":";;;AAAO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EAChC,MAAA;AAAA,EACA,IAAA;AAAA,EACT,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAiB,IAAA,EAAe;AAC5D,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,OAAO,GAAA,CAAA,MAAA,CAAW,IAAA;AACvB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACb;AACD;AAEO,IAAM,SAAA,GAAN,cAAwB,cAAA,CAAe;AAAC;AACxC,IAAM,cAAA,GAAN,cAA6B,cAAA,CAAe;AAAC;AAC7C,IAAM,aAAA,GAAN,cAA4B,cAAA,CAAe;AAAC;AAC5C,IAAM,kBAAA,GAAN,cAAiC,cAAA,CAAe;AAAC;AACjD,IAAM,cAAA,GAAN,cAA6B,cAAA,CAAe;AAAC;AAC7C,IAAM,WAAA,GAAN,cAA0B,cAAA,CAAe;AAAC;AAE1C,SAAS,eAAA,CAAgB,QAAgB,IAAA,EAA8B;AAC7E,EAAA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AC,CAAA;AAAA,EAC/C;AAAA;AAAA;AAAA,EAIA,kBAAkB,OAAA,EAA+C;AAChE,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,MAAA,EAAQ,4BAA4B,EAAE,OAAA,EAAS,CAAA,CAC7D,KAAK,CAAC,GAAA,KAAQ,wBAAA,CAAyB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EACpD;AAAA;AAAA;AAAA,EAIA,aAAA,GAAqC;AACpC,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,KAAA,EAAO,wBAAwB,CAAA,CAC7C,IAAA,CAAK,CAAC,GAAA,KAAQ,gBAAA,CAAiB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW,IAAA,EAGiB;AAC3B,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,MAAA,EAAQ,0BAA0B,IAAA,IAAQ,EAAE,CAAA,CAC1D,KAAK,CAAC,GAAA,KAAQ,oBAAA,CAAqB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAChD;AAAA;AAAA,EAGA,YAAA,GAA0C;AACzC,IAAA,OAAO,IAAA,CAAK,IAAA,CACV,IAAA,CAAc,QAAA,EAAU,wBAAwB,CAAA,CAChD,IAAA,CAAK,CAAC,GAAA,KAAQ,sBAAA,CAAuB,KAAA,CAAM,GAAG,CAAC,CAAA;AAAA,EAClD;AACD","file":"index.js","sourcesContent":["export class AgentChatError extends Error {\n\treadonly status?: number;\n\treadonly body?: string;\n\tconstructor(message: string, status?: number, body?: string) {\n\t\tsuper(message);\n\t\tthis.name = new.target.name;\n\t\tthis.status = status;\n\t\tthis.body = body;\n\t}\n}\n\nexport class AuthError extends AgentChatError {}\nexport class ForbiddenError extends AgentChatError {}\nexport class ConflictError extends AgentChatError {}\nexport class TicketExpiredError extends AgentChatError {}\nexport class RateLimitError extends AgentChatError {}\nexport class ServerError extends AgentChatError {}\n\nexport function errorFromStatus(status: number, body: string): AgentChatError {\n\tconst msg = `Agent API error ${status}: ${body}`;\n\tif (status === 401) return new AuthError(msg, status, body);\n\tif (status === 403) return new ForbiddenError(msg, status, body);\n\tif (status === 409) return new ConflictError(msg, status, body);\n\tif (status === 410) return new TicketExpiredError(msg, status, body);\n\tif (status === 429) return new RateLimitError(msg, status, body);\n\tif (status >= 500) return new ServerError(msg, status, body);\n\treturn new AgentChatError(msg, status, body);\n}\n","import { errorFromStatus } from \"./errors\";\n\nexport interface AgentChatClientConfig {\n\t/** Base URL of the agent API, e.g. https://hl-v2-agent.pearprotocol.io */\n\tbaseUrl: string;\n\t/** Returns the freshest auth token (handles rotation). Required. */\n\tgetToken: () => string | Promise<string>;\n\t/** Sent as `X-Auth-Token-Version`. Defaults to \"v2\". */\n\ttokenVersion?: \"v2\" | \"v3\";\n\t/** Optional fetch override (SSR / tests). Defaults to global fetch. */\n\tfetch?: typeof fetch;\n}\n\nexport interface Http {\n\tbuildUrl: (path: string) => string;\n\tauthHeaders: () => Promise<Record<string, string>>;\n\t/** The resolved fetch — the single authoritative one (JSON + SSE share it). */\n\tfetch: typeof fetch;\n\tjson: <T>(method: string, path: string, body?: unknown) => Promise<T>;\n}\n\nexport function createHttp(config: AgentChatClientConfig): Http {\n\tconst baseUrl = config.baseUrl.replace(/\\/+$/, \"\");\n\tconst tokenVersion = config.tokenVersion ?? \"v2\";\n\tconst rawFetch = config.fetch ?? globalThis.fetch;\n\tif (!rawFetch) {\n\t\tthrow new Error(\"No fetch available — pass `fetch` in the client config\");\n\t}\n\t// Bind to globalThis. `fetch` is exposed on the Http object and the SSE path\n\t// invokes it as `http.fetch(...)` — called as a method, the browser's native\n\t// fetch runs with `this === the http object` and throws \"Illegal invocation\".\n\t// The JSON path calls it as a bare `doFetch(...)` (this === undefined), which\n\t// is why createSession worked but streamChat didn't. Binding pins `this`.\n\tconst doFetch: typeof fetch = rawFetch.bind(globalThis);\n\n\tconst buildUrl = (path: string): string =>\n\t\t`${baseUrl}${path.startsWith(\"/\") ? path : `/${path}`}`;\n\n\tconst authHeaders = async (): Promise<Record<string, string>> => {\n\t\tconst token = await config.getToken();\n\t\treturn {\n\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t\"X-Auth-Token-Version\": tokenVersion,\n\t\t};\n\t};\n\n\tconst json = async <T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody?: unknown,\n\t): Promise<T> => {\n\t\tconst headers = await authHeaders();\n\t\tif (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n\t\tconst res = await doFetch(buildUrl(path), {\n\t\t\tmethod,\n\t\t\theaders,\n\t\t\tbody: body !== undefined ? JSON.stringify(body) : undefined,\n\t\t});\n\t\tif (!res.ok) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\t\tif (res.status === 204) return undefined as T;\n\t\tconst text = await res.text();\n\t\treturn (text ? JSON.parse(text) : undefined) as T;\n\t};\n\n\treturn { buildUrl, authHeaders, fetch: doFetch, json };\n}\n","import { z } from \"zod\";\n\n/** A Pear trade link surfaced with an agent reply. `platform` is left an open\n * string (not an enum) so a new venue doesn't break older SDK consumers. */\nexport const TradeLinkSchema = z.object({\n\tlink: z.string(),\n\tplatform: z.string(),\n\tlabel: z.string(),\n});\nexport type TradeLink = z.infer<typeof TradeLinkSchema>;\n\nexport const TwitterSourceSchema = z.object({\n\tauthor: z.string(),\n\ttweetUrl: z.string(),\n\tpublishedAt: z.string(),\n});\nexport type TwitterSource = z.infer<typeof TwitterSourceSchema>;\n\n/** Research web-citation. The research node emits a bare URL **string** on the\n * wire (research/agent.ts maps annotations -> `url_citation.url`); a future\n * object form is also accepted and normalized to `{ url, ... }`. */\nconst CitationObjectSchema = z.object({\n\turl: z.string(),\n\tstart_index: z.number().optional(),\n\tend_index: z.number().optional(),\n\ttitle: z.string().optional(),\n});\nexport const CitationSourceSchema = z.union([\n\tz.string().transform((url) => ({ url })),\n\tCitationObjectSchema,\n]);\nexport type CitationSource = z.infer<typeof CitationSourceSchema>;\n\nexport const SuggestedActionSchema = z.object({\n\tquestion: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type SuggestedAction = z.infer<typeof SuggestedActionSchema>;\n\nexport const ChatModeSchema = z.enum([\"standard\", \"advanced\"]);\nexport type ChatMode = z.infer<typeof ChatModeSchema>;\n\n/** The Pear client surface a chat request declares — drives per-surface behavior\n * server-side (analysis universe / execution policy). REQUIRED on the wire. The\n * Telegram surfaces (tg_dm / tg_group) are resolved server-side from the TG\n * session and are NOT client-declarable, so they're intentionally absent here. */\nexport const ChatSurfaceSchema = z.enum([\n\t\"pear_v3\",\n\t\"pear_pro\",\n\t\"base_mini\",\n\t\"web\",\n]);\nexport type ChatSurface = z.infer<typeof ChatSurfaceSchema>;\n","import { z } from \"zod\";\n\n/** Known ticket actions. Used for typing; the wire `action` field is parsed\n * permissively (plain string) elsewhere for forward-compat. */\nexport const TicketActionSchema = z.enum([\n\t\"open_position\",\n\t\"close_position\",\n\t\"close_all_positions\",\n\t\"adjust_position\",\n\t\"adjust_advance_position\",\n\t\"reverse_position\",\n\t\"rebalance_position\",\n\t\"set_risk_parameters\",\n]);\nexport type TicketAction = z.infer<typeof TicketActionSchema>;\n\nexport const TicketStatusSchema = z.enum([\n\t\"PENDING\",\n\t\"EXECUTING\",\n\t\"EXECUTED\",\n\t\"CANCELLED\",\n\t\"FAILED\",\n]);\nexport type TicketStatus = z.infer<typeof TicketStatusSchema>;\n\n/** Surfaced on a turn when a money-moving write was FROZEN (nothing executed).\n * `action` is a plain string (forward-compatible); compare against\n * `TicketActionSchema.options` if you need to switch on known actions. */\nexport const PendingActionSchema = z.object({\n\tticketId: z.string(),\n\taction: z.string(),\n\tconsequence: z.string(),\n\toptions: z.array(z.string()),\n});\nexport type PendingAction = z.infer<typeof PendingActionSchema>;\n\n/** Response of POST /trade/tickets/:id/confirm. Strict on the money fields,\n * loose (passthrough) on the action-specific `result` payload. `status` is\n * intentionally narrowed to the two TERMINAL confirm outcomes this endpoint\n * returns; widen to `TicketStatusSchema` if the BE can ever return another. */\nexport const ConfirmResultSchema = z.looseObject({\n\tok: z.boolean(),\n\tstatus: z.enum([\"EXECUTED\", \"FAILED\"]),\n\t// `.optional()` is load-bearing: in zod v4 `z.unknown()` is NO LONGER\n\t// implicitly optional, so dropping it would make these fields required.\n\tresult: z.unknown().optional(),\n\tpositionsSnapshot: z.unknown().optional(),\n\timages: z.array(z.string()).optional(),\n});\nexport type ConfirmResult = z.infer<typeof ConfirmResultSchema>;\n\nexport const CancelResultSchema = z.object({\n\tok: z.literal(true),\n\tstatus: z.literal(\"CANCELLED\"),\n});\nexport type CancelResult = z.infer<typeof CancelResultSchema>;\n\nexport const SetConfirmationsResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetConfirmationsResult = z.infer<\n\ttypeof SetConfirmationsResultSchema\n>;\n\n/** Response of GET /trade/tickets/settings — the caller's two independent trade\n * toggles. `executionEnabled` is the master execution switch (any write at all);\n * `confirmationsEnabled` is the confirm-before-write preference. */\nexport const TradeSettingsSchema = z.object({\n\texecutionEnabled: z.boolean(),\n\tconfirmationsEnabled: z.boolean(),\n});\nexport type TradeSettings = z.infer<typeof TradeSettingsSchema>;\n\n/** Response of POST /trade/tickets/execution — the new master-switch state. */\nexport const SetExecutionResultSchema = z.object({\n\tok: z.boolean(),\n\tenabled: z.boolean(),\n});\nexport type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\nimport { PendingActionSchema } from \"./tickets\";\n\nexport const TokenEventSchema = z.object({\n\ttype: z.literal(\"token\"),\n\ttext: z.string(),\n});\n// `thinking` is emitted by ADVANCED mode only (the standard pipeline doesn't).\nexport const ThinkingEventSchema = z.object({\n\ttype: z.literal(\"thinking\"),\n\ttext: z.string(),\n});\nexport const StatusEventSchema = z.object({\n\ttype: z.literal(\"status\"),\n\ttext: z.string(),\n\tphase: z.enum([\"start\", \"end\"]).optional(),\n\tnode: z.string().optional(),\n});\nexport const SourcesEventSchema = z.object({\n\ttype: z.literal(\"sources\"),\n\t// `.catch` on every NON-critical field so a malformed metadata array can\n\t// never sink the whole event — `pendingAction` (a staged money-moving trade)\n\t// rides on this same frame and MUST always survive.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).catch([]).optional(), // resolved URL strings\n\tsuggestedAction: SuggestedActionSchema.nullish().catch(null),\n\t// pendingAction is deliberately NOT `.catch`-ed: a corrupt ticket must reject,\n\t// never be fabricated.\n\tpendingAction: PendingActionSchema.nullish(),\n});\nexport const ErrorEventSchema = z.object({\n\ttype: z.literal(\"error\"),\n\tmessage: z.string().optional(),\n});\n\n/** The discriminated union of events the SSE wire delivers. Parse each event\n * with `.safeParse`; on failure (unknown/legacy `cycle` etc.) IGNORE it — do\n * not throw. */\nexport const AgentWireEventSchema = z.discriminatedUnion(\"type\", [\n\tTokenEventSchema,\n\tThinkingEventSchema,\n\tStatusEventSchema,\n\tSourcesEventSchema,\n\tErrorEventSchema,\n]);\nexport type AgentWireEvent = z.infer<typeof AgentWireEventSchema>;\n\n/** Final assembled turn — the shape of `POST /chat` AND the SDK's synthetic\n * `done` event (the SSE wire has no `done` frame; the SDK assembles it). */\nexport const ChatResultSchema = z.object({\n\tfinalText: z.string(),\n\tsessionId: z.string().optional(),\n\t// Same money-path guard as SourcesEventSchema: metadata degrades to [] / null\n\t// on drift so a hard `.parse` can never throw away a real `pendingAction`.\n\tresearchAnnotations: z.array(CitationSourceSchema).catch([]).optional(),\n\ttwitterSources: z.array(TwitterSourceSchema).catch([]).optional(),\n\ttradeLinks: z.array(TradeLinkSchema).catch([]).optional(),\n\timages: z.array(z.string()).default([]),\n\tsuggestedAction: SuggestedActionSchema.nullable().default(null).catch(null),\n\tpendingAction: PendingActionSchema.nullable().default(null),\n});\nexport type ChatResult = z.infer<typeof ChatResultSchema>;\n\n/** The RAW wire union plus a synthetic terminal `done`. NOTE: the SDK actually\n * emits a NORMALIZED `StreamEvent` (token/thinking carry a `delta`) defined in\n * the SDK's stream module; this `AgentEvent` is the pre-normalization shape. */\nexport type AgentEvent = AgentWireEvent | { type: \"done\"; result: ChatResult };\n","import { z } from \"zod\";\n\n/** Response of GET /auth/link-wallet/self — whether the caller's wallet has a\n * WalletLink (i.e. the agent holds an API key and can execute trades). */\nexport const LinkStatusSchema = z.object({\n\tlinked: z.boolean(),\n\twalletAddress: z.string(),\n});\nexport type LinkStatus = z.infer<typeof LinkStatusSchema>;\n\n/** Response of POST /auth/link-wallet/self. `created` is true only when this\n * call minted a new key (false on the idempotent already-linked path). */\nexport const SelfLinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(true),\n\tcreated: z.boolean(),\n});\nexport type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>;\n\n/** Response of DELETE /auth/link-wallet/self. */\nexport const SelfUnlinkResultSchema = z.object({\n\tok: z.boolean(),\n\tlinked: z.literal(false),\n});\nexport type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>;\n","import { z } from \"zod\";\nimport {\n\tCitationSourceSchema,\n\tSuggestedActionSchema,\n\tTradeLinkSchema,\n\tTwitterSourceSchema,\n} from \"./primitives\";\n\nexport const SessionListItemSchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(), // ISO (Date serialized over the wire)\n});\nexport type SessionListItem = z.infer<typeof SessionListItemSchema>;\n\nexport const SessionSummarySchema = z.object({\n\tid: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n\tfirstUserMessage: z.string().optional(),\n\tlastUserMessage: z.string().optional(),\n\tlastUserMessageAt: z.string().optional(),\n\tlastAssistantMessageAt: z.string().optional(),\n});\nexport type SessionSummary = z.infer<typeof SessionSummarySchema>;\n\nexport const SessionSchema = z.object({\n\tid: z.string(),\n\tuserId: z.string(),\n\tappType: z.string(),\n\tcreatedAt: z.string(),\n});\nexport type Session = z.infer<typeof SessionSchema>;\n\n/** A persisted chat message (history). `images` are pre-resolved URL strings.\n * `z.looseObject` keeps unknown future fields instead of stripping them. */\nexport const AgentChatMessageSchema = z.looseObject({\n\tid: z.string(),\n\trole: z.string(),\n\tcontent: z.string(),\n\tcreatedAt: z.string(),\n\tresearchAnnotations: z.array(CitationSourceSchema).nullish(),\n\ttwitterSources: z.array(TwitterSourceSchema).nullish(),\n\ttradeLinks: z.array(TradeLinkSchema).nullish(),\n\timages: z.array(z.string()).nullish(),\n\tsuggestedAction: SuggestedActionSchema.nullish(),\n});\nexport type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>;\n","import { type AgentWireEvent, AgentWireEventSchema } from \"./protocol\";\n\n/** A token/thinking event normalized to expose an incremental `delta`. This\n * backend is DELTA-only on every path, so `delta === text` — there is no\n * cumulative reconciliation (a `startsWith` heuristic corrupts real output). */\nexport type StreamEvent =\n\t| (Extract<AgentWireEvent, { type: \"token\" }> & { delta: string })\n\t| (Extract<AgentWireEvent, { type: \"thinking\" }> & { delta: string })\n\t| Exclude<AgentWireEvent, { type: \"token\" | \"thinking\" }>;\n\nexport async function* parseSseStream(\n\tbody: ReadableStream<Uint8Array>,\n): AsyncGenerator<StreamEvent> {\n\tconst reader = body.getReader();\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tbuffer += decoder.decode(value, { stream: true });\n\n\t\t\t// Drain every complete `\\n\\n`-delimited frame in the buffer. `const idx`\n\t\t\t// is recomputed each iteration (no assignment-in-`while`-head: that trips\n\t\t\t// biome `noAssignInExpressions`, a non-auto-fixable CI error).\n\t\t\twhile (true) {\n\t\t\t\tconst idx = buffer.indexOf(\"\\n\\n\");\n\t\t\t\tif (idx < 0) break;\n\t\t\t\tconst rawEvent = buffer.slice(0, idx);\n\t\t\t\tbuffer = buffer.slice(idx + 2);\n\n\t\t\t\tconst lines = rawEvent.split(\"\\n\");\n\t\t\t\tconst eventLine = lines.find((l) => l.startsWith(\"event:\"));\n\t\t\t\tconst dataLine = lines.find((l) => l.startsWith(\"data:\"));\n\t\t\t\tif (!dataLine) continue;\n\t\t\t\tconst payloadText = dataLine.replace(/^data:\\s?/, \"\");\n\n\t\t\t\t// NestJS surfaces stream errors as `event: error\\ndata: <plain string>`\n\t\t\t\t// (NON-JSON). Detect it BEFORE JSON.parse so it isn't swallowed.\n\t\t\t\tif (eventLine?.replace(/^event:\\s?/, \"\") === \"error\") {\n\t\t\t\t\tyield { type: \"error\", message: payloadText };\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet json: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tjson = JSON.parse(payloadText);\n\t\t\t\t} catch {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst parsed = AgentWireEventSchema.safeParse(json);\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\t// Never SILENTLY drop a money-path frame: if it looks like a sources\n\t\t\t\t\t// event carrying pendingAction, fail loud instead of losing a trade.\n\t\t\t\t\tif (\n\t\t\t\t\t\t(json as { type?: string })?.type === \"sources\" &&\n\t\t\t\t\t\t(json as { pendingAction?: unknown })?.pendingAction\n\t\t\t\t\t) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tmessage: \"malformed sources frame with pendingAction\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst ev = parsed.data;\n\t\t\t\tif (ev.type === \"token\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else if (ev.type === \"thinking\") {\n\t\t\t\t\tyield { ...ev, delta: ev.text };\n\t\t\t\t} else {\n\t\t\t\t\tyield ev;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} finally {\n\t\treader.cancel().catch(() => undefined);\n\t}\n}\n","import { AgentChatError, errorFromStatus } from \"./errors\";\nimport { type AgentChatClientConfig, createHttp, type Http } from \"./http\";\nimport {\n\ttype AgentChatMessage,\n\ttype CancelResult,\n\tCancelResultSchema,\n\ttype ChatMode,\n\ttype ChatResult,\n\tChatResultSchema,\n\ttype ChatSurface,\n\ttype ConfirmResult,\n\tConfirmResultSchema,\n\ttype LinkStatus,\n\tLinkStatusSchema,\n\tPendingActionSchema,\n\ttype SelfLinkResult,\n\tSelfLinkResultSchema,\n\ttype SelfUnlinkResult,\n\tSelfUnlinkResultSchema,\n\ttype Session,\n\ttype SessionListItem,\n\ttype SessionSummary,\n\ttype SetConfirmationsResult,\n\tSetConfirmationsResultSchema,\n\ttype SetExecutionResult,\n\tSetExecutionResultSchema,\n\ttype TradeSettings,\n\tTradeSettingsSchema,\n} from \"./protocol\";\nimport { parseSseStream, type StreamEvent } from \"./stream\";\n\n/** Parse a ChatResult but NEVER throw away a real `pendingAction` on metadata\n * drift: on a parse failure, fall back to a minimal result that preserves\n * `finalText` + `pendingAction` rather than rejecting the whole turn. */\nfunction parseChatResult(raw: unknown): ChatResult {\n\tconst parsed = ChatResultSchema.safeParse(raw);\n\tif (parsed.success) return parsed.data;\n\tconst r = raw as { finalText?: unknown; pendingAction?: unknown };\n\t// Salvage finalText, but NEVER fabricate a ticket: keep pendingAction only if\n\t// it INDEPENDENTLY validates — a corrupt ticket is dropped, never handed to\n\t// confirmTicket() (the money endpoint).\n\tconst pa = PendingActionSchema.safeParse(r?.pendingAction);\n\treturn {\n\t\tfinalText: typeof r?.finalText === \"string\" ? r.finalText : \"\",\n\t\timages: [],\n\t\tsuggestedAction: null,\n\t\tpendingAction: pa.success ? pa.data : null,\n\t};\n}\n\nfunction assembleResult(\n\tsessionId: string,\n\tfinalText: string,\n\tsources: Extract<StreamEvent, { type: \"sources\" }> | undefined,\n): ChatResult {\n\treturn parseChatResult({\n\t\tfinalText,\n\t\tsessionId,\n\t\tresearchAnnotations: sources?.researchAnnotations,\n\t\ttwitterSources: sources?.twitterSources,\n\t\ttradeLinks: sources?.tradeLinks,\n\t\timages: sources?.images ?? [],\n\t\tsuggestedAction: sources?.suggestedAction ?? null,\n\t\tpendingAction: sources?.pendingAction ?? null,\n\t});\n}\n\nexport class AgentChatClient {\n\tprivate readonly http: Http;\n\n\tconstructor(config: AgentChatClientConfig) {\n\t\tthis.http = createHttp(config);\n\t}\n\n\tlistSessions(): Promise<SessionListItem[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions\");\n\t}\n\n\tlistSessionSummaries(): Promise<SessionSummary[]> {\n\t\treturn this.http.json(\"GET\", \"/chat/sessions/summary\");\n\t}\n\n\tcreateSession(): Promise<{ id: string }> {\n\t\treturn this.http.json(\"POST\", \"/chat/sessions\");\n\t}\n\n\tgetSession(sessionId: string): Promise<Session> {\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tasync deleteSession(sessionId: string): Promise<void> {\n\t\tawait this.http.json(\n\t\t\t\"DELETE\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}`,\n\t\t);\n\t}\n\n\tgetMessages(\n\t\tsessionId: string,\n\t\topts?: { limit?: number; before?: string },\n\t): Promise<AgentChatMessage[]> {\n\t\tconst params = new URLSearchParams();\n\t\tif (opts?.limit !== undefined) params.set(\"limit\", String(opts.limit));\n\t\tif (opts?.before) params.set(\"before\", opts.before);\n\t\tconst qs = params.toString();\n\t\treturn this.http.json(\n\t\t\t\"GET\",\n\t\t\t`/chat/sessions/${encodeURIComponent(sessionId)}/messages${qs ? `?${qs}` : \"\"}`,\n\t\t);\n\t}\n\n\t/** Stream a turn. Yields token/thinking/status/sources events, then a\n\t * synthetic `{type:'done', result}` assembled from accumulated token deltas +\n\t * the final `sources` payload (the SSE wire has no `done` frame). Throws an\n\t * `AgentChatError` if the backend emits a mid-stream `error` frame. */\n\tasync *streamChat(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Declares the client surface (pear_v3 / pear_pro / base_mini / …). Required —\n\t\t * the API rejects requests without a valid surface. Drives per-surface behavior. */\n\t\tsurface: ChatSurface;\n\t\tsignal?: AbortSignal;\n\t\t/** CTA callback — set when the user clicks a suggested-action option; the\n\t\t * agent rebuilds the turn from this context server-side. */\n\t\tcta?: { previousText: string; question: string; selectedOption: string };\n\t}): AsyncGenerator<StreamEvent | { type: \"done\"; result: ChatResult }> {\n\t\tconst params = new URLSearchParams({\n\t\t\tmessage: args.message,\n\t\t\tsessionId: args.sessionId,\n\t\t\tmode: args.mode ?? \"standard\",\n\t\t});\n\t\tparams.set(\"surface\", args.surface);\n\t\tif (args.cta) {\n\t\t\tparams.set(\"suggestedActionPreviousText\", args.cta.previousText);\n\t\t\tparams.set(\"suggestedActionQuestion\", args.cta.question);\n\t\t\tparams.set(\"suggestedActionSelectedOption\", args.cta.selectedOption);\n\t\t}\n\t\tconst headers = await this.http.authHeaders();\n\t\theaders.Accept = \"text/event-stream\";\n\t\tconst res = await this.http.fetch(\n\t\t\tthis.http.buildUrl(`/chat/stream?${params.toString()}`),\n\t\t\t{ method: \"GET\", headers, signal: args.signal },\n\t\t);\n\t\tif (!res.ok || !res.body) {\n\t\t\tthrow errorFromStatus(res.status, await res.text().catch(() => \"\"));\n\t\t}\n\n\t\tlet finalText = \"\";\n\t\tlet sources: Extract<StreamEvent, { type: \"sources\" }> | undefined;\n\t\tfor await (const ev of parseSseStream(res.body)) {\n\t\t\tif (ev.type === \"error\") {\n\t\t\t\tthrow new AgentChatError(ev.message ?? \"Agent stream error\");\n\t\t\t}\n\t\t\tif (ev.type === \"token\") finalText += ev.delta;\n\t\t\tif (ev.type === \"sources\") sources = ev;\n\t\t\tyield ev;\n\t\t}\n\n\t\tyield {\n\t\t\ttype: \"done\",\n\t\t\tresult: assembleResult(args.sessionId, finalText, sources),\n\t\t};\n\t}\n\n\t/** Sync send (POST /chat). Prefer `streamChat` for UX. */\n\tsendMessage(args: {\n\t\tsessionId: string;\n\t\tmessage: string;\n\t\tmode?: ChatMode;\n\t\t/** Required — the API rejects requests without a valid surface. */\n\t\tsurface: ChatSurface;\n\t}): Promise<ChatResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/chat\", {\n\t\t\t\tmessage: args.message,\n\t\t\t\tsessionId: args.sessionId,\n\t\t\t\tmode: args.mode ?? \"standard\",\n\t\t\t\tsurface: args.surface,\n\t\t\t})\n\t\t\t.then(parseChatResult);\n\t}\n\n\tconfirmTicket(ticketId: string): Promise<ConfirmResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/confirm`,\n\t\t\t)\n\t\t\t.then((raw) => ConfirmResultSchema.parse(raw));\n\t}\n\n\tcancelTicket(ticketId: string): Promise<CancelResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\n\t\t\t\t\"POST\",\n\t\t\t\t`/trade/tickets/${encodeURIComponent(ticketId)}/cancel`,\n\t\t\t)\n\t\t\t.then((raw) => CancelResultSchema.parse(raw));\n\t}\n\n\tsetTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/settings\", { enabled })\n\t\t\t.then((raw) => SetConfirmationsResultSchema.parse(raw));\n\t}\n\n\t/** Read both trade toggles for the caller wallet: the master execution switch\n\t * and the confirm-before-write preference. */\n\tgetTradeSettings(): Promise<TradeSettings> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/trade/tickets/settings\")\n\t\t\t.then((raw) => TradeSettingsSchema.parse(raw));\n\t}\n\n\t/** Flip the caller's master execution switch. `false` opts the wallet out of\n\t * all money-moving writes; `true` restores the default-ON state. */\n\tsetTradeExecution(enabled: boolean): Promise<SetExecutionResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/trade/tickets/execution\", { enabled })\n\t\t\t.then((raw) => SetExecutionResultSchema.parse(raw));\n\t}\n\n\t/** Whether the caller's wallet is linked to the agent (i.e. the agent can\n\t * execute trades for it). Backend-verified — don't cache this locally. */\n\tgetLinkStatus(): Promise<LinkStatus> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"GET\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => LinkStatusSchema.parse(raw));\n\t}\n\n\t/** Link the caller's wallet: the agent mints a Pear API key server-side AS\n\t * the caller (their token is forwarded) — the key never exists client-side.\n\t * Idempotent when already linked; `force` re-mints (recovery), `code` binds\n\t * a Telegram identity (replaces the legacy secret-based flow). */\n\tlinkWallet(opts?: {\n\t\tforce?: boolean;\n\t\tcode?: string;\n\t}): Promise<SelfLinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"POST\", \"/auth/link-wallet/self\", opts ?? {})\n\t\t\t.then((raw) => SelfLinkResultSchema.parse(raw));\n\t}\n\n\t/** Unlink the caller's wallet — the agent loses trade authority. */\n\tunlinkWallet(): Promise<SelfUnlinkResult> {\n\t\treturn this.http\n\t\t\t.json<unknown>(\"DELETE\", \"/auth/link-wallet/self\")\n\t\t\t.then((raw) => SelfUnlinkResultSchema.parse(raw));\n\t}\n}\n"]} |
| import * as react from 'react'; | ||
| import { X as TradeLink, $ as TwitterSource, n as CitationSource, N as SuggestedAction, A as AgentChatClient } from '../client-CJNmyV0P.cjs'; | ||
| import { X as TradeLink, $ as TwitterSource, n as CitationSource, N as SuggestedAction, A as AgentChatClient } from '../client-BSUkCr7k.cjs'; | ||
| import 'zod'; | ||
@@ -29,4 +29,4 @@ | ||
| setMode: react.Dispatch<react.SetStateAction<"standard" | "advanced">>; | ||
| surface: "pear_v3" | "pear_pro" | "base_mini" | "tg_dm" | "tg_group" | "web"; | ||
| setSurface: react.Dispatch<react.SetStateAction<"pear_v3" | "pear_pro" | "base_mini" | "tg_dm" | "tg_group" | "web">>; | ||
| surface: "pear_v3" | "pear_pro" | "base_mini" | "web"; | ||
| setSurface: react.Dispatch<react.SetStateAction<"pear_v3" | "pear_pro" | "base_mini" | "web">>; | ||
| pendingAction: { | ||
@@ -33,0 +33,0 @@ ticketId: string; |
| import * as react from 'react'; | ||
| import { X as TradeLink, $ as TwitterSource, n as CitationSource, N as SuggestedAction, A as AgentChatClient } from '../client-CJNmyV0P.js'; | ||
| import { X as TradeLink, $ as TwitterSource, n as CitationSource, N as SuggestedAction, A as AgentChatClient } from '../client-BSUkCr7k.js'; | ||
| import 'zod'; | ||
@@ -29,4 +29,4 @@ | ||
| setMode: react.Dispatch<react.SetStateAction<"standard" | "advanced">>; | ||
| surface: "pear_v3" | "pear_pro" | "base_mini" | "tg_dm" | "tg_group" | "web"; | ||
| setSurface: react.Dispatch<react.SetStateAction<"pear_v3" | "pear_pro" | "base_mini" | "tg_dm" | "tg_group" | "web">>; | ||
| surface: "pear_v3" | "pear_pro" | "base_mini" | "web"; | ||
| setSurface: react.Dispatch<react.SetStateAction<"pear_v3" | "pear_pro" | "base_mini" | "web">>; | ||
| pendingAction: { | ||
@@ -33,0 +33,0 @@ ticketId: string; |
+1
-1
| { | ||
| "name": "@pear-protocol/agent-sdk", | ||
| "version": "0.4.0", | ||
| "version": "0.4.1", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+6
-5
@@ -63,7 +63,8 @@ # @pear-protocol/agent-sdk | ||
| Both `streamChat` and `sendMessage` require a `surface` | ||
| (`pear_v3` | `pear_pro` | `base_mini` | `tg_dm` | `tg_group` | `web`) declaring | ||
| which Pear client you are — the API rejects requests without a valid one. The | ||
| agent applies per-surface universe and execution policy — e.g. `base_mini` | ||
| surfaces only SYMM assets and is analysis-only. (`useAgentChat` defaults to | ||
| `pear_v3`; set it via the returned `setSurface`.) | ||
| (`pear_v3` | `pear_pro` | `base_mini` | `web`) declaring which Pear client you | ||
| are — the API rejects requests without a valid one. The agent applies | ||
| per-surface universe and execution policy — e.g. `base_mini` surfaces only SYMM | ||
| assets and is analysis-only. (`useAgentChat` defaults to `pear_v3`; set it via | ||
| the returned `setSurface`.) The Telegram surfaces are resolved server-side and | ||
| are not client-declarable. | ||
@@ -70,0 +71,0 @@ ## React |
| import { z } from 'zod'; | ||
| interface AgentChatClientConfig { | ||
| baseUrl: string; | ||
| getToken: () => string | Promise<string>; | ||
| tokenVersion?: "v2" | "v3"; | ||
| fetch?: typeof fetch; | ||
| } | ||
| declare const TokenEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const ThinkingEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const StatusEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const SourcesEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| declare const ErrorEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const AgentWireEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>], "type">; | ||
| type AgentWireEvent = z.infer<typeof AgentWireEventSchema>; | ||
| declare const ChatResultSchema: z.ZodObject<{ | ||
| finalText: z.ZodString; | ||
| sessionId: z.ZodOptional<z.ZodString>; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodDefault<z.ZodArray<z.ZodString>>; | ||
| suggestedAction: z.ZodCatch<z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| type ChatResult = z.infer<typeof ChatResultSchema>; | ||
| type AgentEvent = AgentWireEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }; | ||
| declare const LinkStatusSchema: z.ZodObject<{ | ||
| linked: z.ZodBoolean; | ||
| walletAddress: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type LinkStatus = z.infer<typeof LinkStatusSchema>; | ||
| declare const SelfLinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<true>; | ||
| created: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>; | ||
| declare const SelfUnlinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<false>; | ||
| }, z.core.$strip>; | ||
| type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>; | ||
| declare const SessionListItemSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type SessionListItem = z.infer<typeof SessionListItemSchema>; | ||
| declare const SessionSummarySchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| firstUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessageAt: z.ZodOptional<z.ZodString>; | ||
| lastAssistantMessageAt: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SessionSummary = z.infer<typeof SessionSummarySchema>; | ||
| declare const SessionSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| userId: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type Session = z.infer<typeof SessionSchema>; | ||
| declare const AgentChatMessageSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| role: z.ZodString; | ||
| content: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| researchAnnotations: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$loose>; | ||
| type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>; | ||
| declare const TradeLinkSchema: z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TradeLink = z.infer<typeof TradeLinkSchema>; | ||
| declare const TwitterSourceSchema: z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TwitterSource = z.infer<typeof TwitterSourceSchema>; | ||
| declare const CitationSourceSchema: z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>; | ||
| type CitationSource = z.infer<typeof CitationSourceSchema>; | ||
| declare const SuggestedActionSchema: z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SuggestedAction = z.infer<typeof SuggestedActionSchema>; | ||
| declare const ChatModeSchema: z.ZodEnum<{ | ||
| standard: "standard"; | ||
| advanced: "advanced"; | ||
| }>; | ||
| type ChatMode = z.infer<typeof ChatModeSchema>; | ||
| declare const ChatSurfaceSchema: z.ZodEnum<{ | ||
| pear_v3: "pear_v3"; | ||
| pear_pro: "pear_pro"; | ||
| base_mini: "base_mini"; | ||
| tg_dm: "tg_dm"; | ||
| tg_group: "tg_group"; | ||
| web: "web"; | ||
| }>; | ||
| type ChatSurface = z.infer<typeof ChatSurfaceSchema>; | ||
| declare const TicketActionSchema: z.ZodEnum<{ | ||
| open_position: "open_position"; | ||
| close_position: "close_position"; | ||
| close_all_positions: "close_all_positions"; | ||
| adjust_position: "adjust_position"; | ||
| adjust_advance_position: "adjust_advance_position"; | ||
| reverse_position: "reverse_position"; | ||
| rebalance_position: "rebalance_position"; | ||
| set_risk_parameters: "set_risk_parameters"; | ||
| }>; | ||
| type TicketAction = z.infer<typeof TicketActionSchema>; | ||
| declare const TicketStatusSchema: z.ZodEnum<{ | ||
| PENDING: "PENDING"; | ||
| EXECUTING: "EXECUTING"; | ||
| EXECUTED: "EXECUTED"; | ||
| CANCELLED: "CANCELLED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| type TicketStatus = z.infer<typeof TicketStatusSchema>; | ||
| declare const PendingActionSchema: z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type PendingAction = z.infer<typeof PendingActionSchema>; | ||
| declare const ConfirmResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| status: z.ZodEnum<{ | ||
| EXECUTED: "EXECUTED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| result: z.ZodOptional<z.ZodUnknown>; | ||
| positionsSnapshot: z.ZodOptional<z.ZodUnknown>; | ||
| images: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$loose>; | ||
| type ConfirmResult = z.infer<typeof ConfirmResultSchema>; | ||
| declare const CancelResultSchema: z.ZodObject<{ | ||
| ok: z.ZodLiteral<true>; | ||
| status: z.ZodLiteral<"CANCELLED">; | ||
| }, z.core.$strip>; | ||
| type CancelResult = z.infer<typeof CancelResultSchema>; | ||
| declare const SetConfirmationsResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetConfirmationsResult = z.infer<typeof SetConfirmationsResultSchema>; | ||
| declare const TradeSettingsSchema: z.ZodObject<{ | ||
| executionEnabled: z.ZodBoolean; | ||
| confirmationsEnabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type TradeSettings = z.infer<typeof TradeSettingsSchema>; | ||
| declare const SetExecutionResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>; | ||
| type StreamEvent = (Extract<AgentWireEvent, { | ||
| type: "token"; | ||
| }> & { | ||
| delta: string; | ||
| }) | (Extract<AgentWireEvent, { | ||
| type: "thinking"; | ||
| }> & { | ||
| delta: string; | ||
| }) | Exclude<AgentWireEvent, { | ||
| type: "token" | "thinking"; | ||
| }>; | ||
| declare class AgentChatClient { | ||
| private readonly http; | ||
| constructor(config: AgentChatClientConfig); | ||
| listSessions(): Promise<SessionListItem[]>; | ||
| listSessionSummaries(): Promise<SessionSummary[]>; | ||
| createSession(): Promise<{ | ||
| id: string; | ||
| }>; | ||
| getSession(sessionId: string): Promise<Session>; | ||
| deleteSession(sessionId: string): Promise<void>; | ||
| getMessages(sessionId: string, opts?: { | ||
| limit?: number; | ||
| before?: string; | ||
| }): Promise<AgentChatMessage[]>; | ||
| streamChat(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| signal?: AbortSignal; | ||
| cta?: { | ||
| previousText: string; | ||
| question: string; | ||
| selectedOption: string; | ||
| }; | ||
| }): AsyncGenerator<StreamEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }>; | ||
| sendMessage(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| }): Promise<ChatResult>; | ||
| confirmTicket(ticketId: string): Promise<ConfirmResult>; | ||
| cancelTicket(ticketId: string): Promise<CancelResult>; | ||
| setTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult>; | ||
| getTradeSettings(): Promise<TradeSettings>; | ||
| setTradeExecution(enabled: boolean): Promise<SetExecutionResult>; | ||
| getLinkStatus(): Promise<LinkStatus>; | ||
| linkWallet(opts?: { | ||
| force?: boolean; | ||
| code?: string; | ||
| }): Promise<SelfLinkResult>; | ||
| unlinkWallet(): Promise<SelfUnlinkResult>; | ||
| } | ||
| export { type TwitterSource as $, AgentChatClient as A, type SessionSummary as B, type CancelResult as C, SessionSummarySchema as D, ErrorEventSchema as E, type SetConfirmationsResult as F, SetConfirmationsResultSchema as G, type SetExecutionResult as H, SetExecutionResultSchema as I, SourcesEventSchema as J, StatusEventSchema as K, type LinkStatus as L, type StreamEvent as M, type SuggestedAction as N, SuggestedActionSchema as O, type PendingAction as P, type TicketAction as Q, TicketActionSchema as R, type SelfLinkResult as S, ThinkingEventSchema as T, type TicketStatus as U, TicketStatusSchema as V, TokenEventSchema as W, type TradeLink as X, TradeLinkSchema as Y, type TradeSettings as Z, TradeSettingsSchema as _, type AgentChatClientConfig as a, TwitterSourceSchema as a0, type AgentChatMessage as b, AgentChatMessageSchema as c, type AgentEvent as d, type AgentWireEvent as e, AgentWireEventSchema as f, CancelResultSchema as g, type ChatMode as h, ChatModeSchema as i, type ChatResult as j, ChatResultSchema as k, type ChatSurface as l, ChatSurfaceSchema as m, type CitationSource as n, CitationSourceSchema as o, type ConfirmResult as p, ConfirmResultSchema as q, LinkStatusSchema as r, PendingActionSchema as s, SelfLinkResultSchema as t, type SelfUnlinkResult as u, SelfUnlinkResultSchema as v, type Session as w, type SessionListItem as x, SessionListItemSchema as y, SessionSchema as z }; |
| import { z } from 'zod'; | ||
| interface AgentChatClientConfig { | ||
| baseUrl: string; | ||
| getToken: () => string | Promise<string>; | ||
| tokenVersion?: "v2" | "v3"; | ||
| fetch?: typeof fetch; | ||
| } | ||
| declare const TokenEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const ThinkingEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>; | ||
| declare const StatusEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const SourcesEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| declare const ErrorEventSchema: z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const AgentWireEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ | ||
| type: z.ZodLiteral<"token">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"thinking">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"status">; | ||
| text: z.ZodString; | ||
| phase: z.ZodOptional<z.ZodEnum<{ | ||
| start: "start"; | ||
| end: "end"; | ||
| }>>; | ||
| node: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"sources">; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodCatch<z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"error">; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>], "type">; | ||
| type AgentWireEvent = z.infer<typeof AgentWireEventSchema>; | ||
| declare const ChatResultSchema: z.ZodObject<{ | ||
| finalText: z.ZodString; | ||
| sessionId: z.ZodOptional<z.ZodString>; | ||
| researchAnnotations: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodCatch<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodDefault<z.ZodArray<z.ZodString>>; | ||
| suggestedAction: z.ZodCatch<z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>>; | ||
| pendingAction: z.ZodDefault<z.ZodNullable<z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$strip>; | ||
| type ChatResult = z.infer<typeof ChatResultSchema>; | ||
| type AgentEvent = AgentWireEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }; | ||
| declare const LinkStatusSchema: z.ZodObject<{ | ||
| linked: z.ZodBoolean; | ||
| walletAddress: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type LinkStatus = z.infer<typeof LinkStatusSchema>; | ||
| declare const SelfLinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<true>; | ||
| created: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SelfLinkResult = z.infer<typeof SelfLinkResultSchema>; | ||
| declare const SelfUnlinkResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| linked: z.ZodLiteral<false>; | ||
| }, z.core.$strip>; | ||
| type SelfUnlinkResult = z.infer<typeof SelfUnlinkResultSchema>; | ||
| declare const SessionListItemSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type SessionListItem = z.infer<typeof SessionListItemSchema>; | ||
| declare const SessionSummarySchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| firstUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessage: z.ZodOptional<z.ZodString>; | ||
| lastUserMessageAt: z.ZodOptional<z.ZodString>; | ||
| lastAssistantMessageAt: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SessionSummary = z.infer<typeof SessionSummarySchema>; | ||
| declare const SessionSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| userId: z.ZodString; | ||
| appType: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type Session = z.infer<typeof SessionSchema>; | ||
| declare const AgentChatMessageSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| role: z.ZodString; | ||
| content: z.ZodString; | ||
| createdAt: z.ZodString; | ||
| researchAnnotations: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>>>>; | ||
| twitterSources: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| tradeLinks: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>>>>; | ||
| images: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>; | ||
| suggestedAction: z.ZodOptional<z.ZodNullable<z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>>>; | ||
| }, z.core.$loose>; | ||
| type AgentChatMessage = z.infer<typeof AgentChatMessageSchema>; | ||
| declare const TradeLinkSchema: z.ZodObject<{ | ||
| link: z.ZodString; | ||
| platform: z.ZodString; | ||
| label: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TradeLink = z.infer<typeof TradeLinkSchema>; | ||
| declare const TwitterSourceSchema: z.ZodObject<{ | ||
| author: z.ZodString; | ||
| tweetUrl: z.ZodString; | ||
| publishedAt: z.ZodString; | ||
| }, z.core.$strip>; | ||
| type TwitterSource = z.infer<typeof TwitterSourceSchema>; | ||
| declare const CitationSourceSchema: z.ZodUnion<readonly [z.ZodPipe<z.ZodString, z.ZodTransform<{ | ||
| url: string; | ||
| }, string>>, z.ZodObject<{ | ||
| url: z.ZodString; | ||
| start_index: z.ZodOptional<z.ZodNumber>; | ||
| end_index: z.ZodOptional<z.ZodNumber>; | ||
| title: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>]>; | ||
| type CitationSource = z.infer<typeof CitationSourceSchema>; | ||
| declare const SuggestedActionSchema: z.ZodObject<{ | ||
| question: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type SuggestedAction = z.infer<typeof SuggestedActionSchema>; | ||
| declare const ChatModeSchema: z.ZodEnum<{ | ||
| standard: "standard"; | ||
| advanced: "advanced"; | ||
| }>; | ||
| type ChatMode = z.infer<typeof ChatModeSchema>; | ||
| declare const ChatSurfaceSchema: z.ZodEnum<{ | ||
| pear_v3: "pear_v3"; | ||
| pear_pro: "pear_pro"; | ||
| base_mini: "base_mini"; | ||
| tg_dm: "tg_dm"; | ||
| tg_group: "tg_group"; | ||
| web: "web"; | ||
| }>; | ||
| type ChatSurface = z.infer<typeof ChatSurfaceSchema>; | ||
| declare const TicketActionSchema: z.ZodEnum<{ | ||
| open_position: "open_position"; | ||
| close_position: "close_position"; | ||
| close_all_positions: "close_all_positions"; | ||
| adjust_position: "adjust_position"; | ||
| adjust_advance_position: "adjust_advance_position"; | ||
| reverse_position: "reverse_position"; | ||
| rebalance_position: "rebalance_position"; | ||
| set_risk_parameters: "set_risk_parameters"; | ||
| }>; | ||
| type TicketAction = z.infer<typeof TicketActionSchema>; | ||
| declare const TicketStatusSchema: z.ZodEnum<{ | ||
| PENDING: "PENDING"; | ||
| EXECUTING: "EXECUTING"; | ||
| EXECUTED: "EXECUTED"; | ||
| CANCELLED: "CANCELLED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| type TicketStatus = z.infer<typeof TicketStatusSchema>; | ||
| declare const PendingActionSchema: z.ZodObject<{ | ||
| ticketId: z.ZodString; | ||
| action: z.ZodString; | ||
| consequence: z.ZodString; | ||
| options: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| type PendingAction = z.infer<typeof PendingActionSchema>; | ||
| declare const ConfirmResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| status: z.ZodEnum<{ | ||
| EXECUTED: "EXECUTED"; | ||
| FAILED: "FAILED"; | ||
| }>; | ||
| result: z.ZodOptional<z.ZodUnknown>; | ||
| positionsSnapshot: z.ZodOptional<z.ZodUnknown>; | ||
| images: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$loose>; | ||
| type ConfirmResult = z.infer<typeof ConfirmResultSchema>; | ||
| declare const CancelResultSchema: z.ZodObject<{ | ||
| ok: z.ZodLiteral<true>; | ||
| status: z.ZodLiteral<"CANCELLED">; | ||
| }, z.core.$strip>; | ||
| type CancelResult = z.infer<typeof CancelResultSchema>; | ||
| declare const SetConfirmationsResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetConfirmationsResult = z.infer<typeof SetConfirmationsResultSchema>; | ||
| declare const TradeSettingsSchema: z.ZodObject<{ | ||
| executionEnabled: z.ZodBoolean; | ||
| confirmationsEnabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type TradeSettings = z.infer<typeof TradeSettingsSchema>; | ||
| declare const SetExecutionResultSchema: z.ZodObject<{ | ||
| ok: z.ZodBoolean; | ||
| enabled: z.ZodBoolean; | ||
| }, z.core.$strip>; | ||
| type SetExecutionResult = z.infer<typeof SetExecutionResultSchema>; | ||
| type StreamEvent = (Extract<AgentWireEvent, { | ||
| type: "token"; | ||
| }> & { | ||
| delta: string; | ||
| }) | (Extract<AgentWireEvent, { | ||
| type: "thinking"; | ||
| }> & { | ||
| delta: string; | ||
| }) | Exclude<AgentWireEvent, { | ||
| type: "token" | "thinking"; | ||
| }>; | ||
| declare class AgentChatClient { | ||
| private readonly http; | ||
| constructor(config: AgentChatClientConfig); | ||
| listSessions(): Promise<SessionListItem[]>; | ||
| listSessionSummaries(): Promise<SessionSummary[]>; | ||
| createSession(): Promise<{ | ||
| id: string; | ||
| }>; | ||
| getSession(sessionId: string): Promise<Session>; | ||
| deleteSession(sessionId: string): Promise<void>; | ||
| getMessages(sessionId: string, opts?: { | ||
| limit?: number; | ||
| before?: string; | ||
| }): Promise<AgentChatMessage[]>; | ||
| streamChat(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| signal?: AbortSignal; | ||
| cta?: { | ||
| previousText: string; | ||
| question: string; | ||
| selectedOption: string; | ||
| }; | ||
| }): AsyncGenerator<StreamEvent | { | ||
| type: "done"; | ||
| result: ChatResult; | ||
| }>; | ||
| sendMessage(args: { | ||
| sessionId: string; | ||
| message: string; | ||
| mode?: ChatMode; | ||
| surface: ChatSurface; | ||
| }): Promise<ChatResult>; | ||
| confirmTicket(ticketId: string): Promise<ConfirmResult>; | ||
| cancelTicket(ticketId: string): Promise<CancelResult>; | ||
| setTradeConfirmations(enabled: boolean): Promise<SetConfirmationsResult>; | ||
| getTradeSettings(): Promise<TradeSettings>; | ||
| setTradeExecution(enabled: boolean): Promise<SetExecutionResult>; | ||
| getLinkStatus(): Promise<LinkStatus>; | ||
| linkWallet(opts?: { | ||
| force?: boolean; | ||
| code?: string; | ||
| }): Promise<SelfLinkResult>; | ||
| unlinkWallet(): Promise<SelfUnlinkResult>; | ||
| } | ||
| export { type TwitterSource as $, AgentChatClient as A, type SessionSummary as B, type CancelResult as C, SessionSummarySchema as D, ErrorEventSchema as E, type SetConfirmationsResult as F, SetConfirmationsResultSchema as G, type SetExecutionResult as H, SetExecutionResultSchema as I, SourcesEventSchema as J, StatusEventSchema as K, type LinkStatus as L, type StreamEvent as M, type SuggestedAction as N, SuggestedActionSchema as O, type PendingAction as P, type TicketAction as Q, TicketActionSchema as R, type SelfLinkResult as S, ThinkingEventSchema as T, type TicketStatus as U, TicketStatusSchema as V, TokenEventSchema as W, type TradeLink as X, TradeLinkSchema as Y, type TradeSettings as Z, TradeSettingsSchema as _, type AgentChatClientConfig as a, TwitterSourceSchema as a0, type AgentChatMessage as b, AgentChatMessageSchema as c, type AgentEvent as d, type AgentWireEvent as e, AgentWireEventSchema as f, CancelResultSchema as g, type ChatMode as h, ChatModeSchema as i, type ChatResult as j, ChatResultSchema as k, type ChatSurface as l, ChatSurfaceSchema as m, type CitationSource as n, CitationSourceSchema as o, type ConfirmResult as p, ConfirmResultSchema as q, LinkStatusSchema as r, PendingActionSchema as s, SelfLinkResultSchema as t, type SelfUnlinkResult as u, SelfUnlinkResultSchema as v, type Session as w, type SessionListItem as x, SessionListItemSchema as y, SessionSchema as z }; |
126
0.8%240375
-0.05%2127
-0.28%