@convosite/client 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,224 @@
1
+ type JsonPrimitive = string | number | boolean | null;
2
+ type JsonValue = JsonPrimitive | JsonValue[] | {
3
+ [key: string]: JsonValue;
4
+ };
5
+ interface SiteMetaValue<T = unknown> {
6
+ type: string;
7
+ key: string;
8
+ value: T;
9
+ }
10
+ interface Site {
11
+ name: string;
12
+ global: Record<string, SiteMetaValue>;
13
+ }
14
+ interface Media {
15
+ id: string;
16
+ url: string;
17
+ alt?: string | null;
18
+ caption?: string | null;
19
+ width?: number | null;
20
+ height?: number | null;
21
+ mime?: string | null;
22
+ bytes?: number | null;
23
+ metadata?: Record<string, unknown> | null;
24
+ [key: string]: unknown;
25
+ }
26
+ interface PageBlock<TData extends Record<string, unknown> = Record<string, unknown>> {
27
+ key: string;
28
+ name: string;
29
+ data: TData;
30
+ }
31
+ interface PageMetaValue<T = unknown> {
32
+ type: string;
33
+ key: string;
34
+ value: T;
35
+ }
36
+ interface Page {
37
+ id: string;
38
+ name: string;
39
+ slug: string;
40
+ active: boolean;
41
+ is_home: boolean;
42
+ path: string;
43
+ seo: {
44
+ title: string | null;
45
+ description: string | null;
46
+ };
47
+ blocks: PageBlock[];
48
+ meta: Record<string, PageMetaValue>;
49
+ score?: number;
50
+ [key: string]: unknown;
51
+ }
52
+ interface PageResponse {
53
+ site: Site;
54
+ page: Page;
55
+ }
56
+ interface Pagination {
57
+ current_page: number;
58
+ per_page: number;
59
+ total: number;
60
+ last_page: number;
61
+ from: number | null;
62
+ to: number | null;
63
+ }
64
+ type PageSort = 'name' | 'slug' | 'title' | 'created_at' | 'updated_at';
65
+ type SortDirection = 'asc' | 'desc';
66
+ interface PageListOptions extends RequestOptions {
67
+ parentId?: string | null;
68
+ sort?: PageSort;
69
+ direction?: SortDirection;
70
+ page?: number;
71
+ perPage?: number;
72
+ }
73
+ interface PageListResponse {
74
+ site: Site;
75
+ pages: Page[];
76
+ pagination: Pagination;
77
+ }
78
+ interface MenuItem {
79
+ id: string;
80
+ parent_id: string | null;
81
+ name: string;
82
+ description: string | null;
83
+ classes: string | null;
84
+ type: string;
85
+ position: number;
86
+ href: string | null;
87
+ }
88
+ interface StructuredMenuItem extends MenuItem {
89
+ children: StructuredMenuItem[];
90
+ }
91
+ interface Menu {
92
+ name: string;
93
+ active: boolean;
94
+ items: MenuItem[];
95
+ structured: StructuredMenuItem[];
96
+ }
97
+ interface MenuResponse {
98
+ site: Site;
99
+ menu: Menu;
100
+ }
101
+ interface SearchOptions extends RequestOptions {
102
+ limit?: number;
103
+ }
104
+ interface SearchResponse {
105
+ site: Site;
106
+ pages: Page[];
107
+ }
108
+ interface ActionResponse {
109
+ message: string;
110
+ }
111
+ interface RequestOptions {
112
+ signal?: AbortSignal;
113
+ }
114
+ interface RawRequestOptions extends RequestInit {
115
+ /** Parse successful responses as JSON by default. */
116
+ parseAs?: 'json' | 'text' | 'response';
117
+ }
118
+ interface ConversationSendOptions extends RequestOptions {
119
+ sessionId?: string;
120
+ }
121
+ type ConversationFieldEvent = {
122
+ type: 'field_delta';
123
+ path: string;
124
+ delta: string;
125
+ value?: unknown;
126
+ [key: string]: unknown;
127
+ } | {
128
+ type: 'field_complete';
129
+ path: string;
130
+ value: unknown;
131
+ [key: string]: unknown;
132
+ } | {
133
+ type: 'field';
134
+ path: string;
135
+ value?: unknown;
136
+ delta?: string;
137
+ [key: string]: unknown;
138
+ };
139
+ interface ConversationUsageEvent {
140
+ type: 'conversation_usage';
141
+ user_turns: number;
142
+ max_user_turns: number;
143
+ reached_limit: boolean;
144
+ [key: string]: unknown;
145
+ }
146
+ interface ConversationCompleteEvent {
147
+ type: 'complete';
148
+ [key: string]: unknown;
149
+ }
150
+ interface ConversationErrorEvent {
151
+ type: 'error';
152
+ message: string;
153
+ request_id?: string;
154
+ [key: string]: unknown;
155
+ }
156
+ type ConversationEvent = ConversationFieldEvent | ConversationUsageEvent | ConversationCompleteEvent | ConversationErrorEvent | ({
157
+ type: string;
158
+ } & Record<string, unknown>);
159
+ interface ConversationEndResponse {
160
+ ended: boolean;
161
+ }
162
+ interface Conversation {
163
+ readonly sessionId: string | null;
164
+ send(query: string, options?: RequestOptions): AsyncIterable<ConversationEvent>;
165
+ end(options?: RequestOptions): Promise<ConversationEndResponse>;
166
+ reset(): void;
167
+ }
168
+ type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
169
+ interface ConvositeConfig {
170
+ /** Site ULID used by the Convosite runtime API. */
171
+ site: string;
172
+ /** Laravel runtime API base. Defaults to https://app.convosite.io/api. */
173
+ baseUrl?: string;
174
+ /** Conversations Worker base. Defaults to baseUrl (the production Worker is routed through app.convosite.io). */
175
+ conversationUrl?: string;
176
+ /** Custom fetch implementation for SSR runtimes, tests, proxies, etc. */
177
+ fetch?: Fetch;
178
+ /** Headers applied to Laravel API requests. */
179
+ headers?: HeadersInit;
180
+ /** Timeout for non-streaming requests in milliseconds. Defaults to 30000. Set 0 to disable. */
181
+ timeout?: number;
182
+ }
183
+ interface ConvositeClient {
184
+ readonly site: {
185
+ get(options?: RequestOptions): Promise<Site>;
186
+ };
187
+ readonly pages: {
188
+ get(path: string, options?: RequestOptions): Promise<PageResponse>;
189
+ find(id: string, options?: RequestOptions): Promise<PageResponse>;
190
+ list(options?: PageListOptions): Promise<PageListResponse>;
191
+ };
192
+ readonly menus: {
193
+ get(id: string, options?: RequestOptions): Promise<MenuResponse>;
194
+ };
195
+ search(query: string, options?: SearchOptions): Promise<SearchResponse>;
196
+ readonly actions: {
197
+ run<TInput extends Record<string, unknown> = Record<string, unknown>>(endpointId: string, input: TInput, options?: RequestOptions): Promise<ActionResponse>;
198
+ };
199
+ readonly conversations: {
200
+ create(sessionId?: string): Conversation;
201
+ send(query: string, options?: ConversationSendOptions): AsyncIterable<ConversationEvent>;
202
+ end(sessionId: string, options?: RequestOptions): Promise<ConversationEndResponse>;
203
+ };
204
+ request<T = unknown>(path: string, options?: RawRequestOptions): Promise<T>;
205
+ }
206
+
207
+ declare function createConvosite(config: ConvositeConfig): ConvositeClient;
208
+
209
+ declare class ConvositeError extends Error {
210
+ readonly status: number;
211
+ readonly code: string | null;
212
+ readonly details: unknown;
213
+ readonly requestId: string | null;
214
+ constructor(options: {
215
+ message: string;
216
+ status?: number;
217
+ code?: string | null;
218
+ details?: unknown;
219
+ requestId?: string | null;
220
+ cause?: unknown;
221
+ });
222
+ }
223
+
224
+ export { type ActionResponse, type Conversation, type ConversationCompleteEvent, type ConversationEndResponse, type ConversationErrorEvent, type ConversationEvent, type ConversationFieldEvent, type ConversationSendOptions, type ConversationUsageEvent, type ConvositeClient, type ConvositeConfig, ConvositeError, type Fetch, type JsonPrimitive, type JsonValue, type Media, type Menu, type MenuItem, type MenuResponse, type Page, type PageBlock, type PageListOptions, type PageListResponse, type PageMetaValue, type PageResponse, type PageSort, type Pagination, type RawRequestOptions, type RequestOptions, type SearchOptions, type SearchResponse, type Site, type SiteMetaValue, type SortDirection, type StructuredMenuItem, createConvosite };
@@ -0,0 +1,224 @@
1
+ type JsonPrimitive = string | number | boolean | null;
2
+ type JsonValue = JsonPrimitive | JsonValue[] | {
3
+ [key: string]: JsonValue;
4
+ };
5
+ interface SiteMetaValue<T = unknown> {
6
+ type: string;
7
+ key: string;
8
+ value: T;
9
+ }
10
+ interface Site {
11
+ name: string;
12
+ global: Record<string, SiteMetaValue>;
13
+ }
14
+ interface Media {
15
+ id: string;
16
+ url: string;
17
+ alt?: string | null;
18
+ caption?: string | null;
19
+ width?: number | null;
20
+ height?: number | null;
21
+ mime?: string | null;
22
+ bytes?: number | null;
23
+ metadata?: Record<string, unknown> | null;
24
+ [key: string]: unknown;
25
+ }
26
+ interface PageBlock<TData extends Record<string, unknown> = Record<string, unknown>> {
27
+ key: string;
28
+ name: string;
29
+ data: TData;
30
+ }
31
+ interface PageMetaValue<T = unknown> {
32
+ type: string;
33
+ key: string;
34
+ value: T;
35
+ }
36
+ interface Page {
37
+ id: string;
38
+ name: string;
39
+ slug: string;
40
+ active: boolean;
41
+ is_home: boolean;
42
+ path: string;
43
+ seo: {
44
+ title: string | null;
45
+ description: string | null;
46
+ };
47
+ blocks: PageBlock[];
48
+ meta: Record<string, PageMetaValue>;
49
+ score?: number;
50
+ [key: string]: unknown;
51
+ }
52
+ interface PageResponse {
53
+ site: Site;
54
+ page: Page;
55
+ }
56
+ interface Pagination {
57
+ current_page: number;
58
+ per_page: number;
59
+ total: number;
60
+ last_page: number;
61
+ from: number | null;
62
+ to: number | null;
63
+ }
64
+ type PageSort = 'name' | 'slug' | 'title' | 'created_at' | 'updated_at';
65
+ type SortDirection = 'asc' | 'desc';
66
+ interface PageListOptions extends RequestOptions {
67
+ parentId?: string | null;
68
+ sort?: PageSort;
69
+ direction?: SortDirection;
70
+ page?: number;
71
+ perPage?: number;
72
+ }
73
+ interface PageListResponse {
74
+ site: Site;
75
+ pages: Page[];
76
+ pagination: Pagination;
77
+ }
78
+ interface MenuItem {
79
+ id: string;
80
+ parent_id: string | null;
81
+ name: string;
82
+ description: string | null;
83
+ classes: string | null;
84
+ type: string;
85
+ position: number;
86
+ href: string | null;
87
+ }
88
+ interface StructuredMenuItem extends MenuItem {
89
+ children: StructuredMenuItem[];
90
+ }
91
+ interface Menu {
92
+ name: string;
93
+ active: boolean;
94
+ items: MenuItem[];
95
+ structured: StructuredMenuItem[];
96
+ }
97
+ interface MenuResponse {
98
+ site: Site;
99
+ menu: Menu;
100
+ }
101
+ interface SearchOptions extends RequestOptions {
102
+ limit?: number;
103
+ }
104
+ interface SearchResponse {
105
+ site: Site;
106
+ pages: Page[];
107
+ }
108
+ interface ActionResponse {
109
+ message: string;
110
+ }
111
+ interface RequestOptions {
112
+ signal?: AbortSignal;
113
+ }
114
+ interface RawRequestOptions extends RequestInit {
115
+ /** Parse successful responses as JSON by default. */
116
+ parseAs?: 'json' | 'text' | 'response';
117
+ }
118
+ interface ConversationSendOptions extends RequestOptions {
119
+ sessionId?: string;
120
+ }
121
+ type ConversationFieldEvent = {
122
+ type: 'field_delta';
123
+ path: string;
124
+ delta: string;
125
+ value?: unknown;
126
+ [key: string]: unknown;
127
+ } | {
128
+ type: 'field_complete';
129
+ path: string;
130
+ value: unknown;
131
+ [key: string]: unknown;
132
+ } | {
133
+ type: 'field';
134
+ path: string;
135
+ value?: unknown;
136
+ delta?: string;
137
+ [key: string]: unknown;
138
+ };
139
+ interface ConversationUsageEvent {
140
+ type: 'conversation_usage';
141
+ user_turns: number;
142
+ max_user_turns: number;
143
+ reached_limit: boolean;
144
+ [key: string]: unknown;
145
+ }
146
+ interface ConversationCompleteEvent {
147
+ type: 'complete';
148
+ [key: string]: unknown;
149
+ }
150
+ interface ConversationErrorEvent {
151
+ type: 'error';
152
+ message: string;
153
+ request_id?: string;
154
+ [key: string]: unknown;
155
+ }
156
+ type ConversationEvent = ConversationFieldEvent | ConversationUsageEvent | ConversationCompleteEvent | ConversationErrorEvent | ({
157
+ type: string;
158
+ } & Record<string, unknown>);
159
+ interface ConversationEndResponse {
160
+ ended: boolean;
161
+ }
162
+ interface Conversation {
163
+ readonly sessionId: string | null;
164
+ send(query: string, options?: RequestOptions): AsyncIterable<ConversationEvent>;
165
+ end(options?: RequestOptions): Promise<ConversationEndResponse>;
166
+ reset(): void;
167
+ }
168
+ type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
169
+ interface ConvositeConfig {
170
+ /** Site ULID used by the Convosite runtime API. */
171
+ site: string;
172
+ /** Laravel runtime API base. Defaults to https://app.convosite.io/api. */
173
+ baseUrl?: string;
174
+ /** Conversations Worker base. Defaults to baseUrl (the production Worker is routed through app.convosite.io). */
175
+ conversationUrl?: string;
176
+ /** Custom fetch implementation for SSR runtimes, tests, proxies, etc. */
177
+ fetch?: Fetch;
178
+ /** Headers applied to Laravel API requests. */
179
+ headers?: HeadersInit;
180
+ /** Timeout for non-streaming requests in milliseconds. Defaults to 30000. Set 0 to disable. */
181
+ timeout?: number;
182
+ }
183
+ interface ConvositeClient {
184
+ readonly site: {
185
+ get(options?: RequestOptions): Promise<Site>;
186
+ };
187
+ readonly pages: {
188
+ get(path: string, options?: RequestOptions): Promise<PageResponse>;
189
+ find(id: string, options?: RequestOptions): Promise<PageResponse>;
190
+ list(options?: PageListOptions): Promise<PageListResponse>;
191
+ };
192
+ readonly menus: {
193
+ get(id: string, options?: RequestOptions): Promise<MenuResponse>;
194
+ };
195
+ search(query: string, options?: SearchOptions): Promise<SearchResponse>;
196
+ readonly actions: {
197
+ run<TInput extends Record<string, unknown> = Record<string, unknown>>(endpointId: string, input: TInput, options?: RequestOptions): Promise<ActionResponse>;
198
+ };
199
+ readonly conversations: {
200
+ create(sessionId?: string): Conversation;
201
+ send(query: string, options?: ConversationSendOptions): AsyncIterable<ConversationEvent>;
202
+ end(sessionId: string, options?: RequestOptions): Promise<ConversationEndResponse>;
203
+ };
204
+ request<T = unknown>(path: string, options?: RawRequestOptions): Promise<T>;
205
+ }
206
+
207
+ declare function createConvosite(config: ConvositeConfig): ConvositeClient;
208
+
209
+ declare class ConvositeError extends Error {
210
+ readonly status: number;
211
+ readonly code: string | null;
212
+ readonly details: unknown;
213
+ readonly requestId: string | null;
214
+ constructor(options: {
215
+ message: string;
216
+ status?: number;
217
+ code?: string | null;
218
+ details?: unknown;
219
+ requestId?: string | null;
220
+ cause?: unknown;
221
+ });
222
+ }
223
+
224
+ export { type ActionResponse, type Conversation, type ConversationCompleteEvent, type ConversationEndResponse, type ConversationErrorEvent, type ConversationEvent, type ConversationFieldEvent, type ConversationSendOptions, type ConversationUsageEvent, type ConvositeClient, type ConvositeConfig, ConvositeError, type Fetch, type JsonPrimitive, type JsonValue, type Media, type Menu, type MenuItem, type MenuResponse, type Page, type PageBlock, type PageListOptions, type PageListResponse, type PageMetaValue, type PageResponse, type PageSort, type Pagination, type RawRequestOptions, type RequestOptions, type SearchOptions, type SearchResponse, type Site, type SiteMetaValue, type SortDirection, type StructuredMenuItem, createConvosite };