@ideascol/agents-generator-sdk 0.0.3-rc1 → 0.0.3-rc3

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.js CHANGED
@@ -685,6 +685,7 @@ __export(exports_src, {
685
685
  RootService: () => RootService,
686
686
  OpenAPI: () => OpenAPI,
687
687
  McpServersService: () => McpServersService,
688
+ ConversationsServiceStream: () => ConversationsServiceStream,
688
689
  ConversationsService: () => ConversationsService,
689
690
  CancelablePromise: () => CancelablePromise,
690
691
  CancelError: () => CancelError,
@@ -695,3 +696,100 @@ module.exports = __toCommonJS(exports_src);
695
696
 
696
697
  // src/lib/index.ts
697
698
  init_agents_generator();
699
+ init_agents_generator();
700
+
701
+ class ConversationsServiceStream extends ConversationsService {
702
+ constructor() {
703
+ super();
704
+ }
705
+ static addMessageConversationsConversationIdMessagesPostStream(conversationId, requestBody, callbacks) {
706
+ const apiUrl = OpenAPI.BASE;
707
+ const url = `${apiUrl}/conversations/${conversationId}/messages`;
708
+ const controller = new AbortController;
709
+ const headers = new Headers({
710
+ "Content-Type": "application/json",
711
+ Accept: "text/event-stream"
712
+ });
713
+ if (OpenAPI.TOKEN) {
714
+ if (typeof OpenAPI.TOKEN === "function") {
715
+ OpenAPI.TOKEN({ url, method: "POST", body: requestBody }).then((token) => {
716
+ headers.append("Authorization", `Bearer ${token}`);
717
+ }).catch((error) => {
718
+ if (callbacks.onError) {
719
+ callbacks.onError(new Error(`Failed to get auth token: ${error.message}`));
720
+ }
721
+ });
722
+ } else {
723
+ headers.append("Authorization", `Bearer ${OpenAPI.TOKEN}`);
724
+ }
725
+ }
726
+ fetch(url, {
727
+ method: "POST",
728
+ headers,
729
+ body: JSON.stringify(requestBody),
730
+ credentials: OpenAPI.WITH_CREDENTIALS ? OpenAPI.CREDENTIALS : undefined,
731
+ signal: controller.signal
732
+ }).then((response) => {
733
+ if (!response.ok) {
734
+ throw new Error(`Error: ${response.status} - ${response.statusText}`);
735
+ }
736
+ if (!response.body) {
737
+ throw new Error("ReadableStream not supported");
738
+ }
739
+ const reader = response.body.getReader();
740
+ const decoder = new TextDecoder;
741
+ let buffer = "";
742
+ let fullMessage = "";
743
+ function processStream() {
744
+ reader.read().then(({ done, value }) => {
745
+ if (done) {
746
+ console.log("Stream completado");
747
+ return;
748
+ }
749
+ const chunk = decoder.decode(value, { stream: true });
750
+ buffer += chunk;
751
+ console.log("Chunk recibido:", chunk);
752
+ let eventEnd = buffer.indexOf(`
753
+
754
+ `);
755
+ while (eventEnd > -1) {
756
+ const eventData = buffer.substring(0, eventEnd);
757
+ buffer = buffer.substring(eventEnd + 2);
758
+ if (eventData.startsWith("data: ")) {
759
+ const jsonStr = eventData.substring(6);
760
+ try {
761
+ const data = JSON.parse(jsonStr);
762
+ console.log("Evento SSE recibido:", data);
763
+ if (data.type === "message" && data.content && callbacks.onMessage) {
764
+ fullMessage = data.content;
765
+ callbacks.onMessage(fullMessage);
766
+ } else if (data.type === "done" && data.message_id && callbacks.onDone) {
767
+ callbacks.onDone(data.message_id);
768
+ }
769
+ } catch (e) {
770
+ console.error("Error al parsear JSON del evento:", e);
771
+ if (callbacks.onError) {
772
+ callbacks.onError(new Error(`Error parsing SSE event: ${e}`));
773
+ }
774
+ }
775
+ }
776
+ eventEnd = buffer.indexOf(`
777
+
778
+ `);
779
+ }
780
+ processStream();
781
+ }).catch((error) => {
782
+ if (callbacks.onError) {
783
+ callbacks.onError(error);
784
+ }
785
+ });
786
+ }
787
+ processStream();
788
+ }).catch((error) => {
789
+ if (callbacks.onError) {
790
+ callbacks.onError(error);
791
+ }
792
+ });
793
+ return () => controller.abort();
794
+ }
795
+ }
@@ -1,5 +1,4 @@
1
1
  export type MessageCreate = {
2
2
  content: string;
3
3
  metadata?: (Record<string, any> | null);
4
- stream?: boolean;
5
4
  };
@@ -50,5 +50,9 @@ export declare class ConversationsService {
50
50
  * @returns any Successful response
51
51
  * @throws ApiError
52
52
  */
53
- static addMessageConversationsConversationIdMessagesPost(conversationId: string, requestBody: MessageCreate, accept?: string): CancelablePromise<Record<string, any>>;
53
+ static addMessageConversationsConversationIdMessagesPost(conversationId: string, requestBody: MessageCreate, accept?: string): CancelablePromise<{
54
+ status: string;
55
+ message: string;
56
+ message_id?: string;
57
+ }>;
54
58
  }
@@ -1 +1,23 @@
1
- export * from './clients/agents-generator';
1
+ import { ConversationsService, MessageCreate } from "./clients/agents-generator";
2
+ export * from "./clients/agents-generator";
3
+ export interface StreamEvent {
4
+ type: string;
5
+ content?: string;
6
+ message_id?: string;
7
+ }
8
+ export interface StreamCallbacks {
9
+ onMessage?: (content: string) => void;
10
+ onDone?: (messageId: string) => void;
11
+ onError?: (error: Error) => void;
12
+ }
13
+ export declare class ConversationsServiceStream extends ConversationsService {
14
+ constructor();
15
+ /**
16
+ * Add Message with SSE streaming support
17
+ * @param conversationId The ID of the conversation
18
+ * @param requestBody The message data to send
19
+ * @param callbacks Callbacks for handling streaming events
20
+ * @returns A function to abort the stream
21
+ */
22
+ static addMessageConversationsConversationIdMessagesPostStream(conversationId: string, requestBody: MessageCreate, callbacks: StreamCallbacks): () => void;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideascol/agents-generator-sdk",
3
- "version": "0.0.3-rc1",
3
+ "version": "0.0.3-rc3",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "bun test",