Skip to content

Commit 4d86f85

Browse files
authored
Merge pull request #26 from datastax/fix-ragstack
fix ragstack user agent detection
2 parents 5ac2361 + 6f42e13 commit 4d86f85

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/api/constants.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
import { LIB_NAME, LIB_VERSION } from '@/src/version';
1616

17-
export const RAG_STACK_REQUESTED_WITH = (() => {
17+
export const RAGSTACK_REQUESTED_WITH = (() => {
1818
try {
19-
// eslint-disable-next-line @typescript-eslint/no-var-requires
20-
const lib = require('ragstack-ai');
21-
22-
if (!lib['LIB_NAME'] || !lib['LIB_VERSION']) {
23-
return '';
24-
}
25-
return lib['LIB_NAME'] + '/' + lib['LIB_VERSION'];
19+
/**
20+
* Do not use require() here, it will break the build in some environments such as NextJS application^M
21+
* if @datastax/ragstack-ai is not installed (which is perfectly fine).
22+
*/
23+
const ragstack = eval(`require('@datastax/ragstack-ai')`);
24+
const version = ragstack['RAGSTACK_VERSION'] || "?";
25+
return `ragstack-ai-ts/${version}`
2626
} catch (e) {
2727
return '';
2828
}

src/api/http-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { CLIENT_USER_AGENT, RAG_STACK_REQUESTED_WITH } from '@/src/api/constants';
15+
import { CLIENT_USER_AGENT, RAGSTACK_REQUESTED_WITH } from '@/src/api/constants';
1616
import { HTTPRequestInfo, InternalFetchCtx, InternalHTTPClientOptions, ResponseWithBody } from '@/src/api/types';
1717
import { Caller, DataAPIClientEvents } from '@/src/client';
1818
import TypedEmitter from 'typed-emitter';
@@ -104,5 +104,5 @@ export function buildUserAgent(caller: Caller | Caller[] | undefined): string {
104104
return c[1] ? `${c[0]}/${c[1]}` : c[0];
105105
}).join(' ');
106106

107-
return `${RAG_STACK_REQUESTED_WITH} ${callerString} ${CLIENT_USER_AGENT}`.trim();
107+
return `${RAGSTACK_REQUESTED_WITH} ${callerString} ${CLIENT_USER_AGENT}`.trim();
108108
}

0 commit comments

Comments
 (0)