@adaptive-ai/sdk 0.1.0 → 0.1.2

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.
@@ -1,392 +1,98 @@
1
- import * as z from 'zod';
2
- import { ChatCompletionMessageParam, ChatCompletionContentPart, ChatCompletionMessageFunctionToolCall } from 'openai/resources';
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { createTRPCProxyClient } from '@trpc/client';
3
4
 
4
- declare const ProductKind: {
5
- readonly SUBSCRIPTION: "SUBSCRIPTION";
6
- readonly IN_APP_PURCHASE: "IN_APP_PURCHASE";
7
- };
8
- type ProductKind = (typeof ProductKind)[keyof typeof ProductKind];
9
5
  declare const AuthProvider: {
10
- readonly GITHUB_USER: "GITHUB_USER";
11
- readonly GITHUB_BOT: "GITHUB_BOT";
12
- readonly GOOGLE: "GOOGLE";
13
- readonly AC1: "AC1";
14
- readonly SLACK: "SLACK";
15
- readonly SLACK_BOT: "SLACK_BOT";
16
- readonly DISCORD: "DISCORD";
17
- readonly NOTION: "NOTION";
18
- readonly TWITTER: "TWITTER";
19
- readonly LINKEDIN: "LINKEDIN";
20
- readonly YAHOO: "YAHOO";
21
- readonly FIGMA: "FIGMA";
22
- };
23
- type AuthProvider = (typeof AuthProvider)[keyof typeof AuthProvider];
24
- type CatalogVoice = {
25
- id: string;
26
- name: string;
27
- description?: string;
28
- previewUrl: string;
29
- tier: 'FREE' | 'ONE' | 'TWO';
6
+ readonly GITHUB_USER: "GITHUB_USER";
7
+ readonly GITHUB_BOT: "GITHUB_BOT";
8
+ readonly GOOGLE: "GOOGLE";
9
+ readonly AC1: "AC1";
10
+ readonly SLACK: "SLACK";
11
+ readonly SLACK_BOT: "SLACK_BOT";
12
+ readonly DISCORD: "DISCORD";
13
+ readonly NOTION: "NOTION";
14
+ readonly TWITTER: "TWITTER";
15
+ readonly LINKEDIN: "LINKEDIN";
16
+ readonly YAHOO: "YAHOO";
17
+ readonly FIGMA: "FIGMA";
30
18
  };
