@realtimex/sdk 1.3.0 → 1.3.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.
- package/dist/index.d.mts +161 -5
- package/dist/index.d.ts +161 -5
- package/dist/index.js +223 -7
- package/dist/index.mjs +222 -7
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -165,12 +165,23 @@ interface STTListenOptions {
|
|
|
165
165
|
interface STTModel {
|
|
166
166
|
id: string;
|
|
167
167
|
name: string;
|
|
168
|
-
provider
|
|
168
|
+
provider?: string;
|
|
169
169
|
description?: string;
|
|
170
170
|
language?: string;
|
|
171
171
|
size?: string;
|
|
172
172
|
recommended?: boolean;
|
|
173
173
|
}
|
|
174
|
+
interface STTProvider {
|
|
175
|
+
id: string;
|
|
176
|
+
name: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
models: STTModel[];
|
|
179
|
+
}
|
|
180
|
+
interface STTProvidersResponse {
|
|
181
|
+
success: boolean;
|
|
182
|
+
providers: STTProvider[];
|
|
183
|
+
error?: string;
|
|
184
|
+
}
|
|
174
185
|
interface STTModelsResponse {
|
|
175
186
|
success: boolean;
|
|
176
187
|
models: STTModel[];
|
|
@@ -787,10 +798,10 @@ declare class TTSModule {
|
|
|
787
798
|
|
|
788
799
|
declare class STTModule extends ApiModule {
|
|
789
800
|
/**
|
|
790
|
-
* Get available STT models.
|
|
791
|
-
* @returns Promise resolving to list of
|
|
801
|
+
* Get available STT providers and their models.
|
|
802
|
+
* @returns Promise resolving to list of providers
|
|
792
803
|
*/
|
|
793
|
-
|
|
804
|
+
listProviders(): Promise<STTProvider[]>;
|
|
794
805
|
/**
|
|
795
806
|
* Listen to microphone and transcribe speech to text.
|
|
796
807
|
* Performed on the client device (Electron) via the RealtimeX Hub.
|
|
@@ -801,6 +812,149 @@ declare class STTModule extends ApiModule {
|
|
|
801
812
|
listen(options: STTListenOptions): Promise<STTResponse>;
|
|
802
813
|
}
|
|
803
814
|
|
|
815
|
+
/**
|
|
816
|
+
* HTTP Client Module - Smart Client with Auth Handling
|
|
817
|
+
*/
|
|
818
|
+
declare class HttpClient {
|
|
819
|
+
private baseUrl;
|
|
820
|
+
private appId;
|
|
821
|
+
private apiKey?;
|
|
822
|
+
private accessToken?;
|
|
823
|
+
constructor(baseUrl: string, appId: string, apiKey?: string);
|
|
824
|
+
private getAppHeaders;
|
|
825
|
+
private getAccessToken;
|
|
826
|
+
fetch(endpoint: string, options?: RequestInit): Promise<Response>;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Agent Module - Simple session-based agent chat
|
|
831
|
+
*
|
|
832
|
+
* This module provides the simplest way to chat with AI agents:
|
|
833
|
+
* 1. Create a session (optional - can just chat directly)
|
|
834
|
+
* 2. Send messages (context is automatically maintained)
|
|
835
|
+
* 3. Close session when done (optional - auto-expires)
|
|
836
|
+
*/
|
|
837
|
+
|
|
838
|
+
interface AgentSessionOptions {
|
|
839
|
+
workspace_slug?: string;
|
|
840
|
+
thread_slug?: string;
|
|
841
|
+
agent_name?: string;
|
|
842
|
+
}
|
|
843
|
+
interface AgentSession {
|
|
844
|
+
session_id: string;
|
|
845
|
+
workspace: {
|
|
846
|
+
slug: string;
|
|
847
|
+
name: string;
|
|
848
|
+
};
|
|
849
|
+
thread?: {
|
|
850
|
+
slug: string;
|
|
851
|
+
name: string;
|
|
852
|
+
} | null;
|
|
853
|
+
agent: {
|
|
854
|
+
name: string;
|
|
855
|
+
provider: string;
|
|
856
|
+
model: string | null;
|
|
857
|
+
};
|
|
858
|
+
created_at: string;
|
|
859
|
+
}
|
|
860
|
+
interface AgentChatOptions {
|
|
861
|
+
message: string;
|
|
862
|
+
}
|
|
863
|
+
interface AgentChatResponse {
|
|
864
|
+
id: string;
|
|
865
|
+
session_id: string;
|
|
866
|
+
text: string;
|
|
867
|
+
thoughts: string[];
|
|
868
|
+
message_count: number;
|
|
869
|
+
}
|
|
870
|
+
interface AgentSessionInfo extends AgentSession {
|
|
871
|
+
message_count: number;
|
|
872
|
+
last_message_at: string | null;
|
|
873
|
+
}
|
|
874
|
+
interface StreamChunkEvent {
|
|
875
|
+
type: 'agentThought' | 'textResponse' | 'close' | 'error';
|
|
876
|
+
data: any;
|
|
877
|
+
}
|
|
878
|
+
declare class AgentModule {
|
|
879
|
+
private httpClient;
|
|
880
|
+
constructor(httpClient: HttpClient);
|
|
881
|
+
/**
|
|
882
|
+
* Create a new agent session
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```typescript
|
|
886
|
+
* const session = await sdk.agent.createSession({
|
|
887
|
+
* workspace_slug: 'my-workspace',
|
|
888
|
+
* agent_name: '@agent'
|
|
889
|
+
* });
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
createSession(options?: AgentSessionOptions): Promise<AgentSession>;
|
|
893
|
+
/**
|
|
894
|
+
* Chat within a session (synchronous)
|
|
895
|
+
*
|
|
896
|
+
* @example
|
|
897
|
+
* ```typescript
|
|
898
|
+
* const response = await sdk.agent.chat(sessionId, 'Hello agent!');
|
|
899
|
+
* console.log(response.text);
|
|
900
|
+
* ```
|
|
901
|
+
*/
|
|
902
|
+
chat(sessionId: string, message: string): Promise<AgentChatResponse>;
|
|
903
|
+
/**
|
|
904
|
+
* Stream chat within a session
|
|
905
|
+
* Returns an async iterator for SSE events
|
|
906
|
+
*
|
|
907
|
+
* @example
|
|
908
|
+
* ```typescript
|
|
909
|
+
* for await (const event of sdk.agent.streamChat(sessionId, 'Tell me a story')) {
|
|
910
|
+
* if (event.type === 'agentThought') {
|
|
911
|
+
* console.log('Thinking:', event.data.thought);
|
|
912
|
+
* } else if (event.type === 'textResponse') {
|
|
913
|
+
* console.log('Response:', event.data.textResponse);
|
|
914
|
+
* }
|
|
915
|
+
* }
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
streamChat(sessionId: string, message: string): AsyncIterableIterator<StreamChunkEvent>;
|
|
919
|
+
/**
|
|
920
|
+
* Get session information
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* const info = await sdk.agent.getSession(sessionId);
|
|
925
|
+
* console.log(`Messages sent: ${info.message_count}`);
|
|
926
|
+
* ```
|
|
927
|
+
*/
|
|
928
|
+
getSession(sessionId: string): Promise<AgentSessionInfo>;
|
|
929
|
+
/**
|
|
930
|
+
* Close and delete a session
|
|
931
|
+
* Sessions auto-expire after 1 hour, but you can close them manually
|
|
932
|
+
*
|
|
933
|
+
* @example
|
|
934
|
+
* ```typescript
|
|
935
|
+
* await sdk.agent.closeSession(sessionId);
|
|
936
|
+
* ```
|
|
937
|
+
*/
|
|
938
|
+
closeSession(sessionId: string): Promise<void>;
|
|
939
|
+
/**
|
|
940
|
+
* Helper: Create session and send first message in one call
|
|
941
|
+
* This is the simplest way to start chatting with an agent
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* const { session, response } = await sdk.agent.startChat('Hello agent!');
|
|
946
|
+
* console.log(response.text);
|
|
947
|
+
*
|
|
948
|
+
* // Continue chatting in the same session
|
|
949
|
+
* const reply = await sdk.agent.chat(session.session_id, 'Tell me more');
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
startChat(message: string, options?: AgentSessionOptions): Promise<{
|
|
953
|
+
session: AgentSession;
|
|
954
|
+
response: AgentChatResponse;
|
|
955
|
+
}>;
|
|
956
|
+
}
|
|
957
|
+
|
|
804
958
|
/**
|
|
805
959
|
* RealtimeX Local App SDK
|
|
806
960
|
*
|
|
@@ -817,11 +971,13 @@ declare class RealtimeXSDK {
|
|
|
817
971
|
llm: LLMModule;
|
|
818
972
|
tts: TTSModule;
|
|
819
973
|
stt: STTModule;
|
|
974
|
+
agent: AgentModule;
|
|
820
975
|
readonly appId: string;
|
|
821
976
|
readonly appName: string | undefined;
|
|
822
977
|
readonly apiKey: string | undefined;
|
|
823
978
|
private readonly realtimexUrl;
|
|
824
979
|
private readonly permissions;
|
|
980
|
+
private httpClient;
|
|
825
981
|
private static DEFAULT_REALTIMEX_URL;
|
|
826
982
|
constructor(config?: SDKConfig);
|
|
827
983
|
/**
|
|
@@ -850,4 +1006,4 @@ declare class RealtimeXSDK {
|
|
|
850
1006
|
getAppDataDir(): Promise<string>;
|
|
851
1007
|
}
|
|
852
1008
|
|
|
853
|
-
export { ActivitiesModule, type Activity, type Agent, ApiModule, type ChatMessage, type ChatOptions, type ChatResponse, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTResponse, type StreamChunk, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace };
|
|
1009
|
+
export { ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, type ChatMessage, type ChatOptions, type ChatResponse, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace };
|
package/dist/index.d.ts
CHANGED
|
@@ -165,12 +165,23 @@ interface STTListenOptions {
|
|
|
165
165
|
interface STTModel {
|
|
166
166
|
id: string;
|
|
167
167
|
name: string;
|
|
168
|
-
provider
|
|
168
|
+
provider?: string;
|
|
169
169
|
description?: string;
|
|
170
170
|
language?: string;
|
|
171
171
|
size?: string;
|
|
172
172
|
recommended?: boolean;
|
|
173
173
|
}
|
|
174
|
+
interface STTProvider {
|
|
175
|
+
id: string;
|
|
176
|
+
name: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
models: STTModel[];
|
|
179
|
+
}
|
|
180
|
+
interface STTProvidersResponse {
|
|
181
|
+
success: boolean;
|
|
182
|
+
providers: STTProvider[];
|
|
183
|
+
error?: string;
|
|
184
|
+
}
|
|
174
185
|
interface STTModelsResponse {
|
|
175
186
|
success: boolean;
|
|
176
187
|
models: STTModel[];
|
|
@@ -787,10 +798,10 @@ declare class TTSModule {
|
|
|
787
798
|
|
|
788
799
|
declare class STTModule extends ApiModule {
|
|
789
800
|
/**
|
|
790
|
-
* Get available STT models.
|
|
791
|
-
* @returns Promise resolving to list of
|
|
801
|
+
* Get available STT providers and their models.
|
|
802
|
+
* @returns Promise resolving to list of providers
|
|
792
803
|
*/
|
|
793
|
-
|
|
804
|
+
listProviders(): Promise<STTProvider[]>;
|
|
794
805
|
/**
|
|
795
806
|
* Listen to microphone and transcribe speech to text.
|
|
796
807
|
* Performed on the client device (Electron) via the RealtimeX Hub.
|
|
@@ -801,6 +812,149 @@ declare class STTModule extends ApiModule {
|
|
|
801
812
|
listen(options: STTListenOptions): Promise<STTResponse>;
|
|
802
813
|
}
|
|
803
814
|
|
|
815
|
+
/**
|
|
816
|
+
* HTTP Client Module - Smart Client with Auth Handling
|
|
817
|
+
*/
|
|
818
|
+
declare class HttpClient {
|
|
819
|
+
private baseUrl;
|
|
820
|
+
private appId;
|
|
821
|
+
private apiKey?;
|
|
822
|
+
private accessToken?;
|
|
823
|
+
constructor(baseUrl: string, appId: string, apiKey?: string);
|
|
824
|
+
private getAppHeaders;
|
|
825
|
+
private getAccessToken;
|
|
826
|
+
fetch(endpoint: string, options?: RequestInit): Promise<Response>;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Agent Module - Simple session-based agent chat
|
|
831
|
+
*
|
|
832
|
+
* This module provides the simplest way to chat with AI agents:
|
|
833
|
+
* 1. Create a session (optional - can just chat directly)
|
|
834
|
+
* 2. Send messages (context is automatically maintained)
|
|
835
|
+
* 3. Close session when done (optional - auto-expires)
|
|
836
|
+
*/
|
|
837
|
+
|
|
838
|
+
interface AgentSessionOptions {
|
|
839
|
+
workspace_slug?: string;
|
|
840
|
+
thread_slug?: string;
|
|
841
|
+
agent_name?: string;
|
|
842
|
+
}
|
|
843
|
+
interface AgentSession {
|
|
844
|
+
session_id: string;
|
|
845
|
+
workspace: {
|
|
846
|
+
slug: string;
|
|
847
|
+
name: string;
|
|
848
|
+
};
|
|
849
|
+
thread?: {
|
|
850
|
+
slug: string;
|
|
851
|
+
name: string;
|
|
852
|
+
} | null;
|
|
853
|
+
agent: {
|
|
854
|
+
name: string;
|
|
855
|
+
provider: string;
|
|
856
|
+
model: string | null;
|
|
857
|
+
};
|
|
858
|
+
created_at: string;
|
|
859
|
+
}
|
|
860
|
+
interface AgentChatOptions {
|
|
861
|
+
message: string;
|
|
862
|
+
}
|
|
863
|
+
interface AgentChatResponse {
|
|
864
|
+
id: string;
|
|
865
|
+
session_id: string;
|
|
866
|
+
text: string;
|
|
867
|
+
thoughts: string[];
|
|
868
|
+
message_count: number;
|
|
869
|
+
}
|
|
870
|
+
interface AgentSessionInfo extends AgentSession {
|
|
871
|
+
message_count: number;
|
|
872
|
+
last_message_at: string | null;
|
|
873
|
+
}
|
|
874
|
+
interface StreamChunkEvent {
|
|
875
|
+
type: 'agentThought' | 'textResponse' | 'close' | 'error';
|
|
876
|
+
data: any;
|
|
877
|
+
}
|
|
878
|
+
declare class AgentModule {
|
|
879
|
+
private httpClient;
|
|
880
|
+
constructor(httpClient: HttpClient);
|
|
881
|
+
/**
|
|
882
|
+
* Create a new agent session
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```typescript
|
|
886
|
+
* const session = await sdk.agent.createSession({
|
|
887
|
+
* workspace_slug: 'my-workspace',
|
|
888
|
+
* agent_name: '@agent'
|
|
889
|
+
* });
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
createSession(options?: AgentSessionOptions): Promise<AgentSession>;
|
|
893
|
+
/**
|
|
894
|
+
* Chat within a session (synchronous)
|
|
895
|
+
*
|
|
896
|
+
* @example
|
|
897
|
+
* ```typescript
|
|
898
|
+
* const response = await sdk.agent.chat(sessionId, 'Hello agent!');
|
|
899
|
+
* console.log(response.text);
|
|
900
|
+
* ```
|
|
901
|
+
*/
|
|
902
|
+
chat(sessionId: string, message: string): Promise<AgentChatResponse>;
|
|
903
|
+
/**
|
|
904
|
+
* Stream chat within a session
|
|
905
|
+
* Returns an async iterator for SSE events
|
|
906
|
+
*
|
|
907
|
+
* @example
|
|
908
|
+
* ```typescript
|
|
909
|
+
* for await (const event of sdk.agent.streamChat(sessionId, 'Tell me a story')) {
|
|
910
|
+
* if (event.type === 'agentThought') {
|
|
911
|
+
* console.log('Thinking:', event.data.thought);
|
|
912
|
+
* } else if (event.type === 'textResponse') {
|
|
913
|
+
* console.log('Response:', event.data.textResponse);
|
|
914
|
+
* }
|
|
915
|
+
* }
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
streamChat(sessionId: string, message: string): AsyncIterableIterator<StreamChunkEvent>;
|
|
919
|
+
/**
|
|
920
|
+
* Get session information
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* const info = await sdk.agent.getSession(sessionId);
|
|
925
|
+
* console.log(`Messages sent: ${info.message_count}`);
|
|
926
|
+
* ```
|
|
927
|
+
*/
|
|
928
|
+
getSession(sessionId: string): Promise<AgentSessionInfo>;
|
|
929
|
+
/**
|
|
930
|
+
* Close and delete a session
|
|
931
|
+
* Sessions auto-expire after 1 hour, but you can close them manually
|
|
932
|
+
*
|
|
933
|
+
* @example
|
|
934
|
+
* ```typescript
|
|
935
|
+
* await sdk.agent.closeSession(sessionId);
|
|
936
|
+
* ```
|
|
937
|
+
*/
|
|
938
|
+
closeSession(sessionId: string): Promise<void>;
|
|
939
|
+
/**
|
|
940
|
+
* Helper: Create session and send first message in one call
|
|
941
|
+
* This is the simplest way to start chatting with an agent
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* const { session, response } = await sdk.agent.startChat('Hello agent!');
|
|
946
|
+
* console.log(response.text);
|
|
947
|
+
*
|
|
948
|
+
* // Continue chatting in the same session
|
|
949
|
+
* const reply = await sdk.agent.chat(session.session_id, 'Tell me more');
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
startChat(message: string, options?: AgentSessionOptions): Promise<{
|
|
953
|
+
session: AgentSession;
|
|
954
|
+
response: AgentChatResponse;
|
|
955
|
+
}>;
|
|
956
|
+
}
|
|
957
|
+
|
|
804
958
|
/**
|
|
805
959
|
* RealtimeX Local App SDK
|
|
806
960
|
*
|
|
@@ -817,11 +971,13 @@ declare class RealtimeXSDK {
|
|
|
817
971
|
llm: LLMModule;
|
|
818
972
|
tts: TTSModule;
|
|
819
973
|
stt: STTModule;
|
|
974
|
+
agent: AgentModule;
|
|
820
975
|
readonly appId: string;
|
|
821
976
|
readonly appName: string | undefined;
|
|
822
977
|
readonly apiKey: string | undefined;
|
|
823
978
|
private readonly realtimexUrl;
|
|
824
979
|
private readonly permissions;
|
|
980
|
+
private httpClient;
|
|
825
981
|
private static DEFAULT_REALTIMEX_URL;
|
|
826
982
|
constructor(config?: SDKConfig);
|
|
827
983
|
/**
|
|
@@ -850,4 +1006,4 @@ declare class RealtimeXSDK {
|
|
|
850
1006
|
getAppDataDir(): Promise<string>;
|
|
851
1007
|
}
|
|
852
1008
|
|
|
853
|
-
export { ActivitiesModule, type Activity, type Agent, ApiModule, type ChatMessage, type ChatOptions, type ChatResponse, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTResponse, type StreamChunk, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace };
|
|
1009
|
+
export { ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, type ChatMessage, type ChatOptions, type ChatResponse, type EmbedOptions, type EmbedResponse, LLMModule, LLMPermissionError, LLMProviderError, PermissionDeniedError, PermissionRequiredError, PortModule, type Provider, type ProvidersResponse, RealtimeXSDK, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ActivitiesModule: () => ActivitiesModule,
|
|
34
|
+
AgentModule: () => AgentModule,
|
|
34
35
|
ApiModule: () => ApiModule,
|
|
35
36
|
LLMModule: () => LLMModule,
|
|
36
37
|
LLMPermissionError: () => LLMPermissionError,
|
|
@@ -1170,18 +1171,18 @@ var TTSModule = class {
|
|
|
1170
1171
|
// src/modules/stt.ts
|
|
1171
1172
|
var STTModule = class extends ApiModule {
|
|
1172
1173
|
/**
|
|
1173
|
-
* Get available STT models.
|
|
1174
|
-
* @returns Promise resolving to list of
|
|
1174
|
+
* Get available STT providers and their models.
|
|
1175
|
+
* @returns Promise resolving to list of providers
|
|
1175
1176
|
*/
|
|
1176
|
-
async
|
|
1177
|
+
async listProviders() {
|
|
1177
1178
|
try {
|
|
1178
|
-
const response = await this.apiCall("GET", "/sdk/stt/
|
|
1179
|
+
const response = await this.apiCall("GET", "/sdk/stt/providers");
|
|
1179
1180
|
if (!response.success) {
|
|
1180
|
-
throw new Error(response.error || "Failed to fetch
|
|
1181
|
+
throw new Error(response.error || "Failed to fetch providers");
|
|
1181
1182
|
}
|
|
1182
|
-
return response.
|
|
1183
|
+
return response.providers;
|
|
1183
1184
|
} catch (error) {
|
|
1184
|
-
throw new Error(`STT
|
|
1185
|
+
throw new Error(`STT providers fetch failed: ${error.message}`);
|
|
1185
1186
|
}
|
|
1186
1187
|
}
|
|
1187
1188
|
/**
|
|
@@ -1202,6 +1203,218 @@ var STTModule = class extends ApiModule {
|
|
|
1202
1203
|
}
|
|
1203
1204
|
};
|
|
1204
1205
|
|
|
1206
|
+
// src/modules/agent.ts
|
|
1207
|
+
var AgentModule = class {
|
|
1208
|
+
constructor(httpClient) {
|
|
1209
|
+
this.httpClient = httpClient;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Create a new agent session
|
|
1213
|
+
*
|
|
1214
|
+
* @example
|
|
1215
|
+
* ```typescript
|
|
1216
|
+
* const session = await sdk.agent.createSession({
|
|
1217
|
+
* workspace_slug: 'my-workspace',
|
|
1218
|
+
* agent_name: '@agent'
|
|
1219
|
+
* });
|
|
1220
|
+
* ```
|
|
1221
|
+
*/
|
|
1222
|
+
async createSession(options) {
|
|
1223
|
+
const response = await this.httpClient.fetch("/sdk/agent/session", {
|
|
1224
|
+
method: "POST",
|
|
1225
|
+
body: JSON.stringify(options || {})
|
|
1226
|
+
});
|
|
1227
|
+
const data = await response.json();
|
|
1228
|
+
if (!response.ok) {
|
|
1229
|
+
throw new Error(data.error || "Failed to create session");
|
|
1230
|
+
}
|
|
1231
|
+
return data.session;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Chat within a session (synchronous)
|
|
1235
|
+
*
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```typescript
|
|
1238
|
+
* const response = await sdk.agent.chat(sessionId, 'Hello agent!');
|
|
1239
|
+
* console.log(response.text);
|
|
1240
|
+
* ```
|
|
1241
|
+
*/
|
|
1242
|
+
async chat(sessionId, message) {
|
|
1243
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}/chat`, {
|
|
1244
|
+
method: "POST",
|
|
1245
|
+
body: JSON.stringify({ message })
|
|
1246
|
+
});
|
|
1247
|
+
const data = await response.json();
|
|
1248
|
+
if (!response.ok) {
|
|
1249
|
+
throw new Error(data.error || "Chat request failed");
|
|
1250
|
+
}
|
|
1251
|
+
return data.response;
|
|
1252
|
+
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Stream chat within a session
|
|
1255
|
+
* Returns an async iterator for SSE events
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```typescript
|
|
1259
|
+
* for await (const event of sdk.agent.streamChat(sessionId, 'Tell me a story')) {
|
|
1260
|
+
* if (event.type === 'agentThought') {
|
|
1261
|
+
* console.log('Thinking:', event.data.thought);
|
|
1262
|
+
* } else if (event.type === 'textResponse') {
|
|
1263
|
+
* console.log('Response:', event.data.textResponse);
|
|
1264
|
+
* }
|
|
1265
|
+
* }
|
|
1266
|
+
* ```
|
|
1267
|
+
*/
|
|
1268
|
+
async *streamChat(sessionId, message) {
|
|
1269
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}/chat/stream`, {
|
|
1270
|
+
method: "POST",
|
|
1271
|
+
body: JSON.stringify({ message })
|
|
1272
|
+
});
|
|
1273
|
+
if (!response.ok) {
|
|
1274
|
+
const data = await response.json();
|
|
1275
|
+
throw new Error(data.error || "Stream request failed");
|
|
1276
|
+
}
|
|
1277
|
+
if (!response.body) {
|
|
1278
|
+
throw new Error("Response body is null");
|
|
1279
|
+
}
|
|
1280
|
+
const reader = response.body.getReader();
|
|
1281
|
+
const decoder = new TextDecoder();
|
|
1282
|
+
let buffer = "";
|
|
1283
|
+
try {
|
|
1284
|
+
while (true) {
|
|
1285
|
+
const { done, value } = await reader.read();
|
|
1286
|
+
if (done) break;
|
|
1287
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1288
|
+
const lines = buffer.split("\n");
|
|
1289
|
+
buffer = lines.pop() || "";
|
|
1290
|
+
for (const line of lines) {
|
|
1291
|
+
if (line.startsWith("data: ")) {
|
|
1292
|
+
const data = JSON.parse(line.slice(6));
|
|
1293
|
+
yield {
|
|
1294
|
+
type: data.type,
|
|
1295
|
+
data
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
} finally {
|
|
1301
|
+
reader.releaseLock();
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Get session information
|
|
1306
|
+
*
|
|
1307
|
+
* @example
|
|
1308
|
+
* ```typescript
|
|
1309
|
+
* const info = await sdk.agent.getSession(sessionId);
|
|
1310
|
+
* console.log(`Messages sent: ${info.message_count}`);
|
|
1311
|
+
* ```
|
|
1312
|
+
*/
|
|
1313
|
+
async getSession(sessionId) {
|
|
1314
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}`, {
|
|
1315
|
+
method: "GET"
|
|
1316
|
+
});
|
|
1317
|
+
const data = await response.json();
|
|
1318
|
+
if (!response.ok) {
|
|
1319
|
+
throw new Error(data.error || "Failed to get session info");
|
|
1320
|
+
}
|
|
1321
|
+
return data.session;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Close and delete a session
|
|
1325
|
+
* Sessions auto-expire after 1 hour, but you can close them manually
|
|
1326
|
+
*
|
|
1327
|
+
* @example
|
|
1328
|
+
* ```typescript
|
|
1329
|
+
* await sdk.agent.closeSession(sessionId);
|
|
1330
|
+
* ```
|
|
1331
|
+
*/
|
|
1332
|
+
async closeSession(sessionId) {
|
|
1333
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}`, {
|
|
1334
|
+
method: "DELETE"
|
|
1335
|
+
});
|
|
1336
|
+
const data = await response.json();
|
|
1337
|
+
if (!response.ok) {
|
|
1338
|
+
throw new Error(data.error || "Failed to close session");
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Helper: Create session and send first message in one call
|
|
1343
|
+
* This is the simplest way to start chatting with an agent
|
|
1344
|
+
*
|
|
1345
|
+
* @example
|
|
1346
|
+
* ```typescript
|
|
1347
|
+
* const { session, response } = await sdk.agent.startChat('Hello agent!');
|
|
1348
|
+
* console.log(response.text);
|
|
1349
|
+
*
|
|
1350
|
+
* // Continue chatting in the same session
|
|
1351
|
+
* const reply = await sdk.agent.chat(session.session_id, 'Tell me more');
|
|
1352
|
+
* ```
|
|
1353
|
+
*/
|
|
1354
|
+
async startChat(message, options) {
|
|
1355
|
+
const session = await this.createSession(options);
|
|
1356
|
+
const response = await this.chat(session.session_id, message);
|
|
1357
|
+
return { session, response };
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1361
|
+
// src/modules/http.ts
|
|
1362
|
+
var HttpClient = class {
|
|
1363
|
+
constructor(baseUrl, appId, apiKey) {
|
|
1364
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
1365
|
+
this.appId = appId;
|
|
1366
|
+
this.apiKey = apiKey;
|
|
1367
|
+
}
|
|
1368
|
+
getAppHeaders() {
|
|
1369
|
+
const headers = {
|
|
1370
|
+
"Content-Type": "application/json"
|
|
1371
|
+
};
|
|
1372
|
+
if (this.appId) headers["x-app-id"] = this.appId;
|
|
1373
|
+
if (this.apiKey) headers["x-api-key"] = this.apiKey;
|
|
1374
|
+
return headers;
|
|
1375
|
+
}
|
|
1376
|
+
async getAccessToken() {
|
|
1377
|
+
if (this.accessToken) return this.accessToken;
|
|
1378
|
+
try {
|
|
1379
|
+
const res = await fetch(`${this.baseUrl}/sdk/auth/token`, {
|
|
1380
|
+
headers: this.getAppHeaders()
|
|
1381
|
+
});
|
|
1382
|
+
const data = await res.json();
|
|
1383
|
+
if (res.ok && data.token) {
|
|
1384
|
+
this.accessToken = data.token;
|
|
1385
|
+
return data.token;
|
|
1386
|
+
}
|
|
1387
|
+
} catch (e) {
|
|
1388
|
+
}
|
|
1389
|
+
return "";
|
|
1390
|
+
}
|
|
1391
|
+
async fetch(endpoint, options = {}) {
|
|
1392
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
1393
|
+
let token = await this.getAccessToken();
|
|
1394
|
+
const makeRequest = (authToken) => {
|
|
1395
|
+
const headers = {
|
|
1396
|
+
...this.getAppHeaders(),
|
|
1397
|
+
...options.headers || {}
|
|
1398
|
+
};
|
|
1399
|
+
if (authToken) {
|
|
1400
|
+
headers["Authorization"] = `Bearer ${authToken}`;
|
|
1401
|
+
}
|
|
1402
|
+
return fetch(url, { ...options, headers });
|
|
1403
|
+
};
|
|
1404
|
+
let response = await makeRequest(token);
|
|
1405
|
+
if (response.status === 401) {
|
|
1406
|
+
console.log("[RealtimeX SDK] 401 Unauthorized, refreshing access token...");
|
|
1407
|
+
this.accessToken = void 0;
|
|
1408
|
+
const newToken = await this.getAccessToken();
|
|
1409
|
+
if (newToken && newToken !== token) {
|
|
1410
|
+
console.log("[RealtimeX SDK] Retrying request with new token");
|
|
1411
|
+
response = await makeRequest(newToken);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
return response;
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1205
1418
|
// src/index.ts
|
|
1206
1419
|
var _RealtimeXSDK = class _RealtimeXSDK {
|
|
1207
1420
|
constructor(config = {}) {
|
|
@@ -1213,6 +1426,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
1213
1426
|
this.apiKey = config.realtimex?.apiKey || envApiKey;
|
|
1214
1427
|
this.permissions = config.permissions || [];
|
|
1215
1428
|
this.realtimexUrl = config.realtimex?.url || _RealtimeXSDK.DEFAULT_REALTIMEX_URL;
|
|
1429
|
+
this.httpClient = new HttpClient(this.realtimexUrl, this.appId, this.apiKey);
|
|
1216
1430
|
this.activities = new ActivitiesModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1217
1431
|
this.webhook = new WebhookModule(this.realtimexUrl, this.appName, this.appId, this.apiKey);
|
|
1218
1432
|
this.api = new ApiModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
@@ -1221,6 +1435,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
1221
1435
|
this.llm = new LLMModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1222
1436
|
this.tts = new TTSModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1223
1437
|
this.stt = new STTModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1438
|
+
this.agent = new AgentModule(this.httpClient);
|
|
1224
1439
|
if (this.permissions.length > 0 && this.appId && !this.apiKey) {
|
|
1225
1440
|
this.register().catch((err) => {
|
|
1226
1441
|
console.error("[RealtimeX SDK] Auto-registration failed:", err.message);
|
|
@@ -1323,6 +1538,7 @@ var RealtimeXSDK = _RealtimeXSDK;
|
|
|
1323
1538
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1324
1539
|
0 && (module.exports = {
|
|
1325
1540
|
ActivitiesModule,
|
|
1541
|
+
AgentModule,
|
|
1326
1542
|
ApiModule,
|
|
1327
1543
|
LLMModule,
|
|
1328
1544
|
LLMPermissionError,
|
package/dist/index.mjs
CHANGED
|
@@ -1121,18 +1121,18 @@ var TTSModule = class {
|
|
|
1121
1121
|
// src/modules/stt.ts
|
|
1122
1122
|
var STTModule = class extends ApiModule {
|
|
1123
1123
|
/**
|
|
1124
|
-
* Get available STT models.
|
|
1125
|
-
* @returns Promise resolving to list of
|
|
1124
|
+
* Get available STT providers and their models.
|
|
1125
|
+
* @returns Promise resolving to list of providers
|
|
1126
1126
|
*/
|
|
1127
|
-
async
|
|
1127
|
+
async listProviders() {
|
|
1128
1128
|
try {
|
|
1129
|
-
const response = await this.apiCall("GET", "/sdk/stt/
|
|
1129
|
+
const response = await this.apiCall("GET", "/sdk/stt/providers");
|
|
1130
1130
|
if (!response.success) {
|
|
1131
|
-
throw new Error(response.error || "Failed to fetch
|
|
1131
|
+
throw new Error(response.error || "Failed to fetch providers");
|
|
1132
1132
|
}
|
|
1133
|
-
return response.
|
|
1133
|
+
return response.providers;
|
|
1134
1134
|
} catch (error) {
|
|
1135
|
-
throw new Error(`STT
|
|
1135
|
+
throw new Error(`STT providers fetch failed: ${error.message}`);
|
|
1136
1136
|
}
|
|
1137
1137
|
}
|
|
1138
1138
|
/**
|
|
@@ -1153,6 +1153,218 @@ var STTModule = class extends ApiModule {
|
|
|
1153
1153
|
}
|
|
1154
1154
|
};
|
|
1155
1155
|
|
|
1156
|
+
// src/modules/agent.ts
|
|
1157
|
+
var AgentModule = class {
|
|
1158
|
+
constructor(httpClient) {
|
|
1159
|
+
this.httpClient = httpClient;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Create a new agent session
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* const session = await sdk.agent.createSession({
|
|
1167
|
+
* workspace_slug: 'my-workspace',
|
|
1168
|
+
* agent_name: '@agent'
|
|
1169
|
+
* });
|
|
1170
|
+
* ```
|
|
1171
|
+
*/
|
|
1172
|
+
async createSession(options) {
|
|
1173
|
+
const response = await this.httpClient.fetch("/sdk/agent/session", {
|
|
1174
|
+
method: "POST",
|
|
1175
|
+
body: JSON.stringify(options || {})
|
|
1176
|
+
});
|
|
1177
|
+
const data = await response.json();
|
|
1178
|
+
if (!response.ok) {
|
|
1179
|
+
throw new Error(data.error || "Failed to create session");
|
|
1180
|
+
}
|
|
1181
|
+
return data.session;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Chat within a session (synchronous)
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```typescript
|
|
1188
|
+
* const response = await sdk.agent.chat(sessionId, 'Hello agent!');
|
|
1189
|
+
* console.log(response.text);
|
|
1190
|
+
* ```
|
|
1191
|
+
*/
|
|
1192
|
+
async chat(sessionId, message) {
|
|
1193
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}/chat`, {
|
|
1194
|
+
method: "POST",
|
|
1195
|
+
body: JSON.stringify({ message })
|
|
1196
|
+
});
|
|
1197
|
+
const data = await response.json();
|
|
1198
|
+
if (!response.ok) {
|
|
1199
|
+
throw new Error(data.error || "Chat request failed");
|
|
1200
|
+
}
|
|
1201
|
+
return data.response;
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Stream chat within a session
|
|
1205
|
+
* Returns an async iterator for SSE events
|
|
1206
|
+
*
|
|
1207
|
+
* @example
|
|
1208
|
+
* ```typescript
|
|
1209
|
+
* for await (const event of sdk.agent.streamChat(sessionId, 'Tell me a story')) {
|
|
1210
|
+
* if (event.type === 'agentThought') {
|
|
1211
|
+
* console.log('Thinking:', event.data.thought);
|
|
1212
|
+
* } else if (event.type === 'textResponse') {
|
|
1213
|
+
* console.log('Response:', event.data.textResponse);
|
|
1214
|
+
* }
|
|
1215
|
+
* }
|
|
1216
|
+
* ```
|
|
1217
|
+
*/
|
|
1218
|
+
async *streamChat(sessionId, message) {
|
|
1219
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}/chat/stream`, {
|
|
1220
|
+
method: "POST",
|
|
1221
|
+
body: JSON.stringify({ message })
|
|
1222
|
+
});
|
|
1223
|
+
if (!response.ok) {
|
|
1224
|
+
const data = await response.json();
|
|
1225
|
+
throw new Error(data.error || "Stream request failed");
|
|
1226
|
+
}
|
|
1227
|
+
if (!response.body) {
|
|
1228
|
+
throw new Error("Response body is null");
|
|
1229
|
+
}
|
|
1230
|
+
const reader = response.body.getReader();
|
|
1231
|
+
const decoder = new TextDecoder();
|
|
1232
|
+
let buffer = "";
|
|
1233
|
+
try {
|
|
1234
|
+
while (true) {
|
|
1235
|
+
const { done, value } = await reader.read();
|
|
1236
|
+
if (done) break;
|
|
1237
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1238
|
+
const lines = buffer.split("\n");
|
|
1239
|
+
buffer = lines.pop() || "";
|
|
1240
|
+
for (const line of lines) {
|
|
1241
|
+
if (line.startsWith("data: ")) {
|
|
1242
|
+
const data = JSON.parse(line.slice(6));
|
|
1243
|
+
yield {
|
|
1244
|
+
type: data.type,
|
|
1245
|
+
data
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
} finally {
|
|
1251
|
+
reader.releaseLock();
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Get session information
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```typescript
|
|
1259
|
+
* const info = await sdk.agent.getSession(sessionId);
|
|
1260
|
+
* console.log(`Messages sent: ${info.message_count}`);
|
|
1261
|
+
* ```
|
|
1262
|
+
*/
|
|
1263
|
+
async getSession(sessionId) {
|
|
1264
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}`, {
|
|
1265
|
+
method: "GET"
|
|
1266
|
+
});
|
|
1267
|
+
const data = await response.json();
|
|
1268
|
+
if (!response.ok) {
|
|
1269
|
+
throw new Error(data.error || "Failed to get session info");
|
|
1270
|
+
}
|
|
1271
|
+
return data.session;
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Close and delete a session
|
|
1275
|
+
* Sessions auto-expire after 1 hour, but you can close them manually
|
|
1276
|
+
*
|
|
1277
|
+
* @example
|
|
1278
|
+
* ```typescript
|
|
1279
|
+
* await sdk.agent.closeSession(sessionId);
|
|
1280
|
+
* ```
|
|
1281
|
+
*/
|
|
1282
|
+
async closeSession(sessionId) {
|
|
1283
|
+
const response = await this.httpClient.fetch(`/sdk/agent/session/${sessionId}`, {
|
|
1284
|
+
method: "DELETE"
|
|
1285
|
+
});
|
|
1286
|
+
const data = await response.json();
|
|
1287
|
+
if (!response.ok) {
|
|
1288
|
+
throw new Error(data.error || "Failed to close session");
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Helper: Create session and send first message in one call
|
|
1293
|
+
* This is the simplest way to start chatting with an agent
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* ```typescript
|
|
1297
|
+
* const { session, response } = await sdk.agent.startChat('Hello agent!');
|
|
1298
|
+
* console.log(response.text);
|
|
1299
|
+
*
|
|
1300
|
+
* // Continue chatting in the same session
|
|
1301
|
+
* const reply = await sdk.agent.chat(session.session_id, 'Tell me more');
|
|
1302
|
+
* ```
|
|
1303
|
+
*/
|
|
1304
|
+
async startChat(message, options) {
|
|
1305
|
+
const session = await this.createSession(options);
|
|
1306
|
+
const response = await this.chat(session.session_id, message);
|
|
1307
|
+
return { session, response };
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
// src/modules/http.ts
|
|
1312
|
+
var HttpClient = class {
|
|
1313
|
+
constructor(baseUrl, appId, apiKey) {
|
|
1314
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
1315
|
+
this.appId = appId;
|
|
1316
|
+
this.apiKey = apiKey;
|
|
1317
|
+
}
|
|
1318
|
+
getAppHeaders() {
|
|
1319
|
+
const headers = {
|
|
1320
|
+
"Content-Type": "application/json"
|
|
1321
|
+
};
|
|
1322
|
+
if (this.appId) headers["x-app-id"] = this.appId;
|
|
1323
|
+
if (this.apiKey) headers["x-api-key"] = this.apiKey;
|
|
1324
|
+
return headers;
|
|
1325
|
+
}
|
|
1326
|
+
async getAccessToken() {
|
|
1327
|
+
if (this.accessToken) return this.accessToken;
|
|
1328
|
+
try {
|
|
1329
|
+
const res = await fetch(`${this.baseUrl}/sdk/auth/token`, {
|
|
1330
|
+
headers: this.getAppHeaders()
|
|
1331
|
+
});
|
|
1332
|
+
const data = await res.json();
|
|
1333
|
+
if (res.ok && data.token) {
|
|
1334
|
+
this.accessToken = data.token;
|
|
1335
|
+
return data.token;
|
|
1336
|
+
}
|
|
1337
|
+
} catch (e) {
|
|
1338
|
+
}
|
|
1339
|
+
return "";
|
|
1340
|
+
}
|
|
1341
|
+
async fetch(endpoint, options = {}) {
|
|
1342
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
1343
|
+
let token = await this.getAccessToken();
|
|
1344
|
+
const makeRequest = (authToken) => {
|
|
1345
|
+
const headers = {
|
|
1346
|
+
...this.getAppHeaders(),
|
|
1347
|
+
...options.headers || {}
|
|
1348
|
+
};
|
|
1349
|
+
if (authToken) {
|
|
1350
|
+
headers["Authorization"] = `Bearer ${authToken}`;
|
|
1351
|
+
}
|
|
1352
|
+
return fetch(url, { ...options, headers });
|
|
1353
|
+
};
|
|
1354
|
+
let response = await makeRequest(token);
|
|
1355
|
+
if (response.status === 401) {
|
|
1356
|
+
console.log("[RealtimeX SDK] 401 Unauthorized, refreshing access token...");
|
|
1357
|
+
this.accessToken = void 0;
|
|
1358
|
+
const newToken = await this.getAccessToken();
|
|
1359
|
+
if (newToken && newToken !== token) {
|
|
1360
|
+
console.log("[RealtimeX SDK] Retrying request with new token");
|
|
1361
|
+
response = await makeRequest(newToken);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
return response;
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1156
1368
|
// src/index.ts
|
|
1157
1369
|
var _RealtimeXSDK = class _RealtimeXSDK {
|
|
1158
1370
|
constructor(config = {}) {
|
|
@@ -1164,6 +1376,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
1164
1376
|
this.apiKey = config.realtimex?.apiKey || envApiKey;
|
|
1165
1377
|
this.permissions = config.permissions || [];
|
|
1166
1378
|
this.realtimexUrl = config.realtimex?.url || _RealtimeXSDK.DEFAULT_REALTIMEX_URL;
|
|
1379
|
+
this.httpClient = new HttpClient(this.realtimexUrl, this.appId, this.apiKey);
|
|
1167
1380
|
this.activities = new ActivitiesModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1168
1381
|
this.webhook = new WebhookModule(this.realtimexUrl, this.appName, this.appId, this.apiKey);
|
|
1169
1382
|
this.api = new ApiModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
@@ -1172,6 +1385,7 @@ var _RealtimeXSDK = class _RealtimeXSDK {
|
|
|
1172
1385
|
this.llm = new LLMModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1173
1386
|
this.tts = new TTSModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1174
1387
|
this.stt = new STTModule(this.realtimexUrl, this.appId, this.appName, this.apiKey);
|
|
1388
|
+
this.agent = new AgentModule(this.httpClient);
|
|
1175
1389
|
if (this.permissions.length > 0 && this.appId && !this.apiKey) {
|
|
1176
1390
|
this.register().catch((err) => {
|
|
1177
1391
|
console.error("[RealtimeX SDK] Auto-registration failed:", err.message);
|
|
@@ -1273,6 +1487,7 @@ _RealtimeXSDK.DEFAULT_REALTIMEX_URL = "http://localhost:3001";
|
|
|
1273
1487
|
var RealtimeXSDK = _RealtimeXSDK;
|
|
1274
1488
|
export {
|
|
1275
1489
|
ActivitiesModule,
|
|
1490
|
+
AgentModule,
|
|
1276
1491
|
ApiModule,
|
|
1277
1492
|
LLMModule,
|
|
1278
1493
|
LLMPermissionError,
|