@bagelink/sdk 1.12.61 → 1.12.71
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.cjs +36 -6
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +36 -6
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/openAPITools/functionGenerator.ts +52 -6
package/dist/index.cjs
CHANGED
|
@@ -606,12 +606,12 @@ function generateStreamTypeName(path) {
|
|
|
606
606
|
path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("_")
|
|
607
607
|
)}StreamEvents`;
|
|
608
608
|
}
|
|
609
|
-
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes) {
|
|
609
|
+
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes, queryParams) {
|
|
610
610
|
if (allParams === "undefined") {
|
|
611
611
|
allParams = "";
|
|
612
612
|
}
|
|
613
613
|
const bodyVar = requestBodyPayload || "{}";
|
|
614
|
-
const baseUrlRef =
|
|
614
|
+
const baseUrlRef = "getStreamBaseURL()";
|
|
615
615
|
const streamTypeName = generateStreamTypeName(path);
|
|
616
616
|
if (eventTypes?.length) {
|
|
617
617
|
streamEventTypes[streamTypeName] = eventTypes;
|
|
@@ -649,6 +649,28 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
649
649
|
}
|
|
650
650
|
}`;
|
|
651
651
|
} else {
|
|
652
|
+
let queryStringCode = "";
|
|
653
|
+
if (queryParams?.length) {
|
|
654
|
+
const paramEntries = queryParams.map((p) => {
|
|
655
|
+
const match = p.match(/^'([^']+)':\s*(.+)$/);
|
|
656
|
+
if (match) return { key: match[1], varName: match[2] };
|
|
657
|
+
return { key: p, varName: p };
|
|
658
|
+
});
|
|
659
|
+
const conditions = paramEntries.map(
|
|
660
|
+
({ key, varName }) => `if (${varName}) __qs.set('${key}', String(${varName}))`
|
|
661
|
+
).join("\n ");
|
|
662
|
+
queryStringCode = [
|
|
663
|
+
`const __qs = new URLSearchParams()`,
|
|
664
|
+
conditions,
|
|
665
|
+
`const __qsSuffix = __qs.size ? "?" + __qs.toString() : ""`
|
|
666
|
+
].join("\n ");
|
|
667
|
+
}
|
|
668
|
+
const regularParamStr = queryParams?.length ? `, { params: {${queryParams.join(", ")}} }` : "";
|
|
669
|
+
const urlLine = queryParams?.length ? `const url = \`\${${baseUrlRef}}${pathForUrl}\` + __qsSuffix` : `const url = \`\${${baseUrlRef}}${pathForUrl}\``;
|
|
670
|
+
const streamBody = queryParams?.length ? `
|
|
671
|
+
${queryStringCode}
|
|
672
|
+
${urlLine}` : `
|
|
673
|
+
${urlLine}`;
|
|
652
674
|
return `{
|
|
653
675
|
/**
|
|
654
676
|
* Stream SSE events from this endpoint (returns StreamController)${eventTypesComment}
|
|
@@ -661,15 +683,14 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
661
683
|
* // Close stream when needed
|
|
662
684
|
* stream.close()
|
|
663
685
|
*/
|
|
664
|
-
stream: (${streamParams}): ${typeAnnotation} => {
|
|
665
|
-
const url = \`\${${baseUrlRef}}${pathForUrl}\`
|
|
686
|
+
stream: (${streamParams}): ${typeAnnotation} => {${streamBody}
|
|
666
687
|
return createSSEStream<${streamTypeName}>(url, options)
|
|
667
688
|
},
|
|
668
689
|
/**
|
|
669
690
|
* Regular GET request (non-streaming)
|
|
670
691
|
*/
|
|
671
692
|
get: async (${regularParams}): Promise<AxiosResponse<any>> => {
|
|
672
|
-
return axios.get(${formattedPath})
|
|
693
|
+
return axios.get(${formattedPath}${regularParamStr})
|
|
673
694
|
}
|
|
674
695
|
}`;
|
|
675
696
|
}
|
|
@@ -781,13 +802,15 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
781
802
|
streamEventSchemas[streamTypeName] = eventSchemas;
|
|
782
803
|
Object.values(eventSchemas).forEach((tsType) => collectTypeForImportStatement(tsType));
|
|
783
804
|
}
|
|
805
|
+
const queryParams = parameters.config?.params ? parameters.config.params.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
784
806
|
return functionComment + generateStreamFunction(
|
|
785
807
|
method,
|
|
786
808
|
path,
|
|
787
809
|
formatPathWithParams(path),
|
|
788
810
|
allParams,
|
|
789
811
|
requestBodyPayload,
|
|
790
|
-
eventTypes
|
|
812
|
+
eventTypes,
|
|
813
|
+
queryParams
|
|
791
814
|
);
|
|
792
815
|
}
|
|
793
816
|
return functionComment + generateAxiosFunction(
|
|
@@ -1052,6 +1075,12 @@ type ApiInstance = typeof api & {
|
|
|
1052
1075
|
// Global state
|
|
1053
1076
|
let apiInstance: ApiInstance | null = null
|
|
1054
1077
|
let apiConfig = ref<ApiConfig | null>(null)
|
|
1078
|
+
let _streamBaseURL: string | undefined
|
|
1079
|
+
|
|
1080
|
+
/** Resolve base URL for SSE stream endpoints. Uses streamBaseURL if set, otherwise falls back to axios baseURL. */
|
|
1081
|
+
export function getStreamBaseURL(): string {
|
|
1082
|
+
return _streamBaseURL || axios.defaults.baseURL || ""
|
|
1083
|
+
}
|
|
1055
1084
|
|
|
1056
1085
|
/**
|
|
1057
1086
|
* Create and configure the API instance
|
|
@@ -1066,6 +1095,7 @@ export function createApi(config: ApiConfig = {}): ApiInstance {
|
|
|
1066
1095
|
if (config.baseURL) {
|
|
1067
1096
|
axios.defaults.baseURL = config.baseURL
|
|
1068
1097
|
}
|
|
1098
|
+
_streamBaseURL = config.streamBaseURL
|
|
1069
1099
|
if (config.withCredentials !== undefined) {
|
|
1070
1100
|
axios.defaults.withCredentials = config.withCredentials
|
|
1071
1101
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -655,6 +655,8 @@ type ResponseInterceptor = (response: AxiosResponse) => AxiosResponse | Promise<
|
|
|
655
655
|
*/
|
|
656
656
|
interface ApiConfig {
|
|
657
657
|
baseURL?: string;
|
|
658
|
+
/** Base URL used for SSE stream endpoints (bypasses proxy). Falls back to baseURL if not set. */
|
|
659
|
+
streamBaseURL?: string;
|
|
658
660
|
withCredentials?: boolean;
|
|
659
661
|
onError?: (error: ParsedError, rawError: any) => void;
|
|
660
662
|
auth?: {
|
package/dist/index.d.mts
CHANGED
|
@@ -655,6 +655,8 @@ type ResponseInterceptor = (response: AxiosResponse) => AxiosResponse | Promise<
|
|
|
655
655
|
*/
|
|
656
656
|
interface ApiConfig {
|
|
657
657
|
baseURL?: string;
|
|
658
|
+
/** Base URL used for SSE stream endpoints (bypasses proxy). Falls back to baseURL if not set. */
|
|
659
|
+
streamBaseURL?: string;
|
|
658
660
|
withCredentials?: boolean;
|
|
659
661
|
onError?: (error: ParsedError, rawError: any) => void;
|
|
660
662
|
auth?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -655,6 +655,8 @@ type ResponseInterceptor = (response: AxiosResponse) => AxiosResponse | Promise<
|
|
|
655
655
|
*/
|
|
656
656
|
interface ApiConfig {
|
|
657
657
|
baseURL?: string;
|
|
658
|
+
/** Base URL used for SSE stream endpoints (bypasses proxy). Falls back to baseURL if not set. */
|
|
659
|
+
streamBaseURL?: string;
|
|
658
660
|
withCredentials?: boolean;
|
|
659
661
|
onError?: (error: ParsedError, rawError: any) => void;
|
|
660
662
|
auth?: {
|
package/dist/index.mjs
CHANGED
|
@@ -600,12 +600,12 @@ function generateStreamTypeName(path) {
|
|
|
600
600
|
path.split("/").filter((p) => p && !/\{|\}/.test(p)).join("_")
|
|
601
601
|
)}StreamEvents`;
|
|
602
602
|
}
|
|
603
|
-
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes) {
|
|
603
|
+
function generateStreamFunction(method, path, formattedPath, allParams, requestBodyPayload, eventTypes, queryParams) {
|
|
604
604
|
if (allParams === "undefined") {
|
|
605
605
|
allParams = "";
|
|
606
606
|
}
|
|
607
607
|
const bodyVar = requestBodyPayload || "{}";
|
|
608
|
-
const baseUrlRef =
|
|
608
|
+
const baseUrlRef = "getStreamBaseURL()";
|
|
609
609
|
const streamTypeName = generateStreamTypeName(path);
|
|
610
610
|
if (eventTypes?.length) {
|
|
611
611
|
streamEventTypes[streamTypeName] = eventTypes;
|
|
@@ -643,6 +643,28 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
643
643
|
}
|
|
644
644
|
}`;
|
|
645
645
|
} else {
|
|
646
|
+
let queryStringCode = "";
|
|
647
|
+
if (queryParams?.length) {
|
|
648
|
+
const paramEntries = queryParams.map((p) => {
|
|
649
|
+
const match = p.match(/^'([^']+)':\s*(.+)$/);
|
|
650
|
+
if (match) return { key: match[1], varName: match[2] };
|
|
651
|
+
return { key: p, varName: p };
|
|
652
|
+
});
|
|
653
|
+
const conditions = paramEntries.map(
|
|
654
|
+
({ key, varName }) => `if (${varName}) __qs.set('${key}', String(${varName}))`
|
|
655
|
+
).join("\n ");
|
|
656
|
+
queryStringCode = [
|
|
657
|
+
`const __qs = new URLSearchParams()`,
|
|
658
|
+
conditions,
|
|
659
|
+
`const __qsSuffix = __qs.size ? "?" + __qs.toString() : ""`
|
|
660
|
+
].join("\n ");
|
|
661
|
+
}
|
|
662
|
+
const regularParamStr = queryParams?.length ? `, { params: {${queryParams.join(", ")}} }` : "";
|
|
663
|
+
const urlLine = queryParams?.length ? `const url = \`\${${baseUrlRef}}${pathForUrl}\` + __qsSuffix` : `const url = \`\${${baseUrlRef}}${pathForUrl}\``;
|
|
664
|
+
const streamBody = queryParams?.length ? `
|
|
665
|
+
${queryStringCode}
|
|
666
|
+
${urlLine}` : `
|
|
667
|
+
${urlLine}`;
|
|
646
668
|
return `{
|
|
647
669
|
/**
|
|
648
670
|
* Stream SSE events from this endpoint (returns StreamController)${eventTypesComment}
|
|
@@ -655,15 +677,14 @@ function generateStreamFunction(method, path, formattedPath, allParams, requestB
|
|
|
655
677
|
* // Close stream when needed
|
|
656
678
|
* stream.close()
|
|
657
679
|
*/
|
|
658
|
-
stream: (${streamParams}): ${typeAnnotation} => {
|
|
659
|
-
const url = \`\${${baseUrlRef}}${pathForUrl}\`
|
|
680
|
+
stream: (${streamParams}): ${typeAnnotation} => {${streamBody}
|
|
660
681
|
return createSSEStream<${streamTypeName}>(url, options)
|
|
661
682
|
},
|
|
662
683
|
/**
|
|
663
684
|
* Regular GET request (non-streaming)
|
|
664
685
|
*/
|
|
665
686
|
get: async (${regularParams}): Promise<AxiosResponse<any>> => {
|
|
666
|
-
return axios.get(${formattedPath})
|
|
687
|
+
return axios.get(${formattedPath}${regularParamStr})
|
|
667
688
|
}
|
|
668
689
|
}`;
|
|
669
690
|
}
|
|
@@ -775,13 +796,15 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
775
796
|
streamEventSchemas[streamTypeName] = eventSchemas;
|
|
776
797
|
Object.values(eventSchemas).forEach((tsType) => collectTypeForImportStatement(tsType));
|
|
777
798
|
}
|
|
799
|
+
const queryParams = parameters.config?.params ? parameters.config.params.split(",").map((p) => p.trim()).filter(Boolean) : void 0;
|
|
778
800
|
return functionComment + generateStreamFunction(
|
|
779
801
|
method,
|
|
780
802
|
path,
|
|
781
803
|
formatPathWithParams(path),
|
|
782
804
|
allParams,
|
|
783
805
|
requestBodyPayload,
|
|
784
|
-
eventTypes
|
|
806
|
+
eventTypes,
|
|
807
|
+
queryParams
|
|
785
808
|
);
|
|
786
809
|
}
|
|
787
810
|
return functionComment + generateAxiosFunction(
|
|
@@ -1046,6 +1069,12 @@ type ApiInstance = typeof api & {
|
|
|
1046
1069
|
// Global state
|
|
1047
1070
|
let apiInstance: ApiInstance | null = null
|
|
1048
1071
|
let apiConfig = ref<ApiConfig | null>(null)
|
|
1072
|
+
let _streamBaseURL: string | undefined
|
|
1073
|
+
|
|
1074
|
+
/** Resolve base URL for SSE stream endpoints. Uses streamBaseURL if set, otherwise falls back to axios baseURL. */
|
|
1075
|
+
export function getStreamBaseURL(): string {
|
|
1076
|
+
return _streamBaseURL || axios.defaults.baseURL || ""
|
|
1077
|
+
}
|
|
1049
1078
|
|
|
1050
1079
|
/**
|
|
1051
1080
|
* Create and configure the API instance
|
|
@@ -1060,6 +1089,7 @@ export function createApi(config: ApiConfig = {}): ApiInstance {
|
|
|
1060
1089
|
if (config.baseURL) {
|
|
1061
1090
|
axios.defaults.baseURL = config.baseURL
|
|
1062
1091
|
}
|
|
1092
|
+
_streamBaseURL = config.streamBaseURL
|
|
1063
1093
|
if (config.withCredentials !== undefined) {
|
|
1064
1094
|
axios.defaults.withCredentials = config.withCredentials
|
|
1065
1095
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -302,6 +302,8 @@ export type ResponseInterceptor = (response: AxiosResponse) => AxiosResponse | P
|
|
|
302
302
|
*/
|
|
303
303
|
export interface ApiConfig {
|
|
304
304
|
baseURL?: string
|
|
305
|
+
/** Base URL used for SSE stream endpoints (bypasses proxy). Falls back to baseURL if not set. */
|
|
306
|
+
streamBaseURL?: string
|
|
305
307
|
withCredentials?: boolean
|
|
306
308
|
onError?: (error: ParsedError, rawError: any) => void
|
|
307
309
|
auth?: {
|
|
@@ -401,6 +401,7 @@ function generateStreamTypeName(path: string): string {
|
|
|
401
401
|
* @param allParams - The combined parameter string
|
|
402
402
|
* @param requestBodyPayload - The request body payload
|
|
403
403
|
* @param eventTypes - Array of SSE event types
|
|
404
|
+
* @param queryParams - Query/header parameter mappings (e.g. "'run_id': _runId")
|
|
404
405
|
* @returns A string with the SSE stream function
|
|
405
406
|
*/
|
|
406
407
|
function generateStreamFunction(
|
|
@@ -409,7 +410,8 @@ function generateStreamFunction(
|
|
|
409
410
|
formattedPath: string,
|
|
410
411
|
allParams: string,
|
|
411
412
|
requestBodyPayload: string,
|
|
412
|
-
eventTypes?: string[]
|
|
413
|
+
eventTypes?: string[],
|
|
414
|
+
queryParams?: string[]
|
|
413
415
|
): string {
|
|
414
416
|
if (allParams === 'undefined') { allParams = '' }
|
|
415
417
|
|
|
@@ -417,7 +419,7 @@ function generateStreamFunction(
|
|
|
417
419
|
// const paramNames = allParams ? allParams.match(/\w+(?=\s*[?:])/g) || [] : []
|
|
418
420
|
|
|
419
421
|
const bodyVar = requestBodyPayload || '{}'
|
|
420
|
-
const baseUrlRef = '
|
|
422
|
+
const baseUrlRef = 'getStreamBaseURL()'
|
|
421
423
|
|
|
422
424
|
// Generate type name for this stream
|
|
423
425
|
const streamTypeName = generateStreamTypeName(path)
|
|
@@ -473,6 +475,38 @@ function generateStreamFunction(
|
|
|
473
475
|
}
|
|
474
476
|
}`
|
|
475
477
|
} else {
|
|
478
|
+
// Build query string construction for GET SSE streams
|
|
479
|
+
let queryStringCode = ''
|
|
480
|
+
if (queryParams?.length) {
|
|
481
|
+
// Generate URLSearchParams code to append query params to the SSE URL
|
|
482
|
+
// Query params use 'original_name': varName mapping format
|
|
483
|
+
const paramEntries = queryParams.map(p => {
|
|
484
|
+
const match = p.match(/^'([^']+)':\s*(.+)$/)
|
|
485
|
+
if (match) return { key: match[1], varName: match[2] }
|
|
486
|
+
// Simple case: param name is the same as var name
|
|
487
|
+
return { key: p, varName: p }
|
|
488
|
+
})
|
|
489
|
+
const conditions = paramEntries.map(({ key, varName }) =>
|
|
490
|
+
`if (${varName}) __qs.set('${key}', String(${varName}))`
|
|
491
|
+
).join('\n ')
|
|
492
|
+
queryStringCode = [
|
|
493
|
+
`const __qs = new URLSearchParams()`,
|
|
494
|
+
conditions,
|
|
495
|
+
`const __qsSuffix = __qs.size ? "?" + __qs.toString() : ""`,
|
|
496
|
+
].join('\n ')
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const regularParamStr = queryParams?.length ? `, { params: {${queryParams.join(', ')}} }` : ''
|
|
500
|
+
|
|
501
|
+
// For GET streams with query params, build URL with suffix; otherwise plain URL
|
|
502
|
+
const urlLine = queryParams?.length
|
|
503
|
+
? `const url = \`\${${baseUrlRef}}${pathForUrl}\` + __qsSuffix`
|
|
504
|
+
: `const url = \`\${${baseUrlRef}}${pathForUrl}\``
|
|
505
|
+
|
|
506
|
+
const streamBody = queryParams?.length
|
|
507
|
+
? `\n ${queryStringCode}\n ${urlLine}`
|
|
508
|
+
: `\n ${urlLine}`
|
|
509
|
+
|
|
476
510
|
return `{
|
|
477
511
|
/**
|
|
478
512
|
* Stream SSE events from this endpoint (returns StreamController)${eventTypesComment}
|
|
@@ -485,15 +519,14 @@ function generateStreamFunction(
|
|
|
485
519
|
* // Close stream when needed
|
|
486
520
|
* stream.close()
|
|
487
521
|
*/
|
|
488
|
-
stream: (${streamParams}): ${typeAnnotation} => {
|
|
489
|
-
const url = \`\${${baseUrlRef}}${pathForUrl}\`
|
|
522
|
+
stream: (${streamParams}): ${typeAnnotation} => {${streamBody}
|
|
490
523
|
return createSSEStream<${streamTypeName}>(url, options)
|
|
491
524
|
},
|
|
492
525
|
/**
|
|
493
526
|
* Regular GET request (non-streaming)
|
|
494
527
|
*/
|
|
495
528
|
get: async (${regularParams}): Promise<AxiosResponse<any>> => {
|
|
496
|
-
return axios.get(${formattedPath})
|
|
529
|
+
return axios.get(${formattedPath}${regularParamStr})
|
|
497
530
|
}
|
|
498
531
|
}`
|
|
499
532
|
}
|
|
@@ -690,13 +723,19 @@ function generateFunctionForOperation(
|
|
|
690
723
|
Object.values(eventSchemas).forEach(tsType => collectTypeForImportStatement(tsType))
|
|
691
724
|
}
|
|
692
725
|
|
|
726
|
+
// Extract query param mappings for GET SSE streams (e.g. "'run_id': _runId")
|
|
727
|
+
const queryParams = parameters.config?.params
|
|
728
|
+
? parameters.config.params.split(',').map(p => p.trim()).filter(Boolean)
|
|
729
|
+
: undefined
|
|
730
|
+
|
|
693
731
|
return functionComment + generateStreamFunction(
|
|
694
732
|
method,
|
|
695
733
|
path,
|
|
696
734
|
formatPathWithParams(path),
|
|
697
735
|
allParams,
|
|
698
736
|
requestBodyPayload,
|
|
699
|
-
eventTypes
|
|
737
|
+
eventTypes,
|
|
738
|
+
queryParams
|
|
700
739
|
)
|
|
701
740
|
}
|
|
702
741
|
|
|
@@ -1055,6 +1094,12 @@ type ApiInstance = typeof api & {
|
|
|
1055
1094
|
// Global state
|
|
1056
1095
|
let apiInstance: ApiInstance | null = null
|
|
1057
1096
|
let apiConfig = ref<ApiConfig | null>(null)
|
|
1097
|
+
let _streamBaseURL: string | undefined
|
|
1098
|
+
|
|
1099
|
+
/** Resolve base URL for SSE stream endpoints. Uses streamBaseURL if set, otherwise falls back to axios baseURL. */
|
|
1100
|
+
export function getStreamBaseURL(): string {
|
|
1101
|
+
return _streamBaseURL || axios.defaults.baseURL || ""
|
|
1102
|
+
}
|
|
1058
1103
|
|
|
1059
1104
|
/**
|
|
1060
1105
|
* Create and configure the API instance
|
|
@@ -1069,6 +1114,7 @@ export function createApi(config: ApiConfig = {}): ApiInstance {
|
|
|
1069
1114
|
if (config.baseURL) {
|
|
1070
1115
|
axios.defaults.baseURL = config.baseURL
|
|
1071
1116
|
}
|
|
1117
|
+
_streamBaseURL = config.streamBaseURL
|
|
1072
1118
|
if (config.withCredentials !== undefined) {
|
|
1073
1119
|
axios.defaults.withCredentials = config.withCredentials
|
|
1074
1120
|
}
|