31
- type CatalogImageModel = {
32
- id: string;
33
- name: string;
34
- description?: string;
35
- tier: 'FREE' | 'ONE' | 'TWO';
19
+ export type AuthProvider = (typeof AuthProvider)[keyof typeof AuthProvider];
20
+ export type ProviderInput = {
21
+ provider: AuthProvider;
22
+ scope?: string[];
23
+ redirectUri?: string;
36
24
  };
37
- declare const AgentDefinitions: {
38
- readonly ProductManagerAgent: "ProductManagerAgent";
39
- readonly AppDeveloperAgent: "AppDeveloperAgent";
40
- };
41
- interface ChatCompletionContentPartThinking {
42
- thought: string;
43
- signature?: string;
44
- provider: string;
45
- }
46
- interface ChatCompletionContentPartPDF {
47
- pdf_url: ChatCompletionContentPartPDF.PDFURL;
48
- /**
49
- * The type of the content part.
50
- */
51
- type: 'pdf_url';
52
- }
53
- declare namespace ChatCompletionContentPartPDF {
54
- interface PDFURL {
55
- /**
56
- * The URL of the PDF file.
57
- */
58
- url: string;
59
- }
60
- }
61
- interface ChatCompletionContentPartVideo {
62
- video_url: ChatCompletionContentPartVideo.VideoURL;
63
- /**
64
- * The type of the content part.
65
- */
66
- type: 'video_url';
67
- }
68
- declare namespace ChatCompletionContentPartVideo {
69
- interface VideoURL {
70
- /**
71
- * The URL of the video file.
72
- */
73
- url: string;
74
- }
75
- }
76
- interface ChatCompletionContentPartAudio {
77
- audio_url: ChatCompletionContentPartAudio.AudioURL;
78
- /**
79
- * The type of the content part.
80
- */
81
- type: 'audio_url';
82
- }
83
- declare namespace ChatCompletionContentPartAudio {
84
- interface AudioURL {
85
- /**
86
- * The URL of the audio file.
87
- */
88
- url: string;
89
- }
90
- }
91
- type ExternalApiMessage = {
92
- role: Exclude<ChatCompletionMessageParam['role'], 'function'>;
93
- content?: string | Array<(ChatCompletionContentPart & {
94
- cache_control?: {
95
- type: 'ephemeral';
96
- };
97
- }) | (ChatCompletionContentPartPDF & {
98
- cache_control?: {
99
- type: 'ephemeral';
100
- };
101
- }) | (ChatCompletionContentPartVideo & {
102
- cache_control?: {
103
- type: 'ephemeral';
104
- };
105
- }) | (ChatCompletionContentPartAudio & {
106
- cache_control?: {
107
- type: 'ephemeral';
108
- };
109
- })>;
110
- id?: string;
111
- tool_call_id?: string | null;
112
- tool_calls?: Array<ChatCompletionMessageFunctionToolCall> | null;
113
- thinking?: ChatCompletionContentPartThinking;
114
- name?: 'client' | 'attachments' | keyof typeof AgentDefinitions | null;
25
+ export type RedirectInput = {
26
+ email: string;
27
+ provider: "AC1";
28
+ phoneNumber: null | undefined;
29
+ } | {
30
+ phoneNumber: string;
31
+ provider: "AC1";
32
+ email: null | undefined;
33
+ } | ProviderInput;
34
+ export type RequestContext = {
35
+ requestId: string;
36
+ channelId?: string;
37
+ hasTasks?: boolean;
115
38
  };
116
- declare global {
117
- interface EmailHandlerInput {
118
- subject: string;
119
- body: string;
120
- fromUserId: string;
121
- }
122
- interface Window {
123
- __VERSION_ID__?: string;
124
- __APP_ID__: string;
125
- __IS_TESTING__: boolean;
126
- __ROOT_URL__: string;
127
- __BASE_URL__: string;
128
- __REALTIME_DOMAIN__: string;
129
- __OPEN_AUTH_DRAWER__: (url: string) => void;
130
- }
131
- var env: {
132
- BASE_URL: string;
133
- REALTIME_DOMAIN: string;
134
- GUEST_SERVICES_URL: string;
135
- };
39
+ export interface EmailHandlerInput {
40
+ subject: string;
41
+ body: string;
42
+ fromUserId: string;
136
43
  }
137
-
138
- interface RequestContext {
139
- requestId: string;
140
- channelId?: string;
141
- hasTasks?: boolean;
142
- }
143
- declare function initializeServerEnvironment({ baseUrl, realtimeDomain, guestServicesUrl, }: {
144
- baseUrl: string;
145
- realtimeDomain: string;
146
- guestServicesUrl: string;
44
+ declare let client: ReturnType<typeof createTRPCProxyClient<GuestServicesRouter>>;
45
+ export declare function initializeServerEnvironment({ baseUrl, realtimeDomain, guestServicesUrl, }: {
46
+ baseUrl: string;
47
+ realtimeDomain: string;
48
+ guestServicesUrl: string;
147
49
  }): void;
148
- declare function getRequestContext(): RequestContext | undefined;
149
- declare function setRequestContext(context: Partial<RequestContext>): void;
150
- declare function runWithContext<T>(context: RequestContext, fn: () => Promise<T>): Promise<T>;
151
- type RedirectInput = {
152
- email: string;
153
- provider: typeof AuthProvider.AC1;
154
- phoneNumber: null | undefined;
155
- } | {
156
- phoneNumber: string;
157
- provider: typeof AuthProvider.AC1;
158
- email: null | undefined;
159
- } | {
160
- provider: (typeof AuthProvider)[keyof typeof AuthProvider];
50
+ export type MutationProxy<TClient> = {
51
+ [K in keyof TClient as TClient[K] extends {
52
+ mutate: (...args: any) => any;
53
+ } ? K : never]: TClient[K] extends {
54
+ mutate: (...args: infer TArgs) => infer TReturn;
55
+ } ? (args: TArgs[0]) => TReturn : never;
56
+ };
57
+ export type MCP = MutationProxy<typeof client>;
58
+ export declare const mcp: MCP;
59
+ export declare function getRequestContext(): RequestContext | undefined;
60
+ export declare function setRequestContext(context: Partial<RequestContext>): void;
61
+ export declare function runWithContext<T>(context: RequestContext, fn: () => Promise<T>): Promise<T>;
62
+ export declare function getBaseUrl(): string;
63
+ export declare function getLastStreamTime(): number | null;
64
+ export declare function getRealtimeStore<T extends object>({ channelId, onUpdate, }: {
65
+ channelId: string;
66
+ onUpdate?: (data: T) => void;
67
+ }): {
68
+ destroy(): void;
161
69
  };
70
+ export declare function setRealtimeStore<T extends object>({ channelId, data, }: {
71
+ channelId: string;
72
+ data: T;
73
+ }): Promise<void>;
74
+ export declare function startRealtimeResponse<T extends object>(): Promise<{
75
+ next(data: T): void;
76
+ end(): T;
77
+ }>;
162
78
  declare function signIn(input?: RedirectInput): void;
163
- declare function getUserId(input?: {
164
- throwIfNotLoggedIn?: boolean;
165
- }): Promise<string | null>;
166
- type AuthStatus = {
167
- status: 'authenticated';
168
- userId: string;
169
- signIn: typeof signIn;
170
- providers: AuthProvider[];
79
+ export type AuthStatus = {
80
+ status: "authenticated";
81
+ userId: string;
82
+ signIn: typeof signIn;
83
+ providers: AuthProvider[];
171
84
  } | {
172
- status: 'unauthenticated';
173
- userId: null;
174
- signIn: typeof signIn;
175
- providers: [];
85
+ status: "unauthenticated";
86
+ userId: null;
87
+ signIn: typeof signIn;
88
+ providers: [
89
+ ];
176
90
  };
177
- declare function getAuth(input: {
178
- required: true;
91
+ export declare function getAuth(input: {
92
+ required: true;
179
93
  }): Promise<AuthStatus>;
180
- declare function getAuth(input?: {
181
- required?: boolean;
94
+ export declare function getAuth(input?: {
95
+ required?: boolean;
182
96
  }): Promise<AuthStatus>;
183
- type TaskStatus = {
184
- id: string;
185
- status: 'RUNNING' | 'COMPLETED' | 'FAILED';
186
- error?: any;
187
- } | {
188
- id: string;
189
- status: 'UNKNOWN';
190
- };
191
- declare function queueTask(runner: () => Promise<void>): Promise<TaskStatus>;
192
- declare function getTaskStatus(taskId: string): Promise<TaskStatus>;
193
- declare function getStructuredDataFromContent<T>(input: {
194
- url: string;
195
- base64?: never;
196
- schema: z.ZodSchema<T>;
197
- } | {
198
- url?: never;
199
- base64: string;
200
- schema: z.ZodSchema<T>;
201
- }): Promise<T>;
202
- declare function extractTextFromContent(input: {
203
- url: string;
204
- base64?: never;
205
- outputFormat: 'raw' | 'formatted-markdown';
206
- } | {
207
- url?: never;
208
- base64: string;
209
- outputFormat: 'raw' | 'formatted-markdown';
210
- }): Promise<string>;
211
- declare function requestMultimodalModel<T>(input: {
212
- messages: ExternalApiMessage[];
213
- system?: string;
214
- returnType: z.ZodSchema<T>;
215
- model?: 'small' | 'medium' | 'large';
216
- temperature?: number;
217
- stream?: (data: Partial<T>) => void;
218
- onProgress?: (data: Array<{
219
- toolName: string;
220
- inProgressMessage: string;
221
- status: 'in_progress' | 'done';
222
- thinking: string;
223
- }>) => void;
224
- customTools?: Array<{
225
- name: string;
226
- displayName: string;
227
- description: string;
228
- inputSchema: z.ZodSchema<any>;
229
- inProgressMessage: string;
230
- }>;
231
- }): Promise<T>;
232
- declare function textToImage(input: {
233
- text: string;
234
- size?: 'square_hd' | 'square' | 'portrait_4_3' | 'portrait_16_9' | 'landscape_4_3' | 'landscape_16_9';
235
- }): Promise<string | null>;
236
- declare function textToSpeech(input: {
237
- text: string;
238
- voice?: 'Will' | 'Brian' | 'George' | 'Jessica' | 'Liam' | 'Alice' | 'Sarah' | 'Charlotte' | 'Matilda' | 'Eric' | 'Alloy' | 'Ash' | 'Ballad' | 'Coral' | 'Echo' | 'Fable' | 'Nova' | 'Onyx' | 'Sage' | 'Shimmer';
239
- }): Promise<{
240
- url: string;
241
- duration: number | undefined;
242
- } | null>;
243
- declare function generateSoundEffect(input: {
244
- text: string;
245
- durationInSeconds?: number;
246
- promptInfluence?: number;
247
- loop?: boolean;
248
- }): Promise<any>;
249
- declare function generateDialogue(input: {
250
- inputs: {
251
- character: string;
252
- text: string;
253
- }[];
254
- }): Promise<{
255
- url: string;
256
- duration: number | undefined;
257
- }>;
258
- declare function generateMusic(input: {
259
- text: string;
260
- }): Promise<string>;
261
- declare function upload(input: {
262
- bufferOrBase64: Buffer | string;
263
- fileName: string;
264
- }): Promise<string>;
265
- declare function getOAuthToken(input: {
266
- connectionId: string;
267
- }): Promise<{
268
- connectionId: string;
269
- userId: string | null;
270
- accessToken: string | null;
271
- expiresAt: Date | null;
272
- scope: string[];
273
- }>;
274
- declare function getOAuthConnectionForCurrentUser(input: {
275
- provider: Exclude<AuthProvider, 'AC1'>;
276
- scope?: string[];
277
- required?: boolean;
278
- }): Promise<{
279
- id: string;
280
- provider: string;
281
- userId: string | undefined;
282
- scope: string[];
283
- } | null>;
284
- declare function getOAuthConnection(input: {
285
- connectionId: string;
286
- }): Promise<{
287
- id: string;
288
- provider: string;
289
- userId: string | undefined;
290
- scope: string[];
291
- }>;
292
- declare function queryOAuthConnections(input: {
293
- userId?: string;
294
- provider?: Exclude<AuthProvider, 'AC1'>;
295
- scope?: string[];
296
- }): Promise<{
297
- id: string;
298
- provider: string;
299
- userId: string | undefined;
300
- scope: string[];
301
- }[]>;
302
- declare function deleteOAuthConnection(input: {
303
- connectionId: string;
304
- }): Promise<{
305
- readonly ok: true;
306
- }>;
307
- declare function sendEmail(input: {
308
- markdown: string;
309
- subject: string;
310
- toUserId: string;
311
- }): Promise<void>;
312
- declare function inviteUser(input: {
313
- email: string;
314
- subject?: string;
315
- markdown: string;
316
- unauthenticatedLinks?: boolean;
317
- }): Promise<{
318
- id: string;
319
- }>;
320
- declare function searchWithGoogle(input: {
321
- query: string;
322
- }): Promise<{
323
- answer: string | undefined;
324
- sources: {
325
- title: string;
326
- url: string;
327
- }[];
328
- }>;
329
- declare function isAppOwner(): Promise<boolean>;
330
- declare function generateCrossAppToken(input: {
331
- appId: string;
332
- }): Promise<string>;
333
- declare function createProduct(input: {
334
- name: string;
335
- description: string;
336
- price: number;
337
- kind: ProductKind;
338
- }): Promise<{
339
- purchaseLink: string;
340
- id: string;
341
- description: string;
342
- name: string;
343
- kind: ProductKind;
344
- price: number;
345
- }>;
346
- declare function listProducts(): Promise<{
347
- id: string;
348
- name: string;
349
- description: string;
350
- kind: ProductKind;
351
- price: number;
352
- purchaseLink: string;
353
- }[]>;
354
- declare function listUserPurchases(input?: {
355
- userId: string;
356
- }): Promise<{
357
- id: string;
358
- kind: ProductKind;
359
- description: string;
360
- name: string;
361
- price: number;
362
- }[]>;
363
- declare function discontinueProduct(input: {
364
- productId: string;
365
- }): Promise<void>;
366
- declare function getRealtimeStore<T extends object>({ channelId, onUpdate, }: {
367
- channelId: string;
368
- onUpdate?: (data: T) => void;
369
- }): {
370
- destroy(): void;
371
- };
372
- declare function setRealtimeStore<T extends object>({ channelId, data, }: {
373
- channelId: string;
374
- data: T;
375
- }): Promise<void>;
376
- declare function startRealtimeResponse<T extends object>(): Promise<{
377
- next(data: T): void;
378
- end(): T;
379
- }>;
380
- declare function getTTSVoicesCatalog(input: {
381
- limit: number;
382
- }): Promise<CatalogVoice[]>;
383
- declare function getDialogueVoicesCatalog(input: {
384
- limit: number;
385
- }): Promise<CatalogVoice[]>;
386
- declare function getImageModelsCatalog(input: {
387
- limit: number;
388
- }): Promise<CatalogImageModel[]>;
389
- declare function getBaseUrl(): string;
390
- declare function getLastStreamTime(): number | null;
391
97
 
392
- export { createProduct, deleteOAuthConnection, discontinueProduct, extractTextFromContent, generateCrossAppToken, generateDialogue, generateMusic, generateSoundEffect, getAuth, getBaseUrl, getDialogueVoicesCatalog, getImageModelsCatalog, getLastStreamTime, getOAuthConnection, getOAuthConnectionForCurrentUser, getOAuthToken, getRealtimeStore, getRequestContext, getStructuredDataFromContent, getTTSVoicesCatalog, getTaskStatus, getUserId, initializeServerEnvironment, inviteUser, isAppOwner, listProducts, listUserPurchases, queryOAuthConnections, queueTask, requestMultimodalModel, runWithContext, searchWithGoogle, sendEmail, setRealtimeStore, setRequestContext, startRealtimeResponse, textToImage, textToSpeech, upload };
98
+ export {};
@@ -1,2 +1,2 @@
1
- import {createTRPCProxyClient,httpLink}from'@trpc/client';import {AsyncLocalStorage}from'async_hooks';import {nanoid}from'nanoid';import _ from'superjson';import*as S from'zod';function O(e){let t=Object.create(null);for(let r in e){let n=e[r];t[n]=r;}return t}var y={PARSE_ERROR:-32700,BAD_REQUEST:-32600,INTERNAL_SERVER_ERROR:-32603,NOT_IMPLEMENTED:-32603,UNAUTHORIZED:-32001,FORBIDDEN:-32003,NOT_FOUND:-32004,METHOD_NOT_SUPPORTED:-32005,TIMEOUT:-32008,CONFLICT:-32009,PRECONDITION_FAILED:-32012,PAYLOAD_TOO_LARGE:-32013,UNPROCESSABLE_CONTENT:-32022,TOO_MANY_REQUESTS:-32029,CLIENT_CLOSED_REQUEST:-32099};O(y);O(y);typeof window>"u"||"Deno"in window||globalThis.process?.env?.NODE_ENV==="test"||!!globalThis.process?.env?.JEST_WORKER_ID||!!globalThis.process?.env?.VITEST_WORKER_ID;var h=class e extends Error{static prefix="__MISSING AUTH FOR SCOPE";static jsonRpcCode=-32001;constructor({provider:t,scope:r,accountId:n,popup:o=false}){let s=btoa(JSON.stringify({provider:t,scope:r,accountId:n}));super(`${e.prefix}: ${s}${o?" --popup":" end"}`);}jsonRpcError(){return {code:e.jsonRpcCode,message:this.message}}static check(t){return t?.message?.startsWith(e.prefix)}};function Ge({baseUrl:e,realtimeDomain:t,guestServicesUrl:r}){globalThis.env||(globalThis.env={},globalThis.env.BASE_URL=e,globalThis.env.REALTIME_DOMAIN=t,globalThis.env.GUEST_SERVICES_URL=r,console.log("Adaptive SDK server environment initialized"));}var Q=new AsyncLocalStorage,k=null,K=new Set,P=null;function u(){return k||(k=createTRPCProxyClient({transformer:_,links:[httpLink({url:env.GUEST_SERVICES_URL,transformer:_,headers:()=>{let e=M();if(!e)throw new Error("Missing request context");return {"x-request-id":e.requestId}}})]})),k}function M(){return Q.getStore()}function he(e){let t=M();t&&Object.assign(t,e);}async function We(e,t){return Q.run(e,t)}function J(e){throw new h({provider:e?.provider??"AC1",popup:true})}async function Ke(e){let r=await u().getCurrentUser.mutate(e);if(r?.error==="SEED")throw new Error('Call to "getUserId" in seed function is not allowed. Seed functions should not depend on user data.');if(!r?.userId){if(e?.throwIfNotLoggedIn??true)throw new h({provider:"AC1"});return null}return r.userId}async function Je(e){let r=await u().getCurrentUser.mutate({throwIfNotLoggedIn:e?.required});if(r?.error==="SEED")throw new Error('Call to "getAuth" in seed function is not allowed. Seed functions should not depend on user data.');if(r.userId)return {userId:r.userId,status:"authenticated",signIn:J,providers:r.providers};if(e?.required)throw new h({provider:"AC1"});return {userId:null,status:"unauthenticated",signIn:J,providers:[]}}async function He(e){let t=u(),r=await t.upsertTaskStatus.mutate({status:"RUNNING"});return K.add(r.id),he({hasTasks:true}),(async()=>{let n=r.id;try{await e(),await t.upsertTaskStatus.mutate({id:n,status:"COMPLETED"});}catch(o){console.error(`Task ${n} failed:`,o.message),await t.upsertTaskStatus.mutate({id:n,status:"FAILED",error:o});}finally{K.delete(r.id);}})(),r}async function Qe(e){return await u().getTaskStatus.mutate({id:e})}async function Ze(e){let t=u(),r={...e,schema:S.toJSONSchema(e.schema)};return await t.extractStructuredDataFromContent.mutate(r)}async function Xe(e){return await u().extractTextFromContent.mutate(e)}async function et(e){let t=u(),{stream:r,onProgress:n,...o}=e,s={...o,returnType:S.toJSONSchema(e.returnType),customTools:e.customTools?.map(d=>({...d,inputSchema:S.toJSONSchema(d.inputSchema)}))};if(r??n){let d=nanoid(32),a=new WebSocket(`wss://${env.REALTIME_DOMAIN}/${d}`),l=-1,c=p=>{P=Date.now();try{let g=JSON.parse(p.data.toString());if(g?.id&&g.id>l){let Z=_.parse(g.payload);g.requestAgentToolCalls instanceof Array?n?.(g.requestAgentToolCalls):r?.(Z),l=g.id;}}catch{}};a.addEventListener("message",c);let m=await t.requestMultimodalModel.mutate({...s,realtimeChannelId:d});return r&&r(m),a.close(),a.removeEventListener("message",c),m}return await t.requestMultimodalModel.mutate(s)}async function tt(e){return await u().textToImage.mutate(e)}async function rt(e){return await u().textToSpeech.mutate(e)}async function nt(e){return await u().generateSoundEffect.mutate(e)}async function ot(e){return await u().generateDialogue.mutate(e)}async function st(e){return await u().generateMusic.mutate(e)}async function it(e){let t=u(),r;return typeof e.bufferOrBase64=="string"?r=e.bufferOrBase64:r=e.bufferOrBase64.toString("base64"),await t.uploadToBucket.mutate({base64:r,fileName:e.fileName})}async function at(e){return await u().getOAuthToken.mutate({connectionId:e.connectionId})}async function ut(e){let r=await u().getOAuthConnectionForCurrentUser.mutate({...e,scope:e.scope??[]});if(!r&&e.required)throw new h({provider:e.provider,scope:e.scope,popup:true});return r}async function ct(e){return await u().getOAuthConnection.mutate(e)}async function dt(e){return await u().queryOAuthConnections.mutate(e)}async function lt(e){return await u().deleteOAuthConnection.mutate(e)}async function ft(e){await u().sendEmail.mutate(e);}async function pt(e){let t=u();if(!e.email)throw new Error("Email is required");if(!e.markdown)throw new Error("`markdown` content is required when inviting by email");return await t.inviteUser.mutate(e)}async function mt(e){return await u().searchWithGoogle.mutate(e)}async function gt(){return await u().isAppOwner.mutate()}async function wt(e){return await u().generateCrossAppToken.mutate(e)}async function ht(e){return await u().createProduct.mutate(e)}async function yt(){return await u().listProducts.mutate()}async function Et(e){return await u().listUserPurchases.mutate(e)}async function Tt(e){await u().discontinueProduct.mutate(e);}function _t({channelId:e,onUpdate:t}){let r=new WebSocket(`wss://${env.REALTIME_DOMAIN}/${e}`),n=-1;function o(s){t&&(P=Date.now());try{let i=JSON.parse(s.data.toString());if(i?.id&&i.id>n){let d=_.parse(i.payload);t?.(d),n=i.id;}}catch{}}return r.addEventListener("message",o),{destroy(){r.close(),r.removeEventListener("message",o);}}}async function H({channelId:e,data:t}){P=Date.now(),await fetch(`https://${env.REALTIME_DOMAIN}/${e}`,{method:"POST",body:_.stringify(t)}).catch(console.error);}async function Rt(){let e,t=M()?.channelId;if(!t)throw new Error("API's using `startRealtimeResponse` must be called via `useRealtimeMutation`.");return {next(r){e=r,H({channelId:t,data:r});},end(){return H({channelId:t,data:e}),e}}}async function St(e){return await u().getTTSVoicesCatalog.mutate(e)}async function Pt(e){return await u().getDialogueVoicesCatalog.mutate(e)}async function vt(e){return await u().getImageModelsCatalog.mutate(e)}function xt(){return env.BASE_URL}function Ot(){return P}
2
- export{ht as createProduct,lt as deleteOAuthConnection,Tt as discontinueProduct,Xe as extractTextFromContent,wt as generateCrossAppToken,ot as generateDialogue,st as generateMusic,nt as generateSoundEffect,Je as getAuth,xt as getBaseUrl,Pt as getDialogueVoicesCatalog,vt as getImageModelsCatalog,Ot as getLastStreamTime,ct as getOAuthConnection,ut as getOAuthConnectionForCurrentUser,at as getOAuthToken,_t as getRealtimeStore,M as getRequestContext,Ze as getStructuredDataFromContent,St as getTTSVoicesCatalog,Qe as getTaskStatus,Ke as getUserId,Ge as initializeServerEnvironment,pt as inviteUser,gt as isAppOwner,yt as listProducts,Et as listUserPurchases,dt as queryOAuthConnections,He as queueTask,et as requestMultimodalModel,We as runWithContext,mt as searchWithGoogle,ft as sendEmail,H as setRealtimeStore,he as setRequestContext,Rt as startRealtimeResponse,tt as textToImage,rt as textToSpeech,it as upload};
1
+ import {createTRPCProxyClient,httpLink}from'@trpc/client';import {AsyncLocalStorage}from'async_hooks';import g from'superjson';function S(e){let r=Object.create(null);for(let t in e){let n=e[t];r[n]=t;}return r}var w={PARSE_ERROR:-32700,BAD_REQUEST:-32600,INTERNAL_SERVER_ERROR:-32603,NOT_IMPLEMENTED:-32603,UNAUTHORIZED:-32001,FORBIDDEN:-32003,NOT_FOUND:-32004,METHOD_NOT_SUPPORTED:-32005,TIMEOUT:-32008,CONFLICT:-32009,PRECONDITION_FAILED:-32012,PAYLOAD_TOO_LARGE:-32013,UNPROCESSABLE_CONTENT:-32022,TOO_MANY_REQUESTS:-32029,CLIENT_CLOSED_REQUEST:-32099};S(w);S(w);typeof window>"u"||"Deno"in window||globalThis.process?.env?.NODE_ENV==="test"||!!globalThis.process?.env?.JEST_WORKER_ID||!!globalThis.process?.env?.VITEST_WORKER_ID;var y=class e extends Error{static prefix="__MISSING AUTH FOR SCOPE";static jsonRpcCode=-32001;constructor({provider:r,scope:t,accountId:n,popup:o=false}){let s=btoa(JSON.stringify({provider:r,scope:t,accountId:n}));super(`${e.prefix}: ${s}${o?" --popup":" end"}`);}jsonRpcError(){return {code:e.jsonRpcCode,message:this.message}}static check(r){return r?.message?.startsWith(e.prefix)}};var C=null;function je({baseUrl:e,realtimeDomain:r,guestServicesUrl:t}){globalThis.env||(globalThis.env={},globalThis.env.BASE_URL=e,globalThis.env.REALTIME_DOMAIN=r,globalThis.env.GUEST_SERVICES_URL=t,C=createTRPCProxyClient({transformer:g,links:[httpLink({url:t,transformer:g,headers:()=>{let n=A();if(!n)throw new Error("Missing request context");return {"x-request-id":n.requestId}}})]}),console.log("Adaptive SDK server environment initialized"));}var z=new AsyncLocalStorage,fe=new Proxy({},{get(e,r){return async t=>{if(!C)throw new Error("Adaptive SDK server environment is not initialized. Please call initializeServerEnvironment first.");let o=C[r];if(!o||typeof o.mutate!="function")throw new Error(`Property "${String(r)}" is not a mutation procedure`);return o.mutate(t)}}});function A(){return z.getStore()}function Le(e){let r=A();r&&Object.assign(r,e);}async function $e(e,r){return z.run(e,r)}function Be(){return globalThis.env.BASE_URL}var N=null;function Ve(){return N}function Ye({channelId:e,onUpdate:r}){let t=new WebSocket(`wss://${globalThis.env.REALTIME_DOMAIN}/${e}`),n=-1;function o(s){r&&(N=Date.now());try{let i=JSON.parse(s.data.toString());if(i?.id&&i.id>n){let d=g.parse(i.payload);r?.(d),n=i.id;}}catch{}}return t.addEventListener("message",o),{destroy(){t.close(),t.removeEventListener("message",o);}}}async function K({channelId:e,data:r}){N=Date.now(),await fetch(`https://${globalThis.env.REALTIME_DOMAIN}/${e}`,{method:"POST",body:g.stringify(r)}).catch(console.error);}async function Ke(){let e,r=A()?.channelId;if(!r)throw new Error("API's using `startRealtimeResponse` must be called via `useRealtimeMutation`.");return {next(t){e=t,K({channelId:r,data:t});},end(){return K({channelId:r,data:e}),e}}}function H(e){throw new y({provider:e?.provider??"AC1",popup:true})}async function He(e){let r=await fe.getCurrentUser();if(r?.error==="SEED")throw new Error('Call to "getAuth" in seed function is not allowed. Seed functions should not depend on user data.');if(r.userId)return {userId:r.userId,status:"authenticated",signIn:H,providers:r.providers};if(e?.required)throw new y({provider:"AC1"});return {userId:null,status:"unauthenticated",signIn:H,providers:[]}}
2
+ export{He as getAuth,Be as getBaseUrl,Ve as getLastStreamTime,Ye as getRealtimeStore,A as getRequestContext,je as initializeServerEnvironment,fe as mcp,$e as runWithContext,K as setRealtimeStore,Le as setRequestContext,Ke as startRealtimeResponse};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptive-ai/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,14 +19,16 @@
19
19
  "LICENSE"
20
20
  ],
21
21
  "peerDependencies": {
22
- "@tanstack/react-query": ">=4",
22
+ "@tanstack/react-query": ">=5",
23
23
  "@trpc/client": ">=10",
24
+ "@trpc/server": ">=10",
25
+ "typed-rpc": ">=5",
24
26
  "lodash": ">=4",
25
27
  "nanoid": ">=4",
26
28
  "openai": ">=4",
27
29
  "react": ">=18",
28
30
  "superjson": ">=1",
29
- "zod": ">=4"
31
+ "zod": ">=3"
30
32
  },
31
33
  "peerDependenciesMeta": {
32
34
  "@tanstack/react-query": {
@@ -54,7 +56,7 @@
54
56
  "browser-image-compression": "^2.0.2",
55
57
  "dom-to-image-more": "^3.7.2",
56
58
  "eslint": "^8.47.0",
57
- "eslint-config-next": "15.2.1",
59
+ "eslint-config-next": "15.5.6",
58
60
  "eslint-config-prettier": "^9.0.0",
59
61
  "eslint-formatter-codeframe": "^7.32.1",
60
62
  "eslint-plugin-prettier": "^5.0.1",
@@ -66,8 +68,8 @@
66
68
  "tsup": "^8.2.4",
67
69
  "tsx": "^4.7.1",
68
70
  "typescript": "^5.8.2",
69
- "@ac1/core": "0.1.1",
70
- "@ac1/iso": "0.1.1"
71
+ "@ac1/iso": "0.1.1",
72
+ "@ac1/core": "0.1.1"
71
73
  },
72
74
  "publishConfig": {
73
75
  "access": "public"
@@ -79,6 +81,7 @@
79
81
  "lint": "NODE_OPTIONS='--max-old-space-size=8192' eslint --cache .",
80
82
  "lint:fix": "eslint --cache --fix .",
81
83
  "check": "NODE_OPTIONS='--max-old-space-size=8192' tsc --noEmit",
84
+ "bundle": "./bundle.sh",
82
85
  "build": "tsup",
83
86
  "clean": "rimraf dist"
84
87
  }