@aviaryhq/cloudglue-js 0.6.0 → 0.6.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/generated/Response.d.ts +30 -41
- package/dist/generated/Response.js +35 -17
- package/dist/generated/common.d.ts +17 -17
- package/dist/src/api/response.api.d.ts +112 -43
- package/dist/src/api/response.api.js +113 -0
- package/dist/src/client.js +1 -1
- package/dist/src/types.d.ts +9 -0
- package/package.json +2 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { type ZodiosOptions } from '@zodios/core';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { SearchFilter } from './common';
|
|
3
4
|
type CreateResponseRequest = {
|
|
4
|
-
model:
|
|
5
|
+
model: string;
|
|
5
6
|
input: string | Array<ResponseInputMessage>;
|
|
6
7
|
instructions?: (string | null) | undefined;
|
|
7
8
|
temperature?: number | undefined;
|
|
8
9
|
knowledge_base: ResponseKnowledgeBase;
|
|
9
10
|
include?: Array<'cloudglue_citations.media_descriptions'> | undefined;
|
|
10
11
|
background?: boolean | undefined;
|
|
12
|
+
stream?: boolean | undefined;
|
|
11
13
|
};
|
|
12
14
|
type ResponseOutputMessage = Partial<{
|
|
13
15
|
type: 'message';
|
|
@@ -19,20 +21,20 @@ type ResponseOutputContent = Partial<{
|
|
|
19
21
|
text: string;
|
|
20
22
|
annotations: Array<ResponseAnnotation>;
|
|
21
23
|
}>;
|
|
22
|
-
type ResponseAnnotation =
|
|
24
|
+
type ResponseAnnotation = {
|
|
23
25
|
type: 'cloudglue_citation';
|
|
24
26
|
collection_id: string;
|
|
25
27
|
file_id: string;
|
|
26
|
-
segment_id
|
|
28
|
+
segment_id?: string | undefined;
|
|
27
29
|
start_time: number;
|
|
28
|
-
end_time
|
|
29
|
-
context
|
|
30
|
-
relevant_sources
|
|
31
|
-
visual_scene_description
|
|
32
|
-
scene_text
|
|
33
|
-
speech
|
|
34
|
-
audio_description
|
|
35
|
-
}
|
|
30
|
+
end_time?: number | undefined;
|
|
31
|
+
context?: string | undefined;
|
|
32
|
+
relevant_sources?: Array<string> | undefined;
|
|
33
|
+
visual_scene_description?: Array<string> | undefined;
|
|
34
|
+
scene_text?: Array<string> | undefined;
|
|
35
|
+
speech?: Array<string> | undefined;
|
|
36
|
+
audio_description?: Array<string> | undefined;
|
|
37
|
+
};
|
|
36
38
|
type ResponseUsage = Partial<{
|
|
37
39
|
input_tokens: number;
|
|
38
40
|
output_tokens: number;
|
|
@@ -53,10 +55,19 @@ type ResponseInputContent = {
|
|
|
53
55
|
text: string;
|
|
54
56
|
};
|
|
55
57
|
type ResponseKnowledgeBase = {
|
|
58
|
+
type?: ('general_question_answering' | 'entity_backed_knowledge') | undefined;
|
|
56
59
|
collections: Array<string>;
|
|
57
|
-
filter?:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
filter?: SearchFilter | undefined;
|
|
61
|
+
entity_backed_knowledge_config?: EntityBackedKnowledgeConfig | undefined;
|
|
62
|
+
};
|
|
63
|
+
type EntityBackedKnowledgeConfig = {
|
|
64
|
+
entity_collections: Array<EntityCollectionConfig>;
|
|
65
|
+
description?: string | undefined;
|
|
66
|
+
};
|
|
67
|
+
type EntityCollectionConfig = {
|
|
68
|
+
name: string;
|
|
69
|
+
description: string;
|
|
70
|
+
collection_id: string;
|
|
60
71
|
};
|
|
61
72
|
type ResponseListItem = Partial<{
|
|
62
73
|
id: string;
|
|
@@ -69,6 +80,8 @@ type ResponseListItem = Partial<{
|
|
|
69
80
|
}>;
|
|
70
81
|
declare const ResponseInputContent: z.ZodType<ResponseInputContent>;
|
|
71
82
|
declare const ResponseInputMessage: z.ZodType<ResponseInputMessage>;
|
|
83
|
+
declare const EntityCollectionConfig: z.ZodType<EntityCollectionConfig>;
|
|
84
|
+
declare const EntityBackedKnowledgeConfig: z.ZodType<EntityBackedKnowledgeConfig>;
|
|
72
85
|
declare const ResponseKnowledgeBase: z.ZodType<ResponseKnowledgeBase>;
|
|
73
86
|
declare const CreateResponseRequest: z.ZodType<CreateResponseRequest>;
|
|
74
87
|
declare const ResponseAnnotation: z.ZodType<ResponseAnnotation>;
|
|
@@ -80,35 +93,11 @@ declare const ResponseListItem: z.ZodType<ResponseListItem>;
|
|
|
80
93
|
export declare const schemas: {
|
|
81
94
|
ResponseInputContent: z.ZodType<ResponseInputContent, z.ZodTypeDef, ResponseInputContent>;
|
|
82
95
|
ResponseInputMessage: z.ZodType<ResponseInputMessage, z.ZodTypeDef, ResponseInputMessage>;
|
|
96
|
+
EntityCollectionConfig: z.ZodType<EntityCollectionConfig, z.ZodTypeDef, EntityCollectionConfig>;
|
|
97
|
+
EntityBackedKnowledgeConfig: z.ZodType<EntityBackedKnowledgeConfig, z.ZodTypeDef, EntityBackedKnowledgeConfig>;
|
|
83
98
|
ResponseKnowledgeBase: z.ZodType<ResponseKnowledgeBase, z.ZodTypeDef, ResponseKnowledgeBase>;
|
|
84
99
|
CreateResponseRequest: z.ZodType<CreateResponseRequest, z.ZodTypeDef, CreateResponseRequest>;
|
|
85
|
-
ResponseAnnotation: z.ZodType<
|
|
86
|
-
type: "cloudglue_citation";
|
|
87
|
-
collection_id: string;
|
|
88
|
-
file_id: string;
|
|
89
|
-
segment_id: string;
|
|
90
|
-
start_time: number;
|
|
91
|
-
end_time: number;
|
|
92
|
-
context: string;
|
|
93
|
-
relevant_sources: Array<string>;
|
|
94
|
-
visual_scene_description: Array<string>;
|
|
95
|
-
scene_text: Array<string>;
|
|
96
|
-
speech: Array<string>;
|
|
97
|
-
audio_description: Array<string>;
|
|
98
|
-
}>, z.ZodTypeDef, Partial<{
|
|
99
|
-
type: "cloudglue_citation";
|
|
100
|
-
collection_id: string;
|
|
101
|
-
file_id: string;
|
|
102
|
-
segment_id: string;
|
|
103
|
-
start_time: number;
|
|
104
|
-
end_time: number;
|
|
105
|
-
context: string;
|
|
106
|
-
relevant_sources: Array<string>;
|
|
107
|
-
visual_scene_description: Array<string>;
|
|
108
|
-
scene_text: Array<string>;
|
|
109
|
-
speech: Array<string>;
|
|
110
|
-
audio_description: Array<string>;
|
|
111
|
-
}>>;
|
|
100
|
+
ResponseAnnotation: z.ZodType<ResponseAnnotation, z.ZodTypeDef, ResponseAnnotation>;
|
|
112
101
|
ResponseOutputContent: z.ZodType<Partial<{
|
|
113
102
|
type: "output_text";
|
|
114
103
|
text: string;
|
|
@@ -4,6 +4,7 @@ exports.ResponseApi = exports.schemas = void 0;
|
|
|
4
4
|
exports.createApiClient = createApiClient;
|
|
5
5
|
const core_1 = require("@zodios/core");
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
|
+
const common_1 = require("./common");
|
|
7
8
|
const ResponseInputContent = zod_1.z
|
|
8
9
|
.object({ type: zod_1.z.literal('input_text'), text: zod_1.z.string() })
|
|
9
10
|
.strict()
|
|
@@ -16,29 +17,45 @@ const ResponseInputMessage = zod_1.z
|
|
|
16
17
|
})
|
|
17
18
|
.strict()
|
|
18
19
|
.passthrough();
|
|
20
|
+
const EntityCollectionConfig = zod_1.z
|
|
21
|
+
.object({
|
|
22
|
+
name: zod_1.z.string(),
|
|
23
|
+
description: zod_1.z.string(),
|
|
24
|
+
collection_id: zod_1.z.string().uuid(),
|
|
25
|
+
})
|
|
26
|
+
.strict()
|
|
27
|
+
.passthrough();
|
|
28
|
+
const EntityBackedKnowledgeConfig = zod_1.z
|
|
29
|
+
.object({
|
|
30
|
+
entity_collections: zod_1.z.array(EntityCollectionConfig).min(1),
|
|
31
|
+
description: zod_1.z.string().max(2000).optional(),
|
|
32
|
+
})
|
|
33
|
+
.strict()
|
|
34
|
+
.passthrough();
|
|
19
35
|
const ResponseKnowledgeBase = zod_1.z
|
|
20
36
|
.object({
|
|
37
|
+
type: zod_1.z
|
|
38
|
+
.enum(['general_question_answering', 'entity_backed_knowledge'])
|
|
39
|
+
.optional()
|
|
40
|
+
.default('general_question_answering'),
|
|
21
41
|
collections: zod_1.z.array(zod_1.z.string().uuid()).min(1),
|
|
22
|
-
filter:
|
|
23
|
-
|
|
24
|
-
.partial()
|
|
25
|
-
.strict()
|
|
26
|
-
.passthrough()
|
|
27
|
-
.optional(),
|
|
42
|
+
filter: common_1.SearchFilter.optional(),
|
|
43
|
+
entity_backed_knowledge_config: EntityBackedKnowledgeConfig.optional(),
|
|
28
44
|
})
|
|
29
45
|
.strict()
|
|
30
46
|
.passthrough();
|
|
31
47
|
const CreateResponseRequest = zod_1.z
|
|
32
48
|
.object({
|
|
33
|
-
model: zod_1.z.
|
|
49
|
+
model: zod_1.z.string().min(1),
|
|
34
50
|
input: zod_1.z.union([zod_1.z.string(), zod_1.z.array(ResponseInputMessage)]),
|
|
35
51
|
instructions: zod_1.z.string().optional(),
|
|
36
|
-
temperature: zod_1.z.number().gte(0).lte(2).optional()
|
|
52
|
+
temperature: zod_1.z.number().gte(0).lte(2).optional(),
|
|
37
53
|
knowledge_base: ResponseKnowledgeBase,
|
|
38
54
|
include: zod_1.z
|
|
39
55
|
.array(zod_1.z.literal('cloudglue_citations.media_descriptions'))
|
|
40
56
|
.optional(),
|
|
41
57
|
background: zod_1.z.boolean().optional().default(false),
|
|
58
|
+
stream: zod_1.z.boolean().optional().default(false),
|
|
42
59
|
})
|
|
43
60
|
.strict()
|
|
44
61
|
.passthrough();
|
|
@@ -47,17 +64,16 @@ const ResponseAnnotation = zod_1.z
|
|
|
47
64
|
type: zod_1.z.literal('cloudglue_citation'),
|
|
48
65
|
collection_id: zod_1.z.string().uuid(),
|
|
49
66
|
file_id: zod_1.z.string().uuid(),
|
|
50
|
-
segment_id: zod_1.z.string().uuid(),
|
|
67
|
+
segment_id: zod_1.z.string().uuid().optional(),
|
|
51
68
|
start_time: zod_1.z.number(),
|
|
52
|
-
end_time: zod_1.z.number(),
|
|
53
|
-
context: zod_1.z.string(),
|
|
54
|
-
relevant_sources: zod_1.z.array(zod_1.z.string()),
|
|
55
|
-
visual_scene_description: zod_1.z.array(zod_1.z.string()),
|
|
56
|
-
scene_text: zod_1.z.array(zod_1.z.string()),
|
|
57
|
-
speech: zod_1.z.array(zod_1.z.string()),
|
|
58
|
-
audio_description: zod_1.z.array(zod_1.z.string()),
|
|
69
|
+
end_time: zod_1.z.number().optional(),
|
|
70
|
+
context: zod_1.z.string().optional(),
|
|
71
|
+
relevant_sources: zod_1.z.array(zod_1.z.string()).optional(),
|
|
72
|
+
visual_scene_description: zod_1.z.array(zod_1.z.string()).optional(),
|
|
73
|
+
scene_text: zod_1.z.array(zod_1.z.string()).optional(),
|
|
74
|
+
speech: zod_1.z.array(zod_1.z.string()).optional(),
|
|
75
|
+
audio_description: zod_1.z.array(zod_1.z.string()).optional(),
|
|
59
76
|
})
|
|
60
|
-
.partial()
|
|
61
77
|
.strict()
|
|
62
78
|
.passthrough();
|
|
63
79
|
const ResponseOutputContent = zod_1.z
|
|
@@ -143,6 +159,8 @@ const DeleteResponseResult = zod_1.z
|
|
|
143
159
|
exports.schemas = {
|
|
144
160
|
ResponseInputContent,
|
|
145
161
|
ResponseInputMessage,
|
|
162
|
+
EntityCollectionConfig,
|
|
163
|
+
EntityBackedKnowledgeConfig,
|
|
146
164
|
ResponseKnowledgeBase,
|
|
147
165
|
CreateResponseRequest,
|
|
148
166
|
ResponseAnnotation,
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export type SearchFilter = Partial<{
|
|
3
|
+
metadata: Array<SearchFilterCriteria & Partial<{
|
|
4
|
+
scope: 'file' | 'segment';
|
|
5
|
+
}>>;
|
|
6
|
+
video_info: Array<SearchFilterCriteria & Partial<{
|
|
7
|
+
path: 'duration_seconds' | 'has_audio';
|
|
8
|
+
}>>;
|
|
9
|
+
file: Array<SearchFilterCriteria & Partial<{
|
|
10
|
+
path: 'bytes' | 'filename' | 'uri' | 'created_at' | 'id';
|
|
11
|
+
}>>;
|
|
12
|
+
}>;
|
|
13
|
+
export type SearchFilterCriteria = {
|
|
14
|
+
path: string;
|
|
15
|
+
operator: 'NotEqual' | 'Equal' | 'LessThan' | 'GreaterThan' | 'ContainsAny' | 'ContainsAll' | 'In' | 'Like';
|
|
16
|
+
valueText?: string | undefined;
|
|
17
|
+
valueTextArray?: Array<string> | undefined;
|
|
18
|
+
};
|
|
2
19
|
export type DescribeOutput = Partial<{
|
|
3
20
|
visual_scene_description: Array<DescribeOutputPart>;
|
|
4
21
|
scene_text: Array<DescribeOutputPart>;
|
|
@@ -89,23 +106,6 @@ export type File = {
|
|
|
89
106
|
thumbnail_url?: string | undefined;
|
|
90
107
|
source?: ('video' | 'youtube' | 's3' | 'dropbox' | 'http' | 'upload' | 'google-drive' | 'zoom' | 'gong' | 'recall' | 'gcs') | undefined;
|
|
91
108
|
};
|
|
92
|
-
export type SearchFilter = Partial<{
|
|
93
|
-
metadata: Array<SearchFilterCriteria & Partial<{
|
|
94
|
-
scope: 'file' | 'segment';
|
|
95
|
-
}>>;
|
|
96
|
-
video_info: Array<SearchFilterCriteria & Partial<{
|
|
97
|
-
path: 'duration_seconds' | 'has_audio';
|
|
98
|
-
}>>;
|
|
99
|
-
file: Array<SearchFilterCriteria & Partial<{
|
|
100
|
-
path: 'bytes' | 'filename' | 'uri' | 'created_at' | 'id';
|
|
101
|
-
}>>;
|
|
102
|
-
}>;
|
|
103
|
-
export type SearchFilterCriteria = {
|
|
104
|
-
path: string;
|
|
105
|
-
operator: 'NotEqual' | 'Equal' | 'LessThan' | 'GreaterThan' | 'ContainsAny' | 'ContainsAll' | 'In' | 'Like';
|
|
106
|
-
valueText?: string | undefined;
|
|
107
|
-
valueTextArray?: Array<string> | undefined;
|
|
108
|
-
};
|
|
109
109
|
export type Describe = {
|
|
110
110
|
job_id: string;
|
|
111
111
|
status: 'pending' | 'processing' | 'completed' | 'failed' | 'not_applicable';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ResponseApi } from '../../generated';
|
|
2
|
+
import type { SearchFilter } from '../../generated/common';
|
|
2
3
|
import { WaitForReadyOptions } from '../types';
|
|
3
4
|
type ResponseStatus = 'in_progress' | 'completed' | 'failed' | 'cancelled';
|
|
4
5
|
export interface CreateResponseParams {
|
|
5
6
|
/** The model to use for the response */
|
|
6
|
-
model: 'nimbus-001';
|
|
7
|
+
model: 'nimbus-001' | 'nimbus-002-preview' | (string & {});
|
|
7
8
|
/** The input message(s) - can be a simple string or array of structured messages */
|
|
8
9
|
input: string | Array<{
|
|
9
10
|
type: 'message';
|
|
@@ -19,15 +20,24 @@ export interface CreateResponseParams {
|
|
|
19
20
|
temperature?: number;
|
|
20
21
|
/** Knowledge base configuration specifying collections to search */
|
|
21
22
|
knowledge_base: {
|
|
23
|
+
type?: 'general_question_answering' | 'entity_backed_knowledge';
|
|
22
24
|
collections: string[];
|
|
23
|
-
filter?:
|
|
24
|
-
|
|
25
|
+
filter?: SearchFilter;
|
|
26
|
+
entity_backed_knowledge_config?: {
|
|
27
|
+
entity_collections: Array<{
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
collection_id: string;
|
|
31
|
+
}>;
|
|
32
|
+
description?: string;
|
|
25
33
|
};
|
|
26
34
|
};
|
|
27
35
|
/** Include additional data in response annotations */
|
|
28
36
|
include?: Array<'cloudglue_citations.media_descriptions'>;
|
|
29
37
|
/** Run the response generation in background (async) */
|
|
30
38
|
background?: boolean;
|
|
39
|
+
/** Enable server-sent events streaming */
|
|
40
|
+
stream?: boolean;
|
|
31
41
|
}
|
|
32
42
|
export interface ListResponsesParams {
|
|
33
43
|
limit?: number;
|
|
@@ -36,6 +46,57 @@ export interface ListResponsesParams {
|
|
|
36
46
|
created_before?: string;
|
|
37
47
|
created_after?: string;
|
|
38
48
|
}
|
|
49
|
+
export interface ResponseCreatedEvent {
|
|
50
|
+
type: 'response.created';
|
|
51
|
+
response: Record<string, any>;
|
|
52
|
+
}
|
|
53
|
+
export interface ResponseOutputItemAddedEvent {
|
|
54
|
+
type: 'response.output_item.added';
|
|
55
|
+
output_index: number;
|
|
56
|
+
item: Record<string, any>;
|
|
57
|
+
}
|
|
58
|
+
export interface ResponseContentPartAddedEvent {
|
|
59
|
+
type: 'response.content_part.added';
|
|
60
|
+
output_index: number;
|
|
61
|
+
content_index: number;
|
|
62
|
+
part: Record<string, any>;
|
|
63
|
+
}
|
|
64
|
+
export interface ResponseOutputTextDeltaEvent {
|
|
65
|
+
type: 'response.output_text.delta';
|
|
66
|
+
output_index: number;
|
|
67
|
+
content_index: number;
|
|
68
|
+
delta: string;
|
|
69
|
+
}
|
|
70
|
+
export interface ResponseOutputTextDoneEvent {
|
|
71
|
+
type: 'response.output_text.done';
|
|
72
|
+
output_index: number;
|
|
73
|
+
content_index: number;
|
|
74
|
+
text: string;
|
|
75
|
+
}
|
|
76
|
+
export interface ResponseContentPartDoneEvent {
|
|
77
|
+
type: 'response.content_part.done';
|
|
78
|
+
output_index: number;
|
|
79
|
+
content_index: number;
|
|
80
|
+
part: Record<string, any>;
|
|
81
|
+
}
|
|
82
|
+
export interface ResponseOutputItemDoneEvent {
|
|
83
|
+
type: 'response.output_item.done';
|
|
84
|
+
output_index: number;
|
|
85
|
+
item: Record<string, any>;
|
|
86
|
+
}
|
|
87
|
+
export interface ResponseCompletedEvent {
|
|
88
|
+
type: 'response.completed';
|
|
89
|
+
response: Record<string, any>;
|
|
90
|
+
}
|
|
91
|
+
export interface ResponseErrorEvent {
|
|
92
|
+
type: 'error';
|
|
93
|
+
error: {
|
|
94
|
+
message: string;
|
|
95
|
+
type?: string;
|
|
96
|
+
code?: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export type ResponseStreamEventType = ResponseCreatedEvent | ResponseOutputItemAddedEvent | ResponseContentPartAddedEvent | ResponseOutputTextDeltaEvent | ResponseOutputTextDoneEvent | ResponseContentPartDoneEvent | ResponseOutputItemDoneEvent | ResponseCompletedEvent | ResponseErrorEvent;
|
|
39
100
|
export declare class EnhancedResponseApi {
|
|
40
101
|
private readonly api;
|
|
41
102
|
constructor(api: typeof ResponseApi);
|
|
@@ -59,20 +120,20 @@ export declare class EnhancedResponseApi {
|
|
|
59
120
|
content: Array<Partial<{
|
|
60
121
|
type: "output_text";
|
|
61
122
|
text: string;
|
|
62
|
-
annotations: Array<
|
|
123
|
+
annotations: Array<{
|
|
63
124
|
type: "cloudglue_citation";
|
|
64
125
|
collection_id: string;
|
|
65
126
|
file_id: string;
|
|
66
|
-
segment_id
|
|
127
|
+
segment_id?: string | undefined;
|
|
67
128
|
start_time: number;
|
|
68
|
-
end_time
|
|
69
|
-
context
|
|
70
|
-
relevant_sources
|
|
71
|
-
visual_scene_description
|
|
72
|
-
scene_text
|
|
73
|
-
speech
|
|
74
|
-
audio_description
|
|
75
|
-
}
|
|
129
|
+
end_time?: number | undefined;
|
|
130
|
+
context?: string | undefined;
|
|
131
|
+
relevant_sources?: Array<string> | undefined;
|
|
132
|
+
visual_scene_description?: Array<string> | undefined;
|
|
133
|
+
scene_text?: Array<string> | undefined;
|
|
134
|
+
speech?: Array<string> | undefined;
|
|
135
|
+
audio_description?: Array<string> | undefined;
|
|
136
|
+
}>;
|
|
76
137
|
}>>;
|
|
77
138
|
}>> | null;
|
|
78
139
|
usage: Partial<{
|
|
@@ -86,6 +147,14 @@ export declare class EnhancedResponseApi {
|
|
|
86
147
|
code: string;
|
|
87
148
|
}> | null;
|
|
88
149
|
}>>;
|
|
150
|
+
/**
|
|
151
|
+
* Create a streaming response using the Response API with server-sent events.
|
|
152
|
+
* Returns an async iterable that yields events as they arrive from the server.
|
|
153
|
+
*
|
|
154
|
+
* @param params - Response creation parameters (stream and background are set automatically)
|
|
155
|
+
* @returns Async iterable of streaming events
|
|
156
|
+
*/
|
|
157
|
+
createStreamingResponse(params: Omit<CreateResponseParams, 'stream' | 'background'>): Promise<AsyncIterable<ResponseStreamEventType>>;
|
|
89
158
|
/**
|
|
90
159
|
* List all responses with pagination and filtering options.
|
|
91
160
|
*
|
|
@@ -130,20 +199,20 @@ export declare class EnhancedResponseApi {
|
|
|
130
199
|
content: Array<Partial<{
|
|
131
200
|
type: "output_text";
|
|
132
201
|
text: string;
|
|
133
|
-
annotations: Array<
|
|
202
|
+
annotations: Array<{
|
|
134
203
|
type: "cloudglue_citation";
|
|
135
204
|
collection_id: string;
|
|
136
205
|
file_id: string;
|
|
137
|
-
segment_id
|
|
206
|
+
segment_id?: string | undefined;
|
|
138
207
|
start_time: number;
|
|
139
|
-
end_time
|
|
140
|
-
context
|
|
141
|
-
relevant_sources
|
|
142
|
-
visual_scene_description
|
|
143
|
-
scene_text
|
|
144
|
-
speech
|
|
145
|
-
audio_description
|
|
146
|
-
}
|
|
208
|
+
end_time?: number | undefined;
|
|
209
|
+
context?: string | undefined;
|
|
210
|
+
relevant_sources?: Array<string> | undefined;
|
|
211
|
+
visual_scene_description?: Array<string> | undefined;
|
|
212
|
+
scene_text?: Array<string> | undefined;
|
|
213
|
+
speech?: Array<string> | undefined;
|
|
214
|
+
audio_description?: Array<string> | undefined;
|
|
215
|
+
}>;
|
|
147
216
|
}>>;
|
|
148
217
|
}>> | null;
|
|
149
218
|
usage: Partial<{
|
|
@@ -189,20 +258,20 @@ export declare class EnhancedResponseApi {
|
|
|
189
258
|
content: Array<Partial<{
|
|
190
259
|
type: "output_text";
|
|
191
260
|
text: string;
|
|
192
|
-
annotations: Array<
|
|
261
|
+
annotations: Array<{
|
|
193
262
|
type: "cloudglue_citation";
|
|
194
263
|
collection_id: string;
|
|
195
264
|
file_id: string;
|
|
196
|
-
segment_id
|
|
265
|
+
segment_id?: string | undefined;
|
|
197
266
|
start_time: number;
|
|
198
|
-
end_time
|
|
199
|
-
context
|
|
200
|
-
relevant_sources
|
|
201
|
-
visual_scene_description
|
|
202
|
-
scene_text
|
|
203
|
-
speech
|
|
204
|
-
audio_description
|
|
205
|
-
}
|
|
267
|
+
end_time?: number | undefined;
|
|
268
|
+
context?: string | undefined;
|
|
269
|
+
relevant_sources?: Array<string> | undefined;
|
|
270
|
+
visual_scene_description?: Array<string> | undefined;
|
|
271
|
+
scene_text?: Array<string> | undefined;
|
|
272
|
+
speech?: Array<string> | undefined;
|
|
273
|
+
audio_description?: Array<string> | undefined;
|
|
274
|
+
}>;
|
|
206
275
|
}>>;
|
|
207
276
|
}>> | null;
|
|
208
277
|
usage: Partial<{
|
|
@@ -238,20 +307,20 @@ export declare class EnhancedResponseApi {
|
|
|
238
307
|
content: Array<Partial<{
|
|
239
308
|
type: "output_text";
|
|
240
309
|
text: string;
|
|
241
|
-
annotations: Array<
|
|
310
|
+
annotations: Array<{
|
|
242
311
|
type: "cloudglue_citation";
|
|
243
312
|
collection_id: string;
|
|
244
313
|
file_id: string;
|
|
245
|
-
segment_id
|
|
314
|
+
segment_id?: string | undefined;
|
|
246
315
|
start_time: number;
|
|
247
|
-
end_time
|
|
248
|
-
context
|
|
249
|
-
relevant_sources
|
|
250
|
-
visual_scene_description
|
|
251
|
-
scene_text
|
|
252
|
-
speech
|
|
253
|
-
audio_description
|
|
254
|
-
}
|
|
316
|
+
end_time?: number | undefined;
|
|
317
|
+
context?: string | undefined;
|
|
318
|
+
relevant_sources?: Array<string> | undefined;
|
|
319
|
+
visual_scene_description?: Array<string> | undefined;
|
|
320
|
+
scene_text?: Array<string> | undefined;
|
|
321
|
+
speech?: Array<string> | undefined;
|
|
322
|
+
audio_description?: Array<string> | undefined;
|
|
323
|
+
}>;
|
|
255
324
|
}>>;
|
|
256
325
|
}>> | null;
|
|
257
326
|
usage: Partial<{
|
|
@@ -2,6 +2,69 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EnhancedResponseApi = void 0;
|
|
4
4
|
const error_1 = require("../error");
|
|
5
|
+
/**
|
|
6
|
+
* Process buffered lines, yielding parsed SSE events.
|
|
7
|
+
* Returns true if a [DONE] sentinel was encountered.
|
|
8
|
+
*/
|
|
9
|
+
function* processLines(buffer) {
|
|
10
|
+
let newlineIdx;
|
|
11
|
+
while ((newlineIdx = buffer.value.indexOf('\n')) !== -1) {
|
|
12
|
+
const line = buffer.value.slice(0, newlineIdx).trimEnd();
|
|
13
|
+
buffer.value = buffer.value.slice(newlineIdx + 1);
|
|
14
|
+
// Skip empty lines and event: lines (type is in the JSON data)
|
|
15
|
+
if (!line || line.startsWith('event:')) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (line.startsWith('data: ')) {
|
|
19
|
+
const jsonStr = line.slice(6);
|
|
20
|
+
if (jsonStr === '[DONE]') {
|
|
21
|
+
yield 'DONE';
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
yield JSON.parse(jsonStr);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Skip malformed JSON lines
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse an SSE stream into an async iterable of typed events.
|
|
35
|
+
* Uses the web-standard ReadableStream and TextDecoder APIs for cross-environment compatibility
|
|
36
|
+
* (works in both Node.js 18+ and modern browsers).
|
|
37
|
+
*/
|
|
38
|
+
async function* parseSSEStream(stream) {
|
|
39
|
+
const decoder = new TextDecoder('utf-8');
|
|
40
|
+
const buffer = { value: '' };
|
|
41
|
+
const reader = stream.getReader();
|
|
42
|
+
try {
|
|
43
|
+
while (true) {
|
|
44
|
+
const { done, value } = await reader.read();
|
|
45
|
+
if (done)
|
|
46
|
+
break;
|
|
47
|
+
buffer.value += decoder.decode(value, { stream: true });
|
|
48
|
+
for (const event of processLines(buffer)) {
|
|
49
|
+
if (event === 'DONE')
|
|
50
|
+
return;
|
|
51
|
+
yield event;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Flush any remaining bytes from the decoder and process trailing lines
|
|
55
|
+
buffer.value += decoder.decode();
|
|
56
|
+
if (buffer.value) {
|
|
57
|
+
for (const event of processLines(buffer)) {
|
|
58
|
+
if (event === 'DONE')
|
|
59
|
+
return;
|
|
60
|
+
yield event;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
reader.releaseLock();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
5
68
|
class EnhancedResponseApi {
|
|
6
69
|
constructor(api) {
|
|
7
70
|
this.api = api;
|
|
@@ -16,6 +79,56 @@ class EnhancedResponseApi {
|
|
|
16
79
|
async createResponse(params) {
|
|
17
80
|
return this.api.createResponse(params);
|
|
18
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a streaming response using the Response API with server-sent events.
|
|
84
|
+
* Returns an async iterable that yields events as they arrive from the server.
|
|
85
|
+
*
|
|
86
|
+
* @param params - Response creation parameters (stream and background are set automatically)
|
|
87
|
+
* @returns Async iterable of streaming events
|
|
88
|
+
*/
|
|
89
|
+
async createStreamingResponse(params) {
|
|
90
|
+
const body = {
|
|
91
|
+
...params,
|
|
92
|
+
stream: true,
|
|
93
|
+
background: false,
|
|
94
|
+
};
|
|
95
|
+
const baseURL = this.api.axios.defaults.baseURL;
|
|
96
|
+
const url = `${baseURL}/responses`;
|
|
97
|
+
// Headers are set at the top level of defaults.headers by Object.assign in client.ts
|
|
98
|
+
const h = this.api.axios.defaults.headers;
|
|
99
|
+
const response = await fetch(url, {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: {
|
|
102
|
+
'Content-Type': 'application/json',
|
|
103
|
+
Accept: 'text/event-stream',
|
|
104
|
+
Authorization: h['Authorization'],
|
|
105
|
+
'x-sdk-client': h['x-sdk-client'],
|
|
106
|
+
'x-sdk-version': h['x-sdk-version'],
|
|
107
|
+
},
|
|
108
|
+
body: JSON.stringify(body),
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
let errorMessage = `Request failed with status ${response.status}`;
|
|
112
|
+
let responseData;
|
|
113
|
+
try {
|
|
114
|
+
responseData = await response.json();
|
|
115
|
+
if (typeof responseData?.error === 'string') {
|
|
116
|
+
errorMessage = responseData.error;
|
|
117
|
+
}
|
|
118
|
+
else if (responseData?.error?.message) {
|
|
119
|
+
errorMessage = responseData.error.message;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Could not parse error body
|
|
124
|
+
}
|
|
125
|
+
throw new error_1.CloudGlueError(errorMessage, response.status, JSON.stringify(body), Object.fromEntries(response.headers.entries()), responseData);
|
|
126
|
+
}
|
|
127
|
+
if (!response.body) {
|
|
128
|
+
throw new error_1.CloudGlueError('Response body is empty — streaming not supported in this environment');
|
|
129
|
+
}
|
|
130
|
+
return parseSSEStream(response.body);
|
|
131
|
+
}
|
|
19
132
|
/**
|
|
20
133
|
* List all responses with pagination and filtering options.
|
|
21
134
|
*
|
package/dist/src/client.js
CHANGED
package/dist/src/types.d.ts
CHANGED
|
@@ -311,3 +311,12 @@ export type ResponseUsage = z.infer<typeof responseSchemas.ResponseUsage>;
|
|
|
311
311
|
* Represents knowledge base configuration for the Response API
|
|
312
312
|
*/
|
|
313
313
|
export type ResponseKnowledgeBase = z.infer<typeof responseSchemas.ResponseKnowledgeBase>;
|
|
314
|
+
/**
|
|
315
|
+
* Represents an entity collection configuration for entity-backed knowledge
|
|
316
|
+
*/
|
|
317
|
+
export type EntityCollectionConfig = z.infer<typeof responseSchemas.EntityCollectionConfig>;
|
|
318
|
+
/**
|
|
319
|
+
* Represents the entity-backed knowledge configuration
|
|
320
|
+
*/
|
|
321
|
+
export type EntityBackedKnowledgeConfig = z.infer<typeof responseSchemas.EntityBackedKnowledgeConfig>;
|
|
322
|
+
export type { CreateResponseParams, ListResponsesParams, ResponseCreatedEvent, ResponseOutputItemAddedEvent, ResponseContentPartAddedEvent, ResponseOutputTextDeltaEvent, ResponseOutputTextDoneEvent, ResponseContentPartDoneEvent, ResponseOutputItemDoneEvent, ResponseCompletedEvent, ResponseErrorEvent, ResponseStreamEventType, } from './api/response.api';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aviaryhq/cloudglue-js",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Cloudglue API client for Node.js",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"openapi-zod-client": "^1.18.3",
|
|
42
42
|
"prettier": "^3.7.4",
|
|
43
43
|
"rimraf": "^6.1.2",
|
|
44
|
+
"tsx": "^4.21.0",
|
|
44
45
|
"typescript": "^5.3.3"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|