@qelos/sdk 3.11.3 → 3.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ import BaseSDK from '../base-sdk';
2
+ import { QelosSDKOptions } from '../types';
3
+ import { IChatCompletionOptions, IChatCompletionResponse, ISSEStreamProcessor } from '../ai';
4
+ export default class ChatSDK extends BaseSDK {
5
+ private relativePath;
6
+ constructor(options: QelosSDKOptions);
7
+ /**
8
+ * Create a chat completion without a thread
9
+ */
10
+ chat(integrationId: string, options: IChatCompletionOptions): Promise<IChatCompletionResponse>;
11
+ /**
12
+ * Create a chat completion with a thread
13
+ */
14
+ chatInThread(integrationId: string, threadId: string, options: IChatCompletionOptions): Promise<IChatCompletionResponse>;
15
+ /**
16
+ * Create a streaming chat completion without a thread
17
+ * Returns a ReadableStream for Server-Sent Events
18
+ */
19
+ stream(integrationId: string, options: IChatCompletionOptions): Promise<ReadableStream<Uint8Array>>;
20
+ /**
21
+ * Create a streaming chat completion with a thread
22
+ * Returns a ReadableStream for Server-Sent Events
23
+ */
24
+ streamInThread(integrationId: string, threadId: string, options: IChatCompletionOptions): Promise<ReadableStream<Uint8Array>>;
25
+ /**
26
+ * Helper method to parse Server-Sent Events stream
27
+ */
28
+ parseSSEStream(stream: ReadableStream<Uint8Array>): ISSEStreamProcessor;
29
+ }
@@ -0,0 +1,146 @@
1
+ import BaseSDK from '../base-sdk';
2
+ export default class ChatSDK extends BaseSDK {
3
+ relativePath = '/api/ai';
4
+ constructor(options) {
5
+ super(options);
6
+ }
7
+ /**
8
+ * Create a chat completion without a thread
9
+ */
10
+ chat(integrationId, options) {
11
+ const queryParams = this.getQueryParams(options.queryParams || {});
12
+ return this.callJsonApi(`${this.relativePath}/${integrationId}/chat-completion${queryParams}`, {
13
+ method: 'POST',
14
+ headers: { 'content-type': 'application/json' },
15
+ body: JSON.stringify(options)
16
+ });
17
+ }
18
+ /**
19
+ * Create a chat completion with a thread
20
+ */
21
+ chatInThread(integrationId, threadId, options) {
22
+ const queryParams = this.getQueryParams(options.queryParams || {});
23
+ return this.callJsonApi(`${this.relativePath}/${integrationId}/chat-completion/${threadId}${queryParams}`, {
24
+ method: 'POST',
25
+ headers: { 'content-type': 'application/json' },
26
+ body: JSON.stringify(options)
27
+ });
28
+ }
29
+ /**
30
+ * Create a streaming chat completion without a thread
31
+ * Returns a ReadableStream for Server-Sent Events
32
+ */
33
+ async stream(integrationId, options) {
34
+ const queryParams = this.getQueryParams({ ...options.queryParams, stream: true });
35
+ const response = await this.callApi(`${this.relativePath}/${integrationId}/chat-completion${queryParams}`, {
36
+ method: 'POST',
37
+ headers: {
38
+ 'content-type': 'application/json',
39
+ 'accept': 'text/event-stream'
40
+ },
41
+ body: JSON.stringify({ ...options, stream: true })
42
+ });
43
+ if (!response.ok) {
44
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
45
+ }
46
+ return response.body;
47
+ }
48
+ /**
49
+ * Create a streaming chat completion with a thread
50
+ * Returns a ReadableStream for Server-Sent Events
51
+ */
52
+ async streamInThread(integrationId, threadId, options) {
53
+ const queryParams = this.getQueryParams({ ...options.queryParams, stream: true });
54
+ const response = await this.callApi(`${this.relativePath}/${integrationId}/chat-completion/${threadId}${queryParams}`, {
55
+ method: 'POST',
56
+ headers: {
57
+ 'content-type': 'application/json',
58
+ 'accept': 'text/event-stream'
59
+ },
60
+ body: JSON.stringify({ ...options, stream: true })
61
+ });
62
+ if (!response.ok) {
63
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
64
+ }
65
+ return response.body;
66
+ }
67
+ /**
68
+ * Helper method to parse Server-Sent Events stream
69
+ */
70
+ parseSSEStream(stream) {
71
+ const processStream = async (onData) => {
72
+ const reader = stream.getReader();
73
+ const decoder = new TextDecoder();
74
+ let buffer = "";
75
+ try {
76
+ while (true) {
77
+ const { done, value } = await reader.read();
78
+ if (done)
79
+ break;
80
+ buffer += decoder.decode(value, { stream: true });
81
+ let lines = buffer.split(/\r?\n/);
82
+ buffer = lines.pop() || ""; // Keep incomplete line
83
+ for (const line of lines) {
84
+ if (line.startsWith('data: ')) {
85
+ const data = line.slice(6);
86
+ if (data === '[DONE]')
87
+ return;
88
+ try {
89
+ const parsed = JSON.parse(data);
90
+ const shouldContinue = onData(parsed);
91
+ if (shouldContinue === false) {
92
+ return;
93
+ }
94
+ }
95
+ catch (e) {
96
+ // Skip invalid JSON
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ finally {
103
+ reader.releaseLock();
104
+ }
105
+ };
106
+ const processor = {
107
+ async *[Symbol.asyncIterator]() {
108
+ const reader = stream.getReader();
109
+ const decoder = new TextDecoder();
110
+ let buffer = "";
111
+ try {
112
+ while (true) {
113
+ const { done, value } = await reader.read();
114
+ if (done) {
115
+ break;
116
+ }
117
+ buffer += decoder.decode(value, { stream: true });
118
+ let lines = buffer.split(/\r?\n/);
119
+ buffer = lines.pop() || ""; // Keep incomplete line
120
+ for (const line of lines) {
121
+ if (line.startsWith('data: ')) {
122
+ const data = line.slice(6);
123
+ if (data === '[DONE]') {
124
+ return;
125
+ }
126
+ try {
127
+ const parsed = JSON.parse(data);
128
+ yield parsed;
129
+ }
130
+ catch (e) {
131
+ //
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ finally {
138
+ reader.releaseLock();
139
+ }
140
+ },
141
+ processManually: processStream
142
+ };
143
+ return processor;
144
+ }
145
+ }
146
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/ai/chat.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,aAAa,CAAC;AAQlC,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,OAAO;IAClC,YAAY,GAAG,SAAS,CAAC;IAEjC,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,IAAI,CACF,aAAqB,EACrB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AAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;wBAC5C,IAAI,IAAI,EAAE;4BACR,MAAM;yBACP;wBAED,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;wBAClD,IAAI,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;wBAClC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,uBAAuB;wBAEnD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;4BACxB,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;gCAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gCAC3B,IAAI,IAAI,KAAK,QAAQ,EAAE;oCACrB,OAAO;iCACR;gCAED,IAAI;oCACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oCAChC,MAAM,MAAM,CAAC;iCACd;gCAAC,OAAO,CAAC,EAAE;oCACV,EAAE;iCACH;6BACF;yBACF;qBACF;iBACF;wBAAS;oBACR,MAAM,CAAC,WAAW,EAAE,CAAC;iBACtB;YACH,CAAC;YAED,eAAe,EAAE,aAAa;SAC/B,CAAC;QAEF,OAAO,SAAgC,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export { default as ThreadsSDK } from './threads';
2
+ export { default as ChatSDK } from './chat';
3
+ export { default as RAGSDK } from './rag';
4
+ export * from './types';
@@ -0,0 +1,5 @@
1
+ export { default as ThreadsSDK } from './threads';
2
+ export { default as ChatSDK } from './chat';
3
+ export { default as RAGSDK } from './rag';
4
+ export * from './types';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,cAAc,SAAS,CAAC"}
@@ -0,0 +1,33 @@
1
+ import BaseSDK from '../base-sdk';
2
+ import { QelosSDKOptions } from '../types';
3
+ import { ICreateVectorStorageRequest, IUploadContentRequest, IClearStorageRequest, IVectorStore } from '../ai';
4
+ export default class RAGSDK extends BaseSDK {
5
+ private relativePath;
6
+ constructor(options: QelosSDKOptions);
7
+ /**
8
+ * Create a vector storage for RAG
9
+ */
10
+ createStorage(sourceId: string, data: ICreateVectorStorageRequest): Promise<{
11
+ success: boolean;
12
+ message: string;
13
+ vectorStore: IVectorStore;
14
+ }>;
15
+ /**
16
+ * Upload content to vector storage
17
+ */
18
+ uploadContent(sourceId: string, data: IUploadContentRequest): Promise<{
19
+ success: boolean;
20
+ message: string;
21
+ fileId: string;
22
+ vectorStoreId: string;
23
+ }>;
24
+ /**
25
+ * Clear files from vector storage
26
+ */
27
+ clearStorage(sourceId: string, data: IClearStorageRequest): Promise<{
28
+ success: boolean;
29
+ message: string;
30
+ clearedCount: number;
31
+ vectorStoreId: string;
32
+ }>;
33
+ }
package/dist/ai/rag.js ADDED
@@ -0,0 +1,38 @@
1
+ import BaseSDK from '../base-sdk';
2
+ export default class RAGSDK extends BaseSDK {
3
+ relativePath = '/api/ai';
4
+ constructor(options) {
5
+ super(options);
6
+ }
7
+ /**
8
+ * Create a vector storage for RAG
9
+ */
10
+ createStorage(sourceId, data) {
11
+ return this.callJsonApi(`${this.relativePath}/sources/${sourceId}/storage${this.getQueryParams({})}`, {
12
+ method: 'POST',
13
+ headers: { 'content-type': 'application/json' },
14
+ body: JSON.stringify(data)
15
+ });
16
+ }
17
+ /**
18
+ * Upload content to vector storage
19
+ */
20
+ uploadContent(sourceId, data) {
21
+ return this.callJsonApi(`${this.relativePath}/sources/${sourceId}/storage/upload${this.getQueryParams({})}`, {
22
+ method: 'POST',
23
+ headers: { 'content-type': 'application/json' },
24
+ body: JSON.stringify(data)
25
+ });
26
+ }
27
+ /**
28
+ * Clear files from vector storage
29
+ */
30
+ clearStorage(sourceId, data) {
31
+ return this.callJsonApi(`${this.relativePath}/sources/${sourceId}/storage/clear${this.getQueryParams({})}`, {
32
+ method: 'POST',
33
+ headers: { 'content-type': 'application/json' },
34
+ body: JSON.stringify(data)
35
+ });
36
+ }
37
+ }
38
+ //# sourceMappingURL=rag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rag.js","sourceRoot":"","sources":["../../src/ai/rag.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,aAAa,CAAC;AASlC,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,OAAO;IACjC,YAAY,GAAG,SAAS,CAAC;IAEjC,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,aAAa,CACX,QAAgB,EAChB,IAAiC;QAMjC,OAAO,IAAI,CAAC,WAAW,CAAM,GAAG,IAAI,CAAC,YAAY,YAAY,QAAQ,WAAW,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE;YACzG,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,aAAa,CACX,QAAgB,EAChB,IAA2B;QAO3B,OAAO,IAAI,CAAC,WAAW,CAAM,GAAG,IAAI,CAAC,YAAY,YAAY,QAAQ,kBAAkB,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE;YAChH,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,YAAY,CACV,QAAgB,EAChB,IAA0B;QAO1B,OAAO,IAAI,CAAC,WAAW,CAAM,GAAG,IAAI,CAAC,YAAY,YAAY,QAAQ,iBAAiB,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE;YAC/G,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,33 @@
1
+ import BaseSDK from '../base-sdk';
2
+ import { QelosSDKOptions } from '../types';
3
+ import { IThread, ICreateThreadRequest } from '../ai';
4
+ export default class ThreadsSDK extends BaseSDK {
5
+ private relativePath;
6
+ constructor(options: QelosSDKOptions);
7
+ /**
8
+ * Create a new thread
9
+ */
10
+ create(data: ICreateThreadRequest): Promise<IThread>;
11
+ /**
12
+ * Get a specific thread by ID
13
+ */
14
+ getOne(threadId: string): Promise<IThread>;
15
+ /**
16
+ * List threads with optional filters
17
+ */
18
+ list(options?: {
19
+ integration?: string;
20
+ limit?: number;
21
+ page?: number;
22
+ sort?: string;
23
+ user?: string;
24
+ workspace?: string;
25
+ [key: string]: string | number;
26
+ }): Promise<IThread[]>;
27
+ /**
28
+ * Delete a thread
29
+ */
30
+ delete(threadId: string): Promise<{
31
+ success: boolean;
32
+ }>;
33
+ }
@@ -0,0 +1,39 @@
1
+ import BaseSDK from '../base-sdk';
2
+ export default class ThreadsSDK extends BaseSDK {
3
+ relativePath = '/api/ai';
4
+ constructor(options) {
5
+ super(options);
6
+ }
7
+ /**
8
+ * Create a new thread
9
+ */
10
+ create(data) {
11
+ return this.callJsonApi(this.relativePath + '/threads', {
12
+ method: 'POST',
13
+ headers: { 'content-type': 'application/json' },
14
+ body: JSON.stringify(data)
15
+ });
16
+ }
17
+ /**
18
+ * Get a specific thread by ID
19
+ */
20
+ getOne(threadId) {
21
+ return this.callJsonApi(`${this.relativePath}/threads/${threadId}${this.getQueryParams({})}`);
22
+ }
23
+ /**
24
+ * List threads with optional filters
25
+ */
26
+ list(options) {
27
+ const queryParams = this.getQueryParams(options);
28
+ return this.callJsonApi(`${this.relativePath}/threads${queryParams}`);
29
+ }
30
+ /**
31
+ * Delete a thread
32
+ */
33
+ delete(threadId) {
34
+ return this.callJsonApi(`${this.relativePath}/threads/${threadId}${this.getQueryParams({})}`, {
35
+ method: 'DELETE'
36
+ });
37
+ }
38
+ }
39
+ //# sourceMappingURL=threads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threads.js","sourceRoot":"","sources":["../../src/ai/threads.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,aAAa,CAAC;AAIlC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IACrC,YAAY,GAAG,SAAS,CAAC;IAEjC,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAA0B;QAC/B,OAAO,IAAI,CAAC,WAAW,CAAU,IAAI,CAAC,YAAY,GAAG,UAAU,EAAE;YAC/D,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAgB;QACrB,OAAO,IAAI,CAAC,WAAW,CAAU,GAAG,IAAI,CAAC,YAAY,YAAY,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACzG,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAQJ;QACC,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,WAAW,CACrB,GAAG,IAAI,CAAC,YAAY,WAAW,WAAW,EAAE,CAC7C,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAgB;QACrB,OAAO,IAAI,CAAC,WAAW,CAAuB,GAAG,IAAI,CAAC,YAAY,YAAY,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE;YAClH,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,91 @@
1
+ export interface IMessage {
2
+ role: string;
3
+ content: string;
4
+ timestamp?: Date | string;
5
+ tool_calls?: any[];
6
+ name?: string;
7
+ tool_call_id?: string;
8
+ function_call?: any;
9
+ message_id?: string;
10
+ }
11
+ export interface IMessageSummary {
12
+ fromIndex: number;
13
+ toIndex: number;
14
+ summary: string;
15
+ }
16
+ export interface IThread {
17
+ _id?: string;
18
+ integration: string;
19
+ title?: string;
20
+ messages: IMessage[];
21
+ messageSummaries: IMessageSummary[];
22
+ created?: Date;
23
+ updated?: Date;
24
+ user?: string;
25
+ workspace?: string;
26
+ }
27
+ export interface IChatCompletionOptions {
28
+ messages: IMessage[];
29
+ model?: string;
30
+ temperature?: number;
31
+ top_p?: number;
32
+ frequency_penalty?: number;
33
+ presence_penalty?: number;
34
+ stop?: string | string[];
35
+ max_tokens?: number;
36
+ response_format?: any;
37
+ context?: Record<string, any>;
38
+ stream?: boolean;
39
+ queryParams?: Record<string, any>;
40
+ }
41
+ export interface ISSEStreamProcessor extends AsyncIterable<any> {
42
+ processManually(onData: (data: any) => void | boolean): Promise<void>;
43
+ }
44
+ export interface IChatCompletionResponse {
45
+ id: string;
46
+ object: string;
47
+ created: number;
48
+ model: string;
49
+ choices: Array<{
50
+ index: number;
51
+ message: IMessage;
52
+ finish_reason: string;
53
+ }>;
54
+ usage?: {
55
+ prompt_tokens: number;
56
+ completion_tokens: number;
57
+ total_tokens: number;
58
+ };
59
+ }
60
+ export interface ICreateThreadRequest {
61
+ integration: string;
62
+ title?: string;
63
+ }
64
+ export interface ICreateVectorStorageRequest {
65
+ integrationId: string;
66
+ scope: 'thread' | 'user' | 'workspace' | 'tenant';
67
+ subjectId?: string;
68
+ expirationAfterDays?: number;
69
+ }
70
+ export interface IUploadContentRequest {
71
+ integrationId?: string;
72
+ vectorStoreId?: string;
73
+ content: string | object;
74
+ fileName?: string;
75
+ metadata?: Record<string, any>;
76
+ }
77
+ export interface IClearStorageRequest {
78
+ integrationId?: string;
79
+ vectorStoreId?: string;
80
+ fileIds?: string[];
81
+ }
82
+ export interface IVectorStore {
83
+ _id: string;
84
+ scope: string;
85
+ subjectId?: string;
86
+ tenant: string;
87
+ agent: string;
88
+ externalId: string;
89
+ expirationAfterDays?: number;
90
+ created: Date;
91
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ai/types.ts"],"names":[],"mappings":""}
package/dist/ai.d.ts CHANGED
@@ -1,80 +1,68 @@
1
1
  import { QelosSDKOptions } from './types';
2
2
  import BaseSDK from './base-sdk';
3
- export interface IMessage {
4
- role: string;
5
- content: string;
6
- timestamp?: Date | string;
7
- tool_calls?: any[];
8
- name?: string;
9
- tool_call_id?: string;
10
- function_call?: any;
11
- message_id?: string;
12
- }
13
- export interface IMessageSummary {
14
- fromIndex: number;
15
- toIndex: number;
16
- summary: string;
17
- }
18
- export interface IThread {
19
- _id?: string;
20
- integration: string;
21
- title?: string;
22
- messages: IMessage[];
23
- messageSummaries: IMessageSummary[];
24
- created?: Date;
25
- updated?: Date;
26
- user?: string;
27
- workspace?: string;
28
- }
29
- export interface IChatCompletionOptions {
30
- messages: IMessage[];
31
- model?: string;
32
- temperature?: number;
33
- top_p?: number;
34
- frequency_penalty?: number;
35
- presence_penalty?: number;
36
- stop?: string | string[];
37
- max_tokens?: number;
38
- response_format?: any;
39
- context?: Record<string, any>;
40
- stream?: boolean;
41
- }
42
- export interface ISSEStreamProcessor extends AsyncIterable<any> {
43
- processManually(onData: (data: any) => void | boolean): Promise<void>;
44
- }
45
- export interface IChatCompletionResponse {
46
- id: string;
47
- object: string;
48
- created: number;
49
- model: string;
50
- choices: Array<{
51
- index: number;
52
- message: IMessage;
53
- finish_reason: string;
54
- }>;
55
- usage?: {
56
- prompt_tokens: number;
57
- completion_tokens: number;
58
- total_tokens: number;
59
- };
60
- }
61
- export interface ICreateThreadRequest {
62
- integration: string;
63
- title?: string;
64
- }
3
+ import ThreadsSDK from './ai/threads';
4
+ import ChatSDK from './ai/chat';
5
+ import RAGSDK from './ai/rag';
6
+ import { IMessage, IMessageSummary, IThread, IChatCompletionOptions, ISSEStreamProcessor, IChatCompletionResponse, ICreateThreadRequest, ICreateVectorStorageRequest, IUploadContentRequest, IClearStorageRequest, IVectorStore } from './ai/types';
7
+ export { IMessage, IMessageSummary, IThread, IChatCompletionOptions, ISSEStreamProcessor, IChatCompletionResponse, ICreateThreadRequest, ICreateVectorStorageRequest, IUploadContentRequest, IClearStorageRequest, IVectorStore };
8
+ /**
9
+ * Qelos AI SDK - Main SDK class with three sub-SDKs
10
+ *
11
+ * This class provides access to AI functionality through three sub-SDKs:
12
+ * - `threads`: Thread CRUD operations for managing conversation threads
13
+ * - `chat`: Chat completion operations (streaming and non-streaming)
14
+ * - `rag`: Vector storage management for Retrieval-Augmented Generation
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const sdk = new QelosSDK({
19
+ * appUrl: 'https://your-qelos-instance.com',
20
+ * fetch: globalThis.fetch,
21
+ * accessToken: 'your-token'
22
+ * });
23
+ *
24
+ * // Create a thread
25
+ * const thread = await sdk.ai.threads.create({ integration: 'id' });
26
+ *
27
+ * // Stream chat
28
+ * const stream = await sdk.ai.chat.stream('id', { messages: [...] });
29
+ * for await (const chunk of sdk.ai.chat.parseSSEStream(stream)) {
30
+ * console.log(chunk);
31
+ * }
32
+ *
33
+ * // Upload RAG content
34
+ * await sdk.ai.rag.uploadContent('sourceId', { content: '...' });
35
+ * ```
36
+ */
65
37
  export default class QlAI extends BaseSDK {
66
- private relativePath;
38
+ /**
39
+ * Threads sub-SDK for managing conversation threads
40
+ */
41
+ threads: ThreadsSDK;
42
+ /**
43
+ * Chat sub-SDK for chat completion operations
44
+ */
45
+ chat: ChatSDK;
46
+ /**
47
+ * RAG sub-SDK for vector storage management
48
+ */
49
+ rag: RAGSDK;
50
+ /**
51
+ * Initialize the AI SDK with sub-SDKs
52
+ *
53
+ * @param options - SDK configuration options
54
+ */
67
55
  constructor(options: QelosSDKOptions);
68
56
  /**
69
- * Create a new thread
57
+ * @deprecated Use sdk.threads.create() instead
70
58
  */
71
59
  createThread(data: ICreateThreadRequest): Promise<IThread>;
72
60
  /**
73
- * Get a specific thread by ID
61
+ * @deprecated Use sdk.threads.getOne() instead
74
62
  */
75
63
  getThread(threadId: string): Promise<IThread>;
76
64
  /**
77
- * List threads with optional filters
65
+ * @deprecated Use sdk.threads.list() instead
78
66
  */
79
67
  listThreads(options?: {
80
68
  integration?: string;
@@ -86,31 +74,29 @@ export default class QlAI extends BaseSDK {
86
74
  [key: string]: string | number;
87
75
  }): Promise<IThread[]>;
88
76
  /**
89
- * Delete a thread
77
+ * @deprecated Use sdk.threads.delete() instead
90
78
  */
91
79
  deleteThread(threadId: string): Promise<{
92
80
  success: boolean;
93
81
  }>;
94
82
  /**
95
- * Create a chat completion without a thread
83
+ * @deprecated Use sdk.chat.chat() instead
96
84
  */
97
- chat(integrationId: string, options: IChatCompletionOptions): Promise<IChatCompletionResponse>;
85
+ chatCompletion(integrationId: string, options: IChatCompletionOptions): Promise<IChatCompletionResponse>;
98
86
  /**
99
- * Create a chat completion with a thread
87
+ * @deprecated Use sdk.chat.chatInThread() instead
100
88
  */
101
- chatInThread(integrationId: string, threadId: string, options: IChatCompletionOptions): Promise<IChatCompletionResponse>;
89
+ chatCompletionInThread(integrationId: string, threadId: string, options: IChatCompletionOptions): Promise<IChatCompletionResponse>;
102
90
  /**
103
- * Create a streaming chat completion without a thread
104
- * Returns a ReadableStream for Server-Sent Events
91
+ * @deprecated Use sdk.chat.stream() instead
105
92
  */
106
93
  streamChat(integrationId: string, options: IChatCompletionOptions): Promise<ReadableStream<Uint8Array>>;
107
94
  /**
108
- * Create a streaming chat completion with a thread
109
- * Returns a ReadableStream for Server-Sent Events
95
+ * @deprecated Use sdk.chat.streamInThread() instead
110
96
  */
111
97
  streamChatInThread(integrationId: string, threadId: string, options: IChatCompletionOptions): Promise<ReadableStream<Uint8Array>>;
112
98
  /**
113
- * Helper method to parse Server-Sent Events stream
99
+ * @deprecated Use sdk.chat.parseSSEStream() instead
114
100
  */
115
101
  parseSSEStream(stream: ReadableStream<Uint8Array>): ISSEStreamProcessor;
116
102
  }