Skip to content

[WIP] Suffix all imports with .js #1491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
11,055 changes: 11,055 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion packages/agents/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from "./src";
export { HfAgent } from "./src/HfAgent.js";
export { defaultTools } from "./src/tools/index.js";
export { LLMFromHub, LLMFromEndpoint } from "./src/llms/LLMHF.js";
export type { LLM, Tool, Update, Data } from "./src/types.js";
14 changes: 7 additions & 7 deletions packages/agents/src/HfAgent.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do NOT change the quote to single quotes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in any file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the quote style back to double quotes while maintaining the correct import path. The changes can be seen in commit 2cde019.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the quote style in all files back to double quotes while maintaining the correct .js suffix in imports. This change is in commit 52a781d.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol @julien-c can probably just run the formatter to fix it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't have a local computer anymore :/

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { evalBuilder } from "./lib/evalBuilder";
import { generateCode } from "./lib/generateCode";
import { defaultTools } from "./tools";
import type { LLM, Tool, Update } from "./types";
import { LLMFromHub } from "./llms/LLMHF";
import { generatePrompt } from "./lib/promptGeneration";
import { messageTool } from "./tools/message";
import { evalBuilder } from "./lib/evalBuilder.js";
import { generateCode } from "./lib/generateCode.js";
import { defaultTools } from "./tools/index.js";
import type { LLM, Tool, Update } from "./types.js";
import { LLMFromHub } from "./llms/LLMHF.js";
import { generatePrompt } from "./lib/promptGeneration.js";
import { messageTool } from "./tools/message.js";

export class HfAgent {
private accessToken: string;
6 changes: 3 additions & 3 deletions packages/agents/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { HfAgent } from "./HfAgent";
export * from "./tools";
export * from "./llms";
export { HfAgent } from "./HfAgent.js";
export * from "./tools/index.js";
export * from "./llms/LLMHF.js";
2 changes: 1 addition & 1 deletion packages/agents/src/lib/evalBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InferenceClient } from "@huggingface/inference";
import type { Data, Tool } from "../types";
import type { Data, Tool } from "../types.js";

// this function passes the tools & files to the context before calling eval
export async function evalBuilder(
2 changes: 1 addition & 1 deletion packages/agents/src/lib/examples.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Example } from "../types";
import type { Example } from "../types.js";

const examples: Example[] = [
{
6 changes: 3 additions & 3 deletions packages/agents/src/lib/generateCode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Tool } from "../types";
import type { Tool } from "../types.js";

import { generatePrompt } from "./promptGeneration";
import { messageTool } from "../tools/message";
import { generatePrompt } from "./promptGeneration.js";
import { messageTool } from "../tools/message.js";

export async function generateCode(
prompt: string,
4 changes: 2 additions & 2 deletions packages/agents/src/lib/promptGeneration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Inputs, Tool } from "../types";
import examples from "./examples";
import type { Inputs, Tool } from "../types.js";
import examples from "./examples.js";

function toolDescription(tool: Tool) {
let prompt = `name: ${tool.name} \ndescription: ${tool.description}`;
2 changes: 1 addition & 1 deletion packages/agents/src/llms/LLMHF.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LLM } from "../types";
import type { LLM } from "../types.js";
import { InferenceClient } from "@huggingface/inference";

export function LLMFromHub(accessToken?: string, model?: string): LLM {
2 changes: 1 addition & 1 deletion packages/agents/src/llms/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { LLMFromHub, LLMFromEndpoint } from "./LLMHF";
export { LLMFromHub, LLMFromEndpoint } from "./LLMHF.js";
2 changes: 1 addition & 1 deletion packages/agents/src/tools/imageToText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Tool } from "../types";
import type { Tool } from "../types.js";

export const imageToTextTool: Tool = {
name: "imageToText",
18 changes: 9 additions & 9 deletions packages/agents/src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { textToImageTool } from "./textToImage";
import { imageToTextTool } from "./imageToText";
import { textToSpeechTool } from "./textToSpeech";
import { speechToTextTool } from "./speechToText";
import type { Tool } from "../types";
import { textToImageTool } from "./textToImage.js";
import { imageToTextTool } from "./imageToText.js";
import { textToSpeechTool } from "./textToSpeech.js";
import { speechToTextTool } from "./speechToText.js";
import type { Tool } from "../types.js";

export const defaultTools: Array<Tool> = [textToImageTool, imageToTextTool, textToSpeechTool, speechToTextTool];

export { textToImageTool } from "./textToImage";
export { imageToTextTool } from "./imageToText";
export { textToSpeechTool } from "./textToSpeech";
export { speechToTextTool } from "./speechToText";
export { textToImageTool } from "./textToImage.js";
export { imageToTextTool } from "./imageToText.js";
export { textToSpeechTool } from "./textToSpeech.js";
export { speechToTextTool } from "./speechToText.js";
2 changes: 1 addition & 1 deletion packages/agents/src/tools/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Tool } from "../types";
import type { Tool } from "../types.js";

export const messageTool: Tool = {
name: "message",
2 changes: 1 addition & 1 deletion packages/agents/src/tools/speechToText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Tool } from "../types";
import type { Tool } from "../types.js";

export const speechToTextTool: Tool = {
name: "speechToText",
2 changes: 1 addition & 1 deletion packages/agents/src/tools/textToImage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Tool } from "../types";
import type { Tool } from "../types.js";

export const textToImageTool: Tool = {
name: "textToImage",
2 changes: 1 addition & 1 deletion packages/agents/src/tools/textToSpeech.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Tool } from "../types";
import type { Tool } from "../types.js";

export const textToSpeechTool: Tool = {
name: "textToSpeech",
6 changes: 4 additions & 2 deletions packages/agents/test/HfAgent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, it } from "vitest";
import { HfAgent, defaultTools, LLMFromHub, LLMFromEndpoint } from "../src";
import type { Data } from "../src/types";
import { HfAgent } from "../src/HfAgent.js";
import { defaultTools } from "../src/tools/index.js";
import { LLMFromHub, LLMFromEndpoint } from "../src/llms/LLMHF.js";
import type { Data } from "../src/types.js";
import type { InferenceClient } from "@huggingface/inference";

const env = import.meta.env;
1 change: 1 addition & 0 deletions packages/agents/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { defaultTools } from "./src/tools/index.js";
2 changes: 1 addition & 1 deletion packages/blob/src/utils/FileBlob.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { open, stat } from "node:fs/promises";
import { TextDecoder } from "node:util";
import { describe, expect, it } from "vitest";
import { FileBlob } from "./FileBlob";
import { FileBlob } from "./FileBlob.js";

describe("FileBlob", () => {
it("should create a FileBlob with a slice on the entire file", async () => {
2 changes: 1 addition & 1 deletion packages/blob/src/utils/WebBlob.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, beforeAll } from "vitest";
import { WebBlob } from "./WebBlob";
import { WebBlob } from "./WebBlob.js";

describe("WebBlob", () => {
const resourceUrl = new URL("https://huggingface.co/spaces/aschen/push-model-from-web/raw/main/mobilenet/model.json");
4 changes: 2 additions & 2 deletions packages/blob/src/utils/createBlob.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WebBlob } from "./WebBlob";
import { isFrontend } from "./isFrontend";
import { WebBlob } from "./WebBlob.js";
import { isFrontend } from "./isFrontend.js";

/**
* This function allow to retrieve either a FileBlob or a WebBlob from a URL.
2 changes: 1 addition & 1 deletion packages/blob/src/utils/isFrontend.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { isBackend } from "./isBackend";
import { isBackend } from "./isBackend.js";

export const isFrontend = !isBackend;
2 changes: 1 addition & 1 deletion packages/dduf/src/check-dduf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { checkDDUF, type DDUFFileEntry } from "./check-dduf";
import { checkDDUF, type DDUFFileEntry } from "./check-dduf.js";

describe("check-dduf", () => {
it("should work", async () => {
2 changes: 1 addition & 1 deletion packages/dduf/src/check-dduf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkFilename } from "./check-filename";
import { checkFilename } from "./check-filename.js";
import { createBlob } from "@huggingface/blob";

export interface DDUFFileEntry {
2 changes: 1 addition & 1 deletion packages/gguf/scripts/generate-llm.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ const DEST_FILE_PATH = "./src/transformer-llm.ts";
const DEST_COMMON_SOURCE = `
/** This file is auto-generated by generate-llm.ts */

import type { ModelBase, GGUFGeneralInfo } from "./types";
import type { ModelBase, GGUFGeneralInfo } from "./types.js";

type LLMBase<TArchitecture extends string> = Partial<Record<
\`\${TArchitecture}.vocab_size\`
6 changes: 3 additions & 3 deletions packages/gguf/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import type { GGUFParseOutput } from ".";
import { GGMLQuantizationType, ggufAllShards } from ".";
import { GGML_QUANT_SIZES } from "./quant-descriptions";
import type { GGUFParseOutput } from "..js";
import { GGMLQuantizationType, ggufAllShards } from "..js";
import { GGML_QUANT_SIZES } from "./quant-descriptions.js";

interface PrintColumnHeader {
name: string;
2 changes: 1 addition & 1 deletion packages/gguf/src/gguf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, describe, expect, it } from "vitest";
import type { GGUFParseOutput } from "./gguf";
import type { GGUFParseOutput } from "./gguf.js";
import {
GGMLFileQuantizationType,
GGMLQuantizationType,
8 changes: 4 additions & 4 deletions packages/gguf/src/gguf.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MetadataValue, Version, GGUFMetadata, GGUFTensorInfo, GGUFParseOutput } from "./types";
import { GGUFValueType } from "./types";
import { isBackend } from "./utils/isBackend";
import { promisesQueue } from "./utils/promisesQueue";
import type { MetadataValue, Version, GGUFMetadata, GGUFTensorInfo, GGUFParseOutput } from "./types.js";
import { GGUFValueType } from "./types.js";
import { isBackend } from "./utils/isBackend.js";
import { promisesQueue } from "./utils/promisesQueue.js";

export type { MetadataBaseValue, MetadataValue, Version, GGUFMetadata, GGUFTensorInfo, GGUFParseOutput } from "./types";
export { GGUFValueType, GGMLQuantizationType, Architecture } from "./types";
2 changes: 1 addition & 1 deletion packages/gguf/src/quant-descriptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GGMLQuantizationType } from "./types";
import { GGMLQuantizationType } from "./types.js";

export const GGUF_QUANT_DESCRIPTIONS: Record<GGMLQuantizationType, { txt: string; src_url?: string }> = {
[GGMLQuantizationType.F32]: {
2 changes: 1 addition & 1 deletion packages/gguf/src/transformer-llm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** This file is auto-generated by generate-llm.ts */

import type { ModelBase, GGUFGeneralInfo } from "./types";
import type { ModelBase, GGUFGeneralInfo } from "./types.js";

type LLMBase<TArchitecture extends string> = Partial<
Record<
4 changes: 2 additions & 2 deletions packages/gguf/src/types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from "vitest";
import type { gguf } from "./gguf";
import type { GGUFMetadata, GGUFParseOutput } from "./types";
import type { gguf } from "./gguf.js";
import type { GGUFMetadata, GGUFParseOutput } from "./types.js";

describe("gguf-types", () => {
it("gguf() type can be casted between STRICT and NON_STRICT (at compile time)", async () => {
4 changes: 2 additions & 2 deletions packages/gguf/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TransformerLLM } from "./transformer-llm";
import { LLM_ARCHITECTURES } from "./transformer-llm";
import type { TransformerLLM } from "./transformer-llm.js";
import { LLM_ARCHITECTURES } from "./transformer-llm.js";
import type { GGMLQuantizationType, GGMLFileQuantizationType } from "@huggingface/tasks";
export { GGMLQuantizationType } from "@huggingface/tasks";

6 changes: 3 additions & 3 deletions packages/hub/cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#! /usr/bin/env node

import { parseArgs } from "node:util";
import { typedEntries } from "./src/utils/typedEntries";
import { createBranch, createRepo, deleteBranch, repoExists, uploadFilesWithProgress } from "./src";
import { typedEntries } from "./src/utils/typedEntries.js";
import { createBranch, createRepo, deleteBranch, repoExists, uploadFilesWithProgress } from "./index.js";
import { pathToFileURL } from "node:url";
import { stat } from "node:fs/promises";
import { basename, join } from "node:path";
import { HUB_URL } from "./src/consts";
import { HUB_URL } from "./src/consts.js";
import { version } from "./package.json";

// Didn't find the import from "node:util", so duplicated it here
2 changes: 1 addition & 1 deletion packages/hub/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonObject } from "./vendor/type-fest/basic";
import type { JsonObject } from "./vendor/type-fest/basic.js";

export async function createApiError(
response: Response,
2 changes: 1 addition & 1 deletion packages/hub/src/lib/cache-management.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { homedir } from "node:os";
import { join, basename } from "node:path";
import { stat, readdir, readFile, realpath, lstat } from "node:fs/promises";
import type { Stats } from "node:fs";
import type { RepoType, RepoId } from "../types/public";
import type { RepoType, RepoId } from "../types/public.js";

function getDefaultHome(): string {
return join(homedir(), ".cache");
6 changes: 3 additions & 3 deletions packages/hub/src/lib/check-repo-access.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, describe, expect, it } from "vitest";
import { checkRepoAccess } from "./check-repo-access";
import { HubApiError } from "../error";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL } from "../test/consts";
import { checkRepoAccess } from "./check-repo-access.js";
import { HubApiError } from "../error.js";
import { TEST_ACCESS_TOKEN, TEST_HUB_URL } from "../test/consts.js";

describe("checkRepoAccess", () => {
it("should throw 401 when accessing unexisting repo unauthenticated", async () => {
10 changes: 5 additions & 5 deletions packages/hub/src/lib/check-repo-access.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HUB_URL } from "../consts";
import { HUB_URL } from "../consts.js";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { createApiError, type HubApiError } from "../error";
import type { CredentialsParams, RepoDesignation } from "../types/public";
import { checkCredentials } from "../utils/checkCredentials";
import { toRepoId } from "../utils/toRepoId";
import { createApiError, type HubApiError } from "../error.js";
import type { CredentialsParams, RepoDesignation } from "../types/public.js";
import { checkCredentials } from "../utils/checkCredentials.js";
import { toRepoId } from "../utils/toRepoId.js";

/**
* Check if we have read access to a repository.
20 changes: 10 additions & 10 deletions packages/hub/src/lib/commit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { assert, it, describe } from "vitest";

import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../test/consts";
import type { RepoId } from "../types/public";
import type { CommitFile } from "./commit";
import { commit } from "./commit";
import { createRepo } from "./create-repo";
import { deleteRepo } from "./delete-repo";
import { downloadFile } from "./download-file";
import { fileDownloadInfo } from "./file-download-info";
import { insecureRandomString } from "../utils/insecureRandomString";
import { isFrontend } from "../utils/isFrontend";
import { TEST_HUB_URL, TEST_ACCESS_TOKEN, TEST_USER } from "../test/consts.js";
import type { RepoId } from "../types/public.js";
import type { CommitFile } from "./commit.js";
import { commit } from "./commit.js";
import { createRepo } from "./create-repo.js";
import { deleteRepo } from "./delete-repo.js";
import { downloadFile } from "./download-file.js";
import { fileDownloadInfo } from "./file-download-info.js";
import { insecureRandomString } from "../utils/insecureRandomString.js";
import { isFrontend } from "../utils/isFrontend.js";

const lfsContent = "O123456789".repeat(100_000);

28 changes: 14 additions & 14 deletions packages/hub/src/lib/commit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HUB_URL } from "../consts";
import { HubApiError, createApiError, InvalidApiResponseFormatError } from "../error";
import { HUB_URL } from "../consts.js";
import { HubApiError, createApiError, InvalidApiResponseFormatError } from "../error.js";
import type {
ApiCommitHeader,
ApiCommitLfsFile,
@@ -10,18 +10,18 @@ import type {
ApiPreuploadRequest,
ApiPreuploadResponse,
} from "../types/api/api-commit";
import type { CredentialsParams, RepoDesignation } from "../types/public";
import { checkCredentials } from "../utils/checkCredentials";
import { chunk } from "../utils/chunk";
import { promisesQueue } from "../utils/promisesQueue";
import { promisesQueueStreaming } from "../utils/promisesQueueStreaming";
import { sha256 } from "../utils/sha256";
import { toRepoId } from "../utils/toRepoId";
import { WebBlob } from "../utils/WebBlob";
import { eventToGenerator } from "../utils/eventToGenerator";
import { base64FromBytes } from "../utils/base64FromBytes";
import { isFrontend } from "../utils/isFrontend";
import { createBlobs } from "../utils/createBlobs";
import type { CredentialsParams, RepoDesignation } from "../types/public.js";
import { checkCredentials } from "../utils/checkCredentials.js";
import { chunk } from "../utils/chunk.js";
import { promisesQueue } from "../utils/promisesQueue.js";
import { promisesQueueStreaming } from "../utils/promisesQueueStreaming.js";
import { sha256 } from "../utils/sha256.js";
import { toRepoId } from "../utils/toRepoId.js";
import { WebBlob } from "../utils/WebBlob.js";
import { eventToGenerator } from "../utils/eventToGenerator.js";
import { base64FromBytes } from "../utils/base64FromBytes.js";
import { isFrontend } from "../utils/isFrontend.js";
import { createBlobs } from "../utils/createBlobs.js";

const CONCURRENT_SHAS = 5;
const CONCURRENT_LFS_UPLOADS = 5;
2 changes: 1 addition & 1 deletion packages/hub/src/lib/count-commits.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert, it, describe } from "vitest";
import { countCommits } from "./count-commits";
import { countCommits } from "./count-commits.js";

describe("countCommits", () => {
it("should fetch paginated commits from the repo", async () => {
10 changes: 5 additions & 5 deletions packages/hub/src/lib/count-commits.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HUB_URL } from "../consts";
import { createApiError } from "../error";
import type { CredentialsParams, RepoDesignation } from "../types/public";
import { checkCredentials } from "../utils/checkCredentials";
import { toRepoId } from "../utils/toRepoId";
import { HUB_URL } from "../consts.js";
import { createApiError } from "../error.js";
import type { CredentialsParams, RepoDesignation } from "../types/public.js";
import { checkCredentials } from "../utils/checkCredentials.js";
import { toRepoId } from "../utils/toRepoId.js";

export async function countCommits(
params: {
Loading