Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ jobs:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bunx tsc --noEmit
- run: bun run lint
- run: bun test ./src
- run: bunx prettier --check src
- run: bunx prettier --check .
- run: bun run build
- name: Pack and import on Node
run: |
Expand Down
214 changes: 204 additions & 10 deletions bun.lock

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as eslint from "@eslint/js";
import * as tseslint from "typescript-eslint";
import { defineConfig, globalIgnores } from "eslint/config";

export default defineConfig(
eslint.configs.recommended,
tseslint.configs.strict,
tseslint.configs.stylistic,
globalIgnores(["**/dist/**", "tmp/**"]),
{
linterOptions: {
reportUnusedDisableDirectives: "warn",
},
rules: {
"no-console": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-unused-expressions": [
"error",
{ allowTaggedTemplates: true },
],
"@typescript-eslint/consistent-type-definitions": 0,
"@typescript-eslint/no-unsafe-type-assertion": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
},
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ["eslint.config.ts"],
},
tsconfigRootDir: import.meta.dirname,
},
},
},
);
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"build": "tsc -p tsconfig.build.json",
"prepack": "bun run build",
"typecheck": "tsc --noEmit",
"lint": "eslint .",
"test": "bun test ./src",
"test:e2e": "bun test ./tests",
"format": "prettier -w ."
Expand All @@ -30,12 +31,16 @@
"@intx/types": "^0.4.0"
},
"devDependencies": {
"@eslint/js": "10.0.1",
"@intx/inference": "0.4.0",
"@intx/inference-testing": "0.4.0",
"@intx/types": "0.4.0",
"@types/bun": "1.3.9",
"eslint": "10.10.0",
"jiti": "2.7.0",
"prettier": "3.6.2",
"typescript": "5.9.3"
"typescript": "5.9.3",
"typescript-eslint": "8.69.0"
},
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion src/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type RerankRequestBuilder = (
*/
export type RerankResponseParser = (
body: unknown,
) => Array<{ index: number; score: number }>;
) => { index: number; score: number }[];

/**
* One rerank wire format: how to build the request and how to read the reply.
Expand Down
33 changes: 19 additions & 14 deletions src/rerank.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ describe("retry", () => {
const error = await rerank({ baseURL: BASE_URL, apiStyle: "tei" });

expect(error).toBeInstanceOf(RerankRequestError);
expect((error as RerankRequestError).reason.category).toBe(
"credential_failure",
);
expect((error as RerankRequestError).url).toBe(`${BASE_URL}/rerank`);
expect(error).toMatchObject({
reason: { category: "credential_failure" },
url: `${BASE_URL}/rerank`,
});
expect(harness.scenario.matchedRequests()).toHaveLength(1);
});

Expand Down Expand Up @@ -183,9 +183,7 @@ describe("errors", () => {
const error = await rerank({ baseURL: BASE_URL, apiStyle: "tei" });

expect(error).toBeInstanceOf(RerankRequestError);
expect((error as RerankRequestError).reason.category).toBe(
"protocol_mismatch",
);
expect(error).toMatchObject({ reason: { category: "protocol_mismatch" } });
});

test("an out-of-range index is a protocol mismatch", async () => {
Expand All @@ -195,9 +193,11 @@ describe("errors", () => {
const error = await rerank({ baseURL: BASE_URL, apiStyle: "tei" });

expect(error).toBeInstanceOf(RerankRequestError);
expect((error as RerankRequestError).reason.message).toBe(
"rerank response index 99 out of bounds for 3 documents",
);
expect(error).toMatchObject({
reason: {
message: "rerank response index 99 out of bounds for 3 documents",
},
});
});

test.each(["cohere", "voyage"])(
Expand All @@ -206,7 +206,8 @@ describe("errors", () => {
setup();
const error = await rerank({ baseURL: BASE_URL, apiStyle });

expect((error as Error).message).toBe(
expect(error).toHaveProperty(
"message",
"model must be a string (was undefined)",
);
expect(harness.scenario.matchedRequests()).toHaveLength(0);
Expand All @@ -221,16 +222,20 @@ describe("errors", () => {
timeoutMs: 0,
});

expect((error as Error).message).toBe("timeoutMs must be positive (was 0)");
expect(error).toHaveProperty(
"message",
"timeoutMs must be positive (was 0)",
);
expect(harness.scenario.matchedRequests()).toHaveLength(0);
});

test("an unknown apiStyle, including an inherited name, fails by name", async () => {
setup();
for (const apiStyle of ["nope", "toString"]) {
const error = await rerank({ baseURL: BASE_URL, apiStyle });
expect((error as Error).message).toMatch(
`Unknown rerank API style "${apiStyle}"`,
expect(error).toHaveProperty(
"message",
expect.stringContaining(`Unknown rerank API style "${apiStyle}"`),
);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/rerank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function rerankDocuments(
signal: options.signal,
});

let scored: Array<{ index: number; score: number }>;
let scored: { index: number; score: number }[];
try {
scored = adapter.parseResponse(body);
} catch (cause) {
Expand Down
Loading