@adaptive-ai/sdk 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/client/index.d.ts +80 -0
- package/dist/client/index.js +2 -0
- package/dist/server/index.d.ts +243 -0
- package/dist/server/index.js +2 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Adaptive Computer, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { MutationFunction, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
|
|
3
|
+
type AuthProvider = 'GITHUB_USER' | 'GITHUB_BOT' | 'GOOGLE' | 'AC1' | 'SLACK' | 'SLACK_BOT' | 'DISCORD' | 'NOTION' | 'TWITTER' | 'LINKEDIN' | 'FIGMA';
|
|
4
|
+
type ProviderInput = {
|
|
5
|
+
provider: AuthProvider;
|
|
6
|
+
scope?: string[];
|
|
7
|
+
redirectUri?: string;
|
|
8
|
+
};
|
|
9
|
+
type RedirectInput = {
|
|
10
|
+
email: string;
|
|
11
|
+
provider: 'AC1';
|
|
12
|
+
phoneNumber: null | undefined;
|
|
13
|
+
} | {
|
|
14
|
+
phoneNumber: string;
|
|
15
|
+
provider: 'AC1';
|
|
16
|
+
email: null | undefined;
|
|
17
|
+
} | ProviderInput;
|
|
18
|
+
type AuthenticatedResult = {
|
|
19
|
+
userId: string;
|
|
20
|
+
signIn: (i?: RedirectInput) => void;
|
|
21
|
+
status: 'authenticated';
|
|
22
|
+
providers: AuthProvider[];
|
|
23
|
+
};
|
|
24
|
+
type UnauthenticatedResult = {
|
|
25
|
+
userId: null;
|
|
26
|
+
signIn: (i?: RedirectInput) => void;
|
|
27
|
+
status: 'unauthenticated';
|
|
28
|
+
providers: [];
|
|
29
|
+
};
|
|
30
|
+
type LoadingAuthResult = {
|
|
31
|
+
userId: undefined;
|
|
32
|
+
signIn: (i?: RedirectInput) => void;
|
|
33
|
+
status: 'loading';
|
|
34
|
+
providers: [];
|
|
35
|
+
};
|
|
36
|
+
declare global {
|
|
37
|
+
interface EmailHandlerInput {
|
|
38
|
+
subject: string;
|
|
39
|
+
body: string;
|
|
40
|
+
fromUserId: string;
|
|
41
|
+
}
|
|
42
|
+
interface Window {
|
|
43
|
+
__VERSION_ID__: string;
|
|
44
|
+
__APP_ID__: string;
|
|
45
|
+
__IS_TESTING__: boolean;
|
|
46
|
+
__ROOT_URL__: string;
|
|
47
|
+
__BASE_URL__: string;
|
|
48
|
+
__REALTIME_DOMAIN__: string;
|
|
49
|
+
__OPEN_AUTH_DRAWER__: (url: string) => void;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare function encodeFileAsBase64DataURL(file: File): Promise<string>;
|
|
54
|
+
declare function useRedirectToLogin(): {
|
|
55
|
+
redirectToLogin: (input?: {
|
|
56
|
+
email?: string;
|
|
57
|
+
}) => void;
|
|
58
|
+
};
|
|
59
|
+
declare function useAuth(input: {
|
|
60
|
+
required: true;
|
|
61
|
+
}): AuthenticatedResult | LoadingAuthResult;
|
|
62
|
+
declare function useAuth(input: {
|
|
63
|
+
required: false;
|
|
64
|
+
}): AuthenticatedResult | UnauthenticatedResult | LoadingAuthResult;
|
|
65
|
+
declare function useAuth(): AuthenticatedResult | UnauthenticatedResult | LoadingAuthResult;
|
|
66
|
+
declare function getBaseUrl(): string;
|
|
67
|
+
declare function connectToRealtimeStore<T extends object>({ channelId, initialData, broadcastOnly, onUpdate, }: {
|
|
68
|
+
channelId: string;
|
|
69
|
+
initialData: T;
|
|
70
|
+
broadcastOnly?: boolean;
|
|
71
|
+
onUpdate?: (data: T) => void;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
getData(): T;
|
|
74
|
+
setData(data: T): void;
|
|
75
|
+
destroy(): void;
|
|
76
|
+
}>;
|
|
77
|
+
declare function useRealtimeStore<T extends object>(channelId: string | null, initialData: T): readonly [T | undefined, (data: T) => void];
|
|
78
|
+
declare function useRealtimeMutation<TData extends object, TError = unknown, TVariables = void, TContext = unknown>(fn: MutationFunction<TData, TVariables>, opts?: Omit<UseMutationOptions<TData, TError, TVariables, TContext>, 'mutationFn'>): UseMutationResult<TData, TError, TVariables, TContext>;
|
|
79
|
+
|
|
80
|
+
export { connectToRealtimeStore, encodeFileAsBase64DataURL, getBaseUrl, useAuth, useRealtimeMutation, useRealtimeStore, useRedirectToLogin };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {useMutation}from'@tanstack/react-query';import {identity}from'lodash';import {nanoid}from'nanoid';import {useState,useEffect,useRef,useCallback}from'react';import p from'superjson';function b(e){return new Promise(r=>{let n=new FileReader;n.onload=()=>{r(n.result);},n.readAsDataURL(e);})}var l=e=>{let{email:r,phoneNumber:n}=e??{},s=r??n,t=new URLSearchParams;e&&"redirectUri"in e&&e.redirectUri?t.set("returnTo",e.redirectUri):t.set("returnTo",window.location.pathname+window.location.search),e?.provider&&e.provider!="AC1"&&(t.set("provider",e.provider),e.scope&&e.scope.length>0&&t.set("scope",e.scope.join(","))),e?.provider=="AC1"&&s&&t.set("identity",s),t.set("stripped","true");let o=window.__APP_ID__;window.__OPEN_AUTH_DRAWER__(`${window.__ROOT_URL__}/setup/${o}?${t.toString()}`);};function M(){return {redirectToLogin:e=>e?.email?l({email:e.email,provider:"AC1"}):l()}}function P(e={}){let[r,n]=useState({userId:void 0,status:"loading",signIn:l,providers:[]});return useEffect(()=>{(async()=>{try{let o=await(await fetch("/api/session",{method:"POST",headers:{"Content-Type":"application/json","x-guest-api-internal":"session","x-version-id":window.__VERSION_ID__,...window.__IS_TESTING__?{"x-is-testing":"true"}:{}}})).json()??{};n({userId:o.userId??null,status:"authenticated",signIn:l,providers:o?.providers??[]});}catch{if(e.required){let o=encodeURIComponent(window.location.pathname+window.location.search),d=window.__APP_ID__;window.top?window.top.location.href=`${window.__ROOT_URL__}/setup/${d}?returnTo=${o}`:window.location.href=`${window.__ROOT_URL__}/setup/${d}?returnTo=${o}`;}else n({userId:null,status:"unauthenticated",signIn:l,providers:[]});}})();},[e.required]),r}function $(){return window.__BASE_URL__}async function I({channelId:e,initialData:r,broadcastOnly:n,onUpdate:s}){let t=r,o=0,d=window.__REALTIME_DOMAIN__;if(n)return {getData(){return t},setData(u){t=u,fetch(`https://${d}/${e}`,{method:"POST",body:p.stringify(t)}).catch(console.error),s?.(u);},destroy(){}};let a=new WebSocket(`wss://${d}/${e}`);return new Promise((u,w)=>{function h(i){try{let c=JSON.parse(i.data.toString());c?.id&&c.id>o?(t=p.parse(c.payload),s?.(t),o=c.id):console.error("Invalid message:",i.data);}catch{console.error("Error parsing message:",i.data);}}function T(i){m(),w(i);}function R(){u({getData(){return t},setData(i){t=i,s?.(i),a.send(p.stringify(i));},destroy:m});}function m(){a.removeEventListener("message",h),a.removeEventListener("error",T),a.removeEventListener("open",R),a.close();}a.addEventListener("message",h),a.addEventListener("error",T),a.addEventListener("open",R);})}function L(e,r){let n=useRef(null),[s,t]=useState(0);return useEffect(()=>((async()=>e&&(n.current=await I({channelId:e,initialData:r,onUpdate:()=>{t(o=>o+1);}})))(),n.current?.destroy),[e,t]),[n.current?.getData(),n.current?.setData??identity]}function C(e,r){let[n,s]=useState(null),[t]=L(n,void 0),o=useCallback(async a=>{let u=nanoid(32);return s(u),await e?.({...a,__channelId:u})},[e]);return {...useMutation(o,r),data:t}}
|
|
2
|
+
export{I as connectToRealtimeStore,b as encodeFileAsBase64DataURL,$ as getBaseUrl,P as useAuth,C as useRealtimeMutation,L as useRealtimeStore,M as useRedirectToLogin};
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import * as _ac1_db from '@ac1/db';
|
|
2
|
+
import { AuthProvider } from '@ac1/iso/auth';
|
|
3
|
+
import { ZodSchema } from 'zod';
|
|
4
|
+
|
|
5
|
+
type ProductKind = 'IN_APP_PURCHASE' | 'SUBSCRIPTION';
|
|
6
|
+
type TaskStatus = {
|
|
7
|
+
id: string;
|
|
8
|
+
status: 'RUNNING' | 'COMPLETED' | 'FAILED';
|
|
9
|
+
error?: any;
|
|
10
|
+
} | {
|
|
11
|
+
id: string;
|
|
12
|
+
status: 'UNKNOWN';
|
|
13
|
+
};
|
|
14
|
+
type CatalogVoice = {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
previewUrl: string;
|
|
19
|
+
tier: 'FREE' | 'ONE' | 'TWO';
|
|
20
|
+
};
|
|
21
|
+
type CatalogImageModel = {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
tier: 'FREE' | 'ONE' | 'TWO';
|
|
26
|
+
};
|
|
27
|
+
type AuthStatus = {
|
|
28
|
+
status: 'authenticated';
|
|
29
|
+
userId: string;
|
|
30
|
+
signIn: typeof signIn;
|
|
31
|
+
providers: AuthProvider[];
|
|
32
|
+
} | {
|
|
33
|
+
status: 'unauthenticated';
|
|
34
|
+
userId: null;
|
|
35
|
+
signIn: typeof signIn;
|
|
36
|
+
providers: [];
|
|
37
|
+
};
|
|
38
|
+
type RedirectInput = {
|
|
39
|
+
email: string;
|
|
40
|
+
provider: typeof AuthProvider.AC1;
|
|
41
|
+
phoneNumber: null | undefined;
|
|
42
|
+
} | {
|
|
43
|
+
phoneNumber: string;
|
|
44
|
+
provider: typeof AuthProvider.AC1;
|
|
45
|
+
email: null | undefined;
|
|
46
|
+
} | {
|
|
47
|
+
provider: AuthProvider;
|
|
48
|
+
};
|
|
49
|
+
type ExternalApiMessage = any;
|
|
50
|
+
interface RequestContext {
|
|
51
|
+
requestId: string;
|
|
52
|
+
channelId?: string;
|
|
53
|
+
hasTasks?: boolean;
|
|
54
|
+
}
|
|
55
|
+
declare function getRequestContext(): RequestContext | undefined;
|
|
56
|
+
declare function setRequestContext(context: Partial<RequestContext>): void;
|
|
57
|
+
declare function runWithContext<T>(context: RequestContext, fn: () => Promise<T>): Promise<T>;
|
|
58
|
+
declare function signIn(input?: RedirectInput): void;
|
|
59
|
+
declare function getUserId(input?: {
|
|
60
|
+
throwIfNotLoggedIn?: boolean;
|
|
61
|
+
}): Promise<string | null>;
|
|
62
|
+
declare function getAuth(input: {
|
|
63
|
+
required: true;
|
|
64
|
+
}): Promise<AuthStatus>;
|
|
65
|
+
declare function getAuth(input?: {
|
|
66
|
+
required?: boolean;
|
|
67
|
+
}): Promise<AuthStatus>;
|
|
68
|
+
declare function queueTask(runner: () => Promise<void>): Promise<TaskStatus>;
|
|
69
|
+
declare function getTaskStatus(taskId: string): Promise<TaskStatus>;
|
|
70
|
+
declare function getStructuredDataFromContent<T>(input: {
|
|
71
|
+
url: string;
|
|
72
|
+
base64?: never;
|
|
73
|
+
schema: ZodSchema<T>;
|
|
74
|
+
} | {
|
|
75
|
+
url?: never;
|
|
76
|
+
base64: string;
|
|
77
|
+
schema: ZodSchema<T>;
|
|
78
|
+
}): Promise<T>;
|
|
79
|
+
declare function extractTextFromContent(input: {
|
|
80
|
+
url: string;
|
|
81
|
+
base64?: never;
|
|
82
|
+
outputFormat: 'raw' | 'formatted-markdown';
|
|
83
|
+
} | {
|
|
84
|
+
url?: never;
|
|
85
|
+
base64: string;
|
|
86
|
+
outputFormat: 'raw' | 'formatted-markdown';
|
|
87
|
+
}): Promise<string>;
|
|
88
|
+
declare function requestMultimodalModel<T>(input: {
|
|
89
|
+
messages: ExternalApiMessage[];
|
|
90
|
+
system?: string;
|
|
91
|
+
returnType: ZodSchema<T>;
|
|
92
|
+
model?: 'small' | 'medium' | 'large';
|
|
93
|
+
temperature?: number;
|
|
94
|
+
stream?: (data: Partial<T>) => void;
|
|
95
|
+
onProgress?: (data: Array<{
|
|
96
|
+
toolName: string;
|
|
97
|
+
inProgressMessage: string;
|
|
98
|
+
status: 'in_progress' | 'done';
|
|
99
|
+
thinking: string;
|
|
100
|
+
}>) => void;
|
|
101
|
+
customTools?: Array<{
|
|
102
|
+
name: string;
|
|
103
|
+
displayName: string;
|
|
104
|
+
description: string;
|
|
105
|
+
inputSchema: ZodSchema<any>;
|
|
106
|
+
inProgressMessage: string;
|
|
107
|
+
}>;
|
|
108
|
+
}): Promise<T>;
|
|
109
|
+
declare function textToImage(input: {
|
|
110
|
+
text: string;
|
|
111
|
+
size?: 'square_hd' | 'square' | 'portrait_4_3' | 'portrait_16_9' | 'landscape_4_3' | 'landscape_16_9';
|
|
112
|
+
}): Promise<string | null>;
|
|
113
|
+
declare function textToSpeech(input: {
|
|
114
|
+
text: string;
|
|
115
|
+
voice?: 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer';
|
|
116
|
+
}): Promise<{
|
|
117
|
+
url: string;
|
|
118
|
+
duration: number | undefined;
|
|
119
|
+
} | null>;
|
|
120
|
+
declare function generateSoundEffect(input: {
|
|
121
|
+
text: string;
|
|
122
|
+
durationInSeconds?: number;
|
|
123
|
+
promptInfluence?: number;
|
|
124
|
+
loop?: boolean;
|
|
125
|
+
}): Promise<any>;
|
|
126
|
+
declare function generateDialogue(input: {
|
|
127
|
+
inputs: {
|
|
128
|
+
character: string;
|
|
129
|
+
text: string;
|
|
130
|
+
}[];
|
|
131
|
+
}): Promise<any>;
|
|
132
|
+
declare function generateMusic(input: {
|
|
133
|
+
text: string;
|
|
134
|
+
}): Promise<any>;
|
|
135
|
+
declare function upload(input: {
|
|
136
|
+
bufferOrBase64: Buffer | string;
|
|
137
|
+
fileName: string;
|
|
138
|
+
}): Promise<string>;
|
|
139
|
+
declare function getOAuthToken(input: {
|
|
140
|
+
connectionId: string;
|
|
141
|
+
}): Promise<any>;
|
|
142
|
+
declare function getOAuthConnectionForCurrentUser(input: {
|
|
143
|
+
provider: Exclude<AuthProvider, 'AC1'>;
|
|
144
|
+
scope?: string[];
|
|
145
|
+
required?: boolean;
|
|
146
|
+
}): Promise<any>;
|
|
147
|
+
declare function getOAuthConnection(input: {
|
|
148
|
+
connectionId: string;
|
|
149
|
+
}): Promise<any>;
|
|
150
|
+
declare function queryOAuthConnections(input: {
|
|
151
|
+
userId?: string;
|
|
152
|
+
provider?: Exclude<AuthProvider, 'AC1'>;
|
|
153
|
+
scope?: string[];
|
|
154
|
+
}): Promise<any>;
|
|
155
|
+
declare function deleteOAuthConnection(input: {
|
|
156
|
+
connectionId: string;
|
|
157
|
+
}): Promise<any>;
|
|
158
|
+
declare function sendEmail(input: {
|
|
159
|
+
markdown: string;
|
|
160
|
+
subject: string;
|
|
161
|
+
toUserId: string;
|
|
162
|
+
}): Promise<void>;
|
|
163
|
+
declare function inviteUser(input: {
|
|
164
|
+
email: string;
|
|
165
|
+
subject?: string;
|
|
166
|
+
markdown: string;
|
|
167
|
+
unauthenticatedLinks?: boolean;
|
|
168
|
+
}): Promise<{
|
|
169
|
+
id: string;
|
|
170
|
+
}>;
|
|
171
|
+
declare function searchWithGoogle(input: {
|
|
172
|
+
query: string;
|
|
173
|
+
}): Promise<{
|
|
174
|
+
answer: string | undefined;
|
|
175
|
+
sources: {
|
|
176
|
+
title: string;
|
|
177
|
+
url: string;
|
|
178
|
+
}[];
|
|
179
|
+
}>;
|
|
180
|
+
declare function isAppOwner(): Promise<boolean>;
|
|
181
|
+
declare function generateCrossAppToken(input: {
|
|
182
|
+
appId: string;
|
|
183
|
+
}): Promise<string>;
|
|
184
|
+
declare function createProduct(input: {
|
|
185
|
+
name: string;
|
|
186
|
+
description: string;
|
|
187
|
+
price: number;
|
|
188
|
+
kind: ProductKind;
|
|
189
|
+
}): Promise<{
|
|
190
|
+
purchaseLink: string;
|
|
191
|
+
id: string;
|
|
192
|
+
kind: _ac1_db.$Enums.ProductKind;
|
|
193
|
+
description: string;
|
|
194
|
+
name: string;
|
|
195
|
+
price: number;
|
|
196
|
+
}>;
|
|
197
|
+
declare function listProducts(): Promise<{
|
|
198
|
+
id: string;
|
|
199
|
+
name: string;
|
|
200
|
+
description: string;
|
|
201
|
+
kind: ProductKind;
|
|
202
|
+
price: number;
|
|
203
|
+
purchaseLink: string;
|
|
204
|
+
}[]>;
|
|
205
|
+
declare function listUserPurchases(input?: {
|
|
206
|
+
userId: string;
|
|
207
|
+
}): Promise<{
|
|
208
|
+
id: string;
|
|
209
|
+
kind: _ac1_db.$Enums.ProductKind;
|
|
210
|
+
description: string;
|
|
211
|
+
name: string;
|
|
212
|
+
price: number;
|
|
213
|
+
}[]>;
|
|
214
|
+
declare function discontinueProduct(input: {
|
|
215
|
+
productId: string;
|
|
216
|
+
}): Promise<void>;
|
|
217
|
+
declare function getRealtimeStore<T extends object>({ channelId, onUpdate, }: {
|
|
218
|
+
channelId: string;
|
|
219
|
+
onUpdate?: (data: T) => void;
|
|
220
|
+
}): {
|
|
221
|
+
destroy(): void;
|
|
222
|
+
};
|
|
223
|
+
declare function setRealtimeStore<T extends object>({ channelId, data, }: {
|
|
224
|
+
channelId: string;
|
|
225
|
+
data: T;
|
|
226
|
+
}): Promise<void>;
|
|
227
|
+
declare function startRealtimeResponse<T extends object>(): Promise<{
|
|
228
|
+
next(data: T): void;
|
|
229
|
+
end(): T;
|
|
230
|
+
}>;
|
|
231
|
+
declare function getTTSVoicesCatalog(input: {
|
|
232
|
+
limit: number;
|
|
233
|
+
}): Promise<CatalogVoice[]>;
|
|
234
|
+
declare function getDialogueVoicesCatalog(input: {
|
|
235
|
+
limit: number;
|
|
236
|
+
}): Promise<CatalogVoice[]>;
|
|
237
|
+
declare function getImageModelsCatalog(input: {
|
|
238
|
+
limit: number;
|
|
239
|
+
}): Promise<CatalogImageModel[]>;
|
|
240
|
+
declare function getBaseUrl(): string;
|
|
241
|
+
declare function getLastStreamTime(): number | null;
|
|
242
|
+
|
|
243
|
+
export { type ProductKind, createProduct, deleteOAuthConnection, discontinueProduct, extractTextFromContent, generateCrossAppToken, generateDialogue, generateMusic, generateSoundEffect, getAuth, getBaseUrl, getDialogueVoicesCatalog, getImageModelsCatalog, getLastStreamTime, getOAuthConnection, getOAuthConnectionForCurrentUser, getOAuthToken, getRealtimeStore, getRequestContext, getStructuredDataFromContent, getTTSVoicesCatalog, getTaskStatus, getUserId, inviteUser, isAppOwner, listProducts, listUserPurchases, queryOAuthConnections, queueTask, requestMultimodalModel, runWithContext, searchWithGoogle, sendEmail, setRealtimeStore, setRequestContext, startRealtimeResponse, textToImage, textToSpeech, upload };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {MissingAuthError}from'@ac1/iso/errors';import {createTRPCProxyClient,httpLink}from'@trpc/client';import {AsyncLocalStorage}from'async_hooks';import {nanoid}from'nanoid';import g from'superjson';import w from'zod-to-json-schema';import {z as z$1}from'zod';var b=z$1.object({GUEST_SERVICES_URL:z$1.string().url().default("http://localhost:3000/trpc"),REALTIME_DOMAIN:z$1.string().default("localhost:3002"),BASE_URL:z$1.string().url().default("http://localhost:3001"),NODE_ENV:z$1.enum(["development","production","test"]).default("development")}),h=b.safeParse({GUEST_SERVICES_URL:process.env.GUEST_SERVICES_URL,REALTIME_DOMAIN:process.env.REALTIME_DOMAIN,BASE_URL:process.env.BASE_URL,NODE_ENV:process.env.NODE_ENV});if(!h.success)throw console.error("Invalid environment variables:",h.error.format()),new Error("Invalid environment variables");var c=h.data;var A=new AsyncLocalStorage,y=null,S=new Set,p=null;function r(){return y||(y=createTRPCProxyClient({transformer:g,links:[httpLink({url:c.GUEST_SERVICES_URL,headers:()=>{let t=T();if(!t)throw new Error("Missing request context");return {"x-request-id":t.requestId}}})]})),y}function T(){return A.getStore()}function k(t){let e=T();e&&Object.assign(e,t);}async function W(t,e){return A.run(t,e)}function E(t){throw new MissingAuthError({provider:t?.provider??"AC1",popup:true})}async function $(t){let n=await r().getCurrentUser.mutate(t);if(n?.error==="SEED")throw new Error('Call to "getUserId" in seed function is not allowed. Seed functions should not depend on user data.');if(!n?.userId){if(t?.throwIfNotLoggedIn??true)throw new MissingAuthError({provider:"AC1"});return null}return n.userId}async function Z(t){let n=await r().getCurrentUser.mutate({throwIfNotLoggedIn:t?.required});if(n?.error==="SEED")throw new Error('Call to "getAuth" in seed function is not allowed. Seed functions should not depend on user data.');if(n.userId)return {userId:n.userId,status:"authenticated",signIn:E,providers:n.providers};if(t?.required)throw new MissingAuthError({provider:"AC1"});return {userId:null,status:"unauthenticated",signIn:E,providers:[]}}async function K(t){let e=r(),n=await e.upsertTaskStatus.mutate({status:"RUNNING"});return S.add(n.id),k({hasTasks:true}),(async()=>{let o=n.id;try{await t(),await e.upsertTaskStatus.mutate({id:o,status:"COMPLETED"});}catch(s){console.error(`Task ${o} failed:`,s.message),await e.upsertTaskStatus.mutate({id:o,status:"FAILED",error:s});}finally{S.delete(n.id);}})(),n}async function z(t){return await r().getTaskStatus.mutate({id:t})}async function J(t){let e=r(),n={...t,schema:w(t.schema)};return await e.extractStructuredDataFromContent.mutate(n)}async function H(t){return await r().extractTextFromContent.mutate(t)}async function Q(t){let e=r(),{stream:n,onProgress:o,...s}=t,d={...s,returnType:w(t.returnType),customTools:t.customTools?.map(i=>({...i,inputSchema:w(i.inputSchema)}))};if(n??o){let i=nanoid(32),f=new WebSocket(`wss://${c.REALTIME_DOMAIN}/${i}`),x=-1,v=C=>{p=Date.now();try{let a=JSON.parse(C.data.toString());if(a?.id&&a.id>x){let R=g.parse(a.payload);a.requestAgentToolCalls instanceof Array?o?.(a.requestAgentToolCalls):n?.(R),x=a.id;}}catch{}};f.addEventListener("message",v);let I=await e.requestMultimodalModel.mutate({...d,realtimeChannelId:i});return n&&n(I),f.close(),f.removeEventListener("message",v),I}return await e.requestMultimodalModel.mutate(d)}async function X(t){return await r().textToImage.mutate(t)}async function Y(t){return await r().textToSpeech.mutate(t)}async function tt(t){return await r().generateSoundEffect.mutate(t)}async function et(t){return await r().generateDialogue.mutate(t)}async function nt(t){return await r().generateMusic.mutate(t)}async function rt(t){let e=r(),n;return typeof t.bufferOrBase64=="string"?n=t.bufferOrBase64:n=t.bufferOrBase64.toString("base64"),await e.uploadToBucket.mutate({base64:n,fileName:t.fileName})}async function ot(t){return await r().getOAuthToken.mutate({connectionId:t.connectionId})}async function st(t){let n=await r().getOAuthConnectionForCurrentUser.mutate({...t,scope:t.scope??[]});if(!n&&t.required)throw new MissingAuthError({provider:t.provider,scope:t.scope,popup:true});return n}async function it(t){return await r().getOAuthConnection.mutate(t)}async function at(t){return await r().queryOAuthConnections.mutate(t)}async function ut(t){return await r().deleteOAuthConnection.mutate(t)}async function ct(t){await r().sendEmail.mutate(t);}async function lt(t){let e=r();if(!t.email)throw new Error("Email is required");if(!t.markdown)throw new Error("`markdown` content is required when inviting by email");return await e.inviteUser.mutate(t)}async function dt(t){return await r().searchWithGoogle.mutate(t)}async function mt(){return await r().isAppOwner.mutate()}async function gt(t){return await r().generateCrossAppToken.mutate(t)}async function pt(t){return await r().createProduct.mutate(t)}async function ft(){return await r().listProducts.mutate()}async function ht(t){return await r().listUserPurchases.mutate(t)}async function yt(t){await r().discontinueProduct.mutate(t);}function wt({channelId:t,onUpdate:e}){let n=new WebSocket(`wss://${c.REALTIME_DOMAIN}/${t}`),o=-1;function s(d){e&&(p=Date.now());try{let u=JSON.parse(d.data.toString());if(u?.id&&u.id>o){let i=g.parse(u.payload);e?.(i),o=u.id;}}catch{}}return n.addEventListener("message",s),{destroy(){n.close(),n.removeEventListener("message",s);}}}async function P({channelId:t,data:e}){p=Date.now(),await fetch(`https://${c.REALTIME_DOMAIN}/${t}`,{method:"POST",body:g.stringify(e)}).catch(console.error);}async function Tt(){let t,e=T()?.channelId;if(!e)throw new Error("API's using `startRealtimeResponse` must be called via `useRealtimeMutation`.");return {next(n){t=n,P({channelId:e,data:n});},end(){return P({channelId:e,data:t}),t}}}async function xt(t){return await r().getTTSVoicesCatalog.mutate(t)}async function vt(t){return await r().getDialogueVoicesCatalog.mutate(t)}async function It(t){return await r().getImageModelsCatalog.mutate(t)}function St(){return c.BASE_URL}function Et(){return p}
|
|
2
|
+
export{pt as createProduct,ut as deleteOAuthConnection,yt as discontinueProduct,H as extractTextFromContent,gt as generateCrossAppToken,et as generateDialogue,nt as generateMusic,tt as generateSoundEffect,Z as getAuth,St as getBaseUrl,vt as getDialogueVoicesCatalog,It as getImageModelsCatalog,Et as getLastStreamTime,it as getOAuthConnection,st as getOAuthConnectionForCurrentUser,ot as getOAuthToken,wt as getRealtimeStore,T as getRequestContext,J as getStructuredDataFromContent,xt as getTTSVoicesCatalog,z as getTaskStatus,$ as getUserId,lt as inviteUser,mt as isAppOwner,ft as listProducts,ht as listUserPurchases,at as queryOAuthConnections,K as queueTask,Q as requestMultimodalModel,W as runWithContext,dt as searchWithGoogle,ct as sendEmail,P as setRealtimeStore,k as setRequestContext,Tt as startRealtimeResponse,X as textToImage,Y as textToSpeech,rt as upload};
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adaptive-ai/sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./client": {
|
|
8
|
+
"types": "./dist/client/index.d.ts",
|
|
9
|
+
"import": "./dist/client/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./server": {
|
|
12
|
+
"types": "./dist/server/index.d.ts",
|
|
13
|
+
"import": "./dist/server/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@tanstack/react-query": ">=4",
|
|
23
|
+
"@trpc/client": ">=10",
|
|
24
|
+
"lodash": ">=4",
|
|
25
|
+
"nanoid": ">=4",
|
|
26
|
+
"openai": ">=4",
|
|
27
|
+
"react": ">=18",
|
|
28
|
+
"superjson": ">=1",
|
|
29
|
+
"zod": ">=3",
|
|
30
|
+
"zod-to-json-schema": ">=3"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"@tanstack/react-query": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"lodash": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"react": {
|
|
40
|
+
"optional": false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"optionalPeerDependencies": {
|
|
44
|
+
"ws": "^8"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/eslint": "^8.44.2",
|
|
48
|
+
"@types/lodash": "^4.14.200",
|
|
49
|
+
"@types/node": "^20.14.8",
|
|
50
|
+
"@types/react": "19.0.10",
|
|
51
|
+
"@types/ws": "^8.5.10",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
53
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
54
|
+
"eslint": "^8.47.0",
|
|
55
|
+
"eslint-config-next": "15.2.1",
|
|
56
|
+
"eslint-config-prettier": "^9.0.0",
|
|
57
|
+
"eslint-formatter-codeframe": "^7.32.1",
|
|
58
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
59
|
+
"eslint-plugin-simple-import-sort": "^12.1.0",
|
|
60
|
+
"npm-run-all": "^4.1.5",
|
|
61
|
+
"prettier": "^3.0.3",
|
|
62
|
+
"rimraf": "^6.0.1",
|
|
63
|
+
"tsup": "^8.2.4",
|
|
64
|
+
"tsx": "^4.7.1",
|
|
65
|
+
"typescript": "^5.8.2",
|
|
66
|
+
"@ac1/iso": "0.1.1",
|
|
67
|
+
"@ac1/core": "0.1.1"
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"pnpm": ">=10.6.1",
|
|
74
|
+
"node": ">=18.17.0 <22.0.0"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"lint": "NODE_OPTIONS='--max-old-space-size=8192' eslint --cache .",
|
|
78
|
+
"lint:fix": "eslint --cache --fix .",
|
|
79
|
+
"check": "NODE_OPTIONS='--max-old-space-size=8192' tsc --noEmit",
|
|
80
|
+
"build": "tsup",
|
|
81
|
+
"clean": "rimraf dist"
|
|
82
|
+
}
|
|
83
|
+
}
|