@langchain/google-common 2.1.17 → 2.1.19
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/CHANGELOG.md +18 -0
- package/dist/auth.cjs +1 -2
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +1 -2
- package/dist/auth.js.map +1 -1
- package/dist/chat_models.cjs +24 -27
- package/dist/chat_models.cjs.map +1 -1
- package/dist/chat_models.d.cts.map +1 -1
- package/dist/chat_models.d.ts.map +1 -1
- package/dist/chat_models.js +7 -9
- package/dist/chat_models.js.map +1 -1
- package/dist/connection.cjs +16 -26
- package/dist/connection.cjs.map +1 -1
- package/dist/connection.d.cts.map +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +13 -22
- package/dist/connection.js.map +1 -1
- package/dist/embeddings.cjs +12 -22
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +0 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +0 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +7 -16
- package/dist/embeddings.js.map +1 -1
- package/dist/experimental/media.cjs +41 -70
- package/dist/experimental/media.cjs.map +1 -1
- package/dist/experimental/media.d.cts.map +1 -1
- package/dist/experimental/media.d.ts.map +1 -1
- package/dist/experimental/media.js +36 -65
- package/dist/experimental/media.js.map +1 -1
- package/dist/experimental/utils/media_core.cjs +22 -39
- package/dist/experimental/utils/media_core.cjs.map +1 -1
- package/dist/experimental/utils/media_core.d.cts.map +1 -1
- package/dist/experimental/utils/media_core.d.ts.map +1 -1
- package/dist/experimental/utils/media_core.js +16 -33
- package/dist/experimental/utils/media_core.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/llms.cjs +14 -19
- package/dist/llms.cjs.map +1 -1
- package/dist/llms.d.cts.map +1 -1
- package/dist/llms.d.ts.map +1 -1
- package/dist/llms.js +4 -8
- package/dist/llms.js.map +1 -1
- package/dist/output_parsers.cjs +12 -29
- package/dist/output_parsers.cjs.map +1 -1
- package/dist/output_parsers.d.cts.map +1 -1
- package/dist/output_parsers.d.ts.map +1 -1
- package/dist/output_parsers.js +10 -26
- package/dist/output_parsers.js.map +1 -1
- package/dist/profiles.cjs +100 -17
- package/dist/profiles.cjs.map +1 -1
- package/dist/profiles.js +100 -17
- package/dist/profiles.js.map +1 -1
- package/dist/types-anthropic.d.cts.map +1 -1
- package/dist/types-anthropic.d.ts.map +1 -1
- package/dist/types.cjs +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +0 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/anthropic.cjs +73 -113
- package/dist/utils/anthropic.cjs.map +1 -1
- package/dist/utils/anthropic.js +63 -102
- package/dist/utils/anthropic.js.map +1 -1
- package/dist/utils/common.cjs +10 -13
- package/dist/utils/common.cjs.map +1 -1
- package/dist/utils/common.d.cts.map +1 -1
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/common.js +6 -8
- package/dist/utils/common.js.map +1 -1
- package/dist/utils/failed_handler.cjs +1 -2
- package/dist/utils/failed_handler.cjs.map +1 -1
- package/dist/utils/failed_handler.d.cts.map +1 -1
- package/dist/utils/failed_handler.d.ts.map +1 -1
- package/dist/utils/failed_handler.js +1 -2
- package/dist/utils/failed_handler.js.map +1 -1
- package/dist/utils/gemini.cjs +89 -135
- package/dist/utils/gemini.cjs.map +1 -1
- package/dist/utils/gemini.d.cts.map +1 -1
- package/dist/utils/gemini.d.ts.map +1 -1
- package/dist/utils/gemini.js +64 -109
- package/dist/utils/gemini.js.map +1 -1
- package/dist/utils/index.cjs +1 -0
- package/dist/utils/palm.d.cts.map +1 -1
- package/dist/utils/palm.d.ts.map +1 -1
- package/dist/utils/safety.cjs.map +1 -1
- package/dist/utils/safety.d.cts.map +1 -1
- package/dist/utils/safety.d.ts.map +1 -1
- package/dist/utils/safety.js.map +1 -1
- package/dist/utils/stream.cjs +5 -9
- package/dist/utils/stream.cjs.map +1 -1
- package/dist/utils/stream.d.cts.map +1 -1
- package/dist/utils/stream.d.ts.map +1 -1
- package/dist/utils/stream.js +5 -9
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/zod_to_gemini_parameters.cjs +4 -7
- package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -1
- package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -1
- package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -1
- package/dist/utils/zod_to_gemini_parameters.js +2 -4
- package/dist/utils/zod_to_gemini_parameters.js.map +1 -1
- package/package.json +5 -5
- package/dist/_virtual/rolldown_runtime.cjs +0 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media_core.cjs","names":["dataArray: Uint8Array","Serializable","params: MediaBlobParameters","encoding: string","url: string","data: MediaBlobData","blob: Blob","other?: Omit<MediaBlobParameters, \"data\">","BaseStore","opts?: BlobStoreOptions","key: string | MediaBlob","path: string | undefined","opts?: BlobStoreStoreOptions","blob: MediaBlob","oldBlob: MediaBlob","newPath?: string","name: ActionIfInvalidAction | string","_opts?: BlobStoreStoreOptions","opts: BlobStoreStoreOptions","allOpts: BlobStoreStoreOptions","path: string","_opts?: BlobStoreFetchOptions","opts?: BlobStoreFetchOptions","opts: BlobStoreFetchOptions","allOpts: BlobStoreFetchOptions","opts: BackedBlobStoreOptions","keys: string[]","keyValuePairs: [string, MediaBlob][]","prefix: string | undefined","opts: ReadThroughBlobStoreOptions","_keyValuePairs: [string, MediaBlob][]","metadata: Record<string, unknown>","headers: Record<string, string>","_keys: string[]","_prefix: string | undefined","config: MediaManagerConfiguration","blob: MediaBlob | undefined","uri: string","resolvedBlob: MediaBlob | undefined"],"sources":["../../../src/experimental/utils/media_core.ts"],"sourcesContent":["import { v1, v4 } from \"uuid\"; // FIXME - it is importing the wrong uuid, so v6 and v7 aren't implemented\nimport { BaseStore } from \"@langchain/core/stores\";\nimport { Serializable } from \"@langchain/core/load/serializable\";\n\nexport type MediaBlobData = {\n value: string; // In Base64 encoding\n type: string; // The mime type and possibly encoding\n};\n\nexport interface MediaBlobParameters {\n data?: MediaBlobData;\n\n metadata?: Record<string, unknown>;\n\n path?: string;\n}\n\nfunction bytesToString(dataArray: Uint8Array): string {\n // Need to handle the array in smaller chunks to deal with stack size limits\n let ret = \"\";\n const chunkSize = 102400;\n for (let i = 0; i < dataArray.length; i += chunkSize) {\n const chunk = dataArray.subarray(i, i + chunkSize);\n ret += String.fromCharCode(...chunk);\n }\n\n return ret;\n}\n\n/**\n * Represents a chunk of data that can be identified by the path where the\n * data is (or will be) located, along with optional metadata about the data.\n */\nexport class MediaBlob extends Serializable implements MediaBlobParameters {\n lc_serializable = true;\n\n lc_namespace = [\n \"langchain\",\n \"google_common\",\n \"experimental\",\n \"utils\",\n \"media_core\",\n ];\n\n data: MediaBlobData = {\n value: \"\",\n type: \"text/plain\",\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>;\n\n path?: string;\n\n constructor(params: MediaBlobParameters) {\n super(params);\n\n this.data = params.data ?? this.data;\n this.metadata = params.metadata;\n this.path = params.path;\n }\n\n get size(): number {\n return this.asBytes.length;\n }\n\n get dataType(): string {\n return this.data?.type ?? \"\";\n }\n\n get encoding(): string {\n const charsetEquals = this.dataType.indexOf(\"charset=\");\n return charsetEquals === -1\n ? \"utf-8\"\n : this.dataType.substring(charsetEquals + 8);\n }\n\n get mimetype(): string {\n const semicolon = this.dataType.indexOf(\";\");\n return semicolon === -1\n ? this.dataType\n : this.dataType.substring(0, semicolon);\n }\n\n get asBytes(): Uint8Array {\n if (!this.data) {\n return Uint8Array.from([]);\n }\n const binString = atob(this.data?.value);\n const ret = new Uint8Array(binString.length);\n for (let co = 0; co < binString.length; co += 1) {\n ret[co] = binString.charCodeAt(co);\n }\n return ret;\n }\n\n async asString(): Promise<string> {\n return bytesToString(this.asBytes);\n }\n\n async asBase64(): Promise<string> {\n return this.data?.value ?? \"\";\n }\n\n async asDataUrl(): Promise<string> {\n return `data:${this.mimetype};base64,${await this.asBase64()}`;\n }\n\n async asUri(): Promise<string> {\n return this.path ?? (await this.asDataUrl());\n }\n\n async encode(): Promise<{ encoded: string; encoding: string }> {\n const dataUrl = await this.asDataUrl();\n const comma = dataUrl.indexOf(\",\");\n const encoded = dataUrl.substring(comma + 1);\n const encoding: string = dataUrl.indexOf(\"base64\") > -1 ? \"base64\" : \"8bit\";\n return {\n encoded,\n encoding,\n };\n }\n\n static fromDataUrl(url: string): MediaBlob {\n if (!url.startsWith(\"data:\")) {\n throw new Error(\"Not a data: URL\");\n }\n const colon = url.indexOf(\":\");\n const semicolon = url.indexOf(\";\");\n const mimeType = url.substring(colon + 1, semicolon);\n\n const comma = url.indexOf(\",\");\n const base64Data = url.substring(comma + 1);\n\n const data: MediaBlobData = {\n type: mimeType,\n value: base64Data,\n };\n\n return new MediaBlob({\n data,\n path: url,\n });\n }\n\n static async fromBlob(\n blob: Blob,\n other?: Omit<MediaBlobParameters, \"data\">\n ): Promise<MediaBlob> {\n const valueBuffer = await blob.arrayBuffer();\n const valueArray = new Uint8Array(valueBuffer);\n const valueStr = bytesToString(valueArray);\n const value = btoa(valueStr);\n\n return new MediaBlob({\n ...other,\n data: {\n value,\n type: blob.type,\n },\n });\n }\n}\n\nexport type ActionIfInvalidAction =\n | \"ignore\"\n | \"prefixPath\"\n | \"prefixUuid1\"\n | \"prefixUuid4\"\n | \"prefixUuid6\"\n | \"prefixUuid7\"\n | \"removePath\";\n\nexport interface BlobStoreStoreOptions {\n /**\n * If the path is missing or invalid in the blob, how should we create\n * a new path?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an emtpy string: Reject the blob\n * - \"ignore\": Attempt to store it anyway (but this may fail)\n * - \"prefixPath\": Use the default prefix for the BlobStore and get the\n * unique portion from the URL. The original path is stored in the metadata\n * - \"prefixUuid\": Use the default prefix for the BlobStore and get the\n * unique portion from a generated UUID. The original path is stored\n * in the metadata\n */\n actionIfInvalid?: ActionIfInvalidAction;\n\n /**\n * The expected prefix for URIs that are stored.\n * This may be used to test if a MediaBlob is valid and used to create a new\n * path if \"prefixPath\" or \"prefixUuid\" is set for actionIfInvalid.\n */\n pathPrefix?: string;\n}\n\nexport type ActionIfBlobMissingAction = \"emptyBlob\";\n\nexport interface BlobStoreFetchOptions {\n /**\n * If the blob is not found when fetching, what should we do?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an empty string: return undefined\n * - \"emptyBlob\": return a new MediaBlob that has the path set, but nothing else.\n */\n actionIfBlobMissing?: ActionIfBlobMissingAction;\n}\n\nexport interface BlobStoreOptions {\n defaultStoreOptions?: BlobStoreStoreOptions;\n\n defaultFetchOptions?: BlobStoreFetchOptions;\n}\n\n/**\n * A specialized Store that is designed to handle MediaBlobs and use the\n * key that is included in the blob to determine exactly how it is stored.\n *\n * The full details of a MediaBlob may be changed when it is stored.\n * For example, it may get additional or different Metadata. This should be\n * what is returned when the store() method is called.\n *\n * Although BlobStore extends BaseStore, not all of the methods from\n * BaseStore may be implemented (or even possible). Those that are not\n * implemented should be documented and throw an Error if called.\n */\nexport abstract class BlobStore extends BaseStore<string, MediaBlob> {\n lc_namespace = [\"langchain\", \"google-common\"]; // FIXME - What should this be? And why?\n\n defaultStoreOptions: BlobStoreStoreOptions;\n\n defaultFetchOptions: BlobStoreFetchOptions;\n\n constructor(opts?: BlobStoreOptions) {\n super(opts);\n this.defaultStoreOptions = opts?.defaultStoreOptions ?? {};\n this.defaultFetchOptions = opts?.defaultFetchOptions ?? {};\n }\n\n protected async _realKey(key: string | MediaBlob): Promise<string> {\n return typeof key === \"string\" ? key : await key.asUri();\n }\n\n /**\n * Is the path supported by this BlobStore?\n *\n * Although this is async, this is expected to be a relatively fast operation\n * (ie - you shouldn't make network calls).\n *\n * @param path The path to check\n * @param opts Any options (if needed) that may be used to determine if it is valid\n * @return If the path is supported\n */\n hasValidPath(\n path: string | undefined,\n opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n const prefix = opts?.pathPrefix ?? \"\";\n const isPrefixed = typeof path !== \"undefined\" && path.startsWith(prefix);\n return Promise.resolve(isPrefixed);\n }\n\n protected _blobPathSuffix(blob: MediaBlob): string {\n // Get the path currently set and make sure we treat it as a string\n const blobPath = `${blob.path}`;\n\n // Advance past the first set of /\n let pathStart = blobPath.indexOf(\"/\") + 1;\n while (blobPath.charAt(pathStart) === \"/\") {\n pathStart += 1;\n }\n\n // We will use the rest as the path for a replacement\n return blobPath.substring(pathStart);\n }\n\n protected async _newBlob(\n oldBlob: MediaBlob,\n newPath?: string\n ): Promise<MediaBlob> {\n const oldPath = oldBlob.path;\n const metadata = oldBlob?.metadata ?? {};\n metadata.langchainOldPath = oldPath;\n const newBlob = new MediaBlob({\n ...oldBlob,\n metadata,\n });\n if (newPath) {\n newBlob.path = newPath;\n } else if (newBlob.path) {\n delete newBlob.path;\n }\n return newBlob;\n }\n\n protected async _validBlobPrefixPath(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._blobPathSuffix(blob);\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected _validBlobPrefixUuidFunction(\n name: ActionIfInvalidAction | string\n ): string {\n switch (name) {\n case \"prefixUuid1\":\n return v1();\n case \"prefixUuid4\":\n return v4();\n // case \"prefixUuid6\": return v6();\n // case \"prefixUuid7\": return v7();\n default:\n throw new Error(`Unknown uuid function: ${name}`);\n }\n }\n\n protected async _validBlobPrefixUuid(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._validBlobPrefixUuidFunction(\n opts?.actionIfInvalid ?? \"prefixUuid4\"\n );\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected async _validBlobRemovePath(\n blob: MediaBlob,\n _opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n return this._newBlob(blob, undefined);\n }\n\n /**\n * Based on the blob and options, return a blob that has a valid path\n * that can be saved.\n * @param blob\n * @param opts\n */\n protected async _validStoreBlob(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob | undefined> {\n if (await this.hasValidPath(blob.path, opts)) {\n return blob;\n }\n switch (opts?.actionIfInvalid) {\n case \"ignore\":\n return blob;\n case \"prefixPath\":\n return this._validBlobPrefixPath(blob, opts);\n case \"prefixUuid1\":\n case \"prefixUuid4\":\n case \"prefixUuid6\":\n case \"prefixUuid7\":\n return this._validBlobPrefixUuid(blob, opts);\n case \"removePath\":\n return this._validBlobRemovePath(blob, opts);\n default:\n return undefined;\n }\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreStoreOptions = {\n ...this.defaultStoreOptions,\n ...opts,\n };\n const validBlob = await this._validStoreBlob(blob, allOpts);\n if (typeof validBlob !== \"undefined\") {\n const validKey = await validBlob.asUri();\n await this.mset([[validKey, validBlob]]);\n const savedKey = await validBlob.asUri();\n return await this.fetch(savedKey);\n }\n return undefined;\n }\n\n protected async _missingFetchBlobEmpty(\n path: string,\n _opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob> {\n return new MediaBlob({ path });\n }\n\n protected async _missingFetchBlob(\n path: string,\n opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob | undefined> {\n switch (opts?.actionIfBlobMissing) {\n case \"emptyBlob\":\n return this._missingFetchBlobEmpty(path, opts);\n default:\n return undefined;\n }\n }\n\n async fetch(\n key: string | MediaBlob,\n opts: BlobStoreFetchOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreFetchOptions = {\n ...this.defaultFetchOptions,\n ...opts,\n };\n const realKey = await this._realKey(key);\n const ret = await this.mget([realKey]);\n return ret?.[0] ?? (await this._missingFetchBlob(realKey, allOpts));\n }\n}\n\nexport interface BackedBlobStoreOptions extends BlobStoreOptions {\n backingStore: BaseStore<string, MediaBlob>;\n}\n\nexport class BackedBlobStore extends BlobStore {\n backingStore: BaseStore<string, MediaBlob>;\n\n constructor(opts: BackedBlobStoreOptions) {\n super(opts);\n this.backingStore = opts.backingStore;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.backingStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.backingStore.mget(keys);\n }\n\n mset(keyValuePairs: [string, MediaBlob][]): Promise<void> {\n return this.backingStore.mset(keyValuePairs);\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.backingStore.yieldKeys(prefix);\n }\n}\n\nexport interface ReadThroughBlobStoreOptions extends BlobStoreOptions {\n baseStore: BlobStore;\n backingStore: BlobStore;\n}\n\nexport class ReadThroughBlobStore extends BlobStore {\n baseStore: BlobStore;\n\n backingStore: BlobStore;\n\n constructor(opts: ReadThroughBlobStoreOptions) {\n super(opts);\n this.baseStore = opts.baseStore;\n this.backingStore = opts.backingStore;\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const originalUri = await blob.asUri();\n const newBlob = await this.backingStore.store(blob, opts);\n if (newBlob) {\n await this.baseStore.mset([[originalUri, newBlob]]);\n }\n return newBlob;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.baseStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.baseStore.mget(keys);\n }\n\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n throw new Error(\"Do not call ReadThroughBlobStore.mset directly\");\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.baseStore.yieldKeys(prefix);\n }\n}\n\nexport class SimpleWebBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for SimpleWebBlobStore\");\n }\n\n async hasValidPath(\n path: string | undefined,\n _opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n return (\n (await super.hasValidPath(path, { pathPrefix: \"https://\" })) ||\n (await super.hasValidPath(path, { pathPrefix: \"http://\" }))\n );\n }\n\n async _fetch(url: string): Promise<MediaBlob | undefined> {\n const ret = new MediaBlob({\n path: url,\n });\n const metadata: Record<string, unknown> = {};\n const fetchOptions = {\n method: \"GET\",\n };\n const res = await fetch(url, fetchOptions);\n metadata.status = res.status;\n\n const headers: Record<string, string> = {};\n for (const [key, value] of res.headers.entries()) {\n headers[key] = value;\n }\n metadata.headers = headers;\n\n metadata.ok = res.ok;\n if (res.ok) {\n const resMediaBlob = await MediaBlob.fromBlob(await res.blob());\n ret.data = resMediaBlob.data;\n }\n\n ret.metadata = metadata;\n return ret;\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return await Promise.all(blobMap);\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\n/**\n * A blob \"store\" that works with data: URLs that will turn the URL into\n * a blob.\n */\nexport class DataBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for DataBlobStore\");\n }\n\n hasValidPath(path: string, _opts?: BlobStoreStoreOptions): Promise<boolean> {\n return super.hasValidPath(path, { pathPrefix: \"data:\" });\n }\n\n _fetch(url: string): MediaBlob {\n return MediaBlob.fromDataUrl(url);\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return blobMap;\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\nexport interface MediaManagerConfiguration {\n /**\n * A store that, given a common URI, returns the corresponding MediaBlob.\n * The returned MediaBlob may have a different URI.\n * In many cases, this will be a ReadThroughStore or something similar\n * that has a cached version of the MediaBlob, but also a way to get\n * a new (or refreshed) version.\n */\n store: BlobStore;\n\n /**\n * BlobStores that can resolve a URL into the MediaBlob to save\n * in the canonical store. This list is evaluated in order.\n * If not provided, a default list (which involves a DataBlobStore\n * and a SimpleWebBlobStore) will be used.\n */\n resolvers?: BlobStore[];\n}\n\n/**\n * Responsible for converting a URI (typically a web URL) into a MediaBlob.\n * Allows for aliasing / caching of the requested URI and what it resolves to.\n * This MediaBlob is expected to be usable to provide to an LLM, either\n * through the Base64 of the media or through a canonical URI that the LLM\n * supports.\n */\nexport class MediaManager {\n store: BlobStore;\n\n resolvers: BlobStore[] | undefined;\n\n constructor(config: MediaManagerConfiguration) {\n this.store = config.store;\n this.resolvers = config.resolvers;\n }\n\n defaultResolvers(): BlobStore[] {\n return [new DataBlobStore({}), new SimpleWebBlobStore({})];\n }\n\n async _isInvalid(blob: MediaBlob | undefined): Promise<boolean> {\n return typeof blob === \"undefined\";\n }\n\n /**\n * Given the public URI, load what is at this URI and save it\n * in the store.\n * @param uri The URI to resolve using the resolver\n * @return A canonical MediaBlob for this URI\n */\n async _resolveAndSave(uri: string): Promise<MediaBlob | undefined> {\n let resolvedBlob: MediaBlob | undefined;\n\n const resolvers = this.resolvers || this.defaultResolvers();\n for (let co = 0; co < resolvers.length; co += 1) {\n const resolver = resolvers[co];\n if (await resolver.hasValidPath(uri)) {\n resolvedBlob = await resolver.fetch(uri);\n }\n }\n\n if (resolvedBlob) {\n return await this.store.store(resolvedBlob);\n } else {\n return new MediaBlob({});\n }\n }\n\n async getMediaBlob(uri: string): Promise<MediaBlob | undefined> {\n const aliasBlob = await this.store.fetch(uri);\n const ret = (await this._isInvalid(aliasBlob))\n ? await this._resolveAndSave(uri)\n : (aliasBlob as MediaBlob);\n return ret;\n }\n}\n"],"mappings":";;;;;;AAiBA,SAAS,cAAcA,WAA+B;CAEpD,IAAI,MAAM;CACV,MAAM,YAAY;AAClB,MAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK,WAAW;EACpD,MAAM,QAAQ,UAAU,SAAS,GAAG,IAAI,UAAU;EAClD,OAAO,OAAO,aAAa,GAAG,MAAM;CACrC;AAED,QAAO;AACR;;;;;AAMD,IAAa,YAAb,MAAa,kBAAkBC,gDAA4C;CACzE,kBAAkB;CAElB,eAAe;EACb;EACA;EACA;EACA;EACA;CACD;CAED,OAAsB;EACpB,OAAO;EACP,MAAM;CACP;CAGD;CAEA;CAEA,YAAYC,QAA6B;EACvC,MAAM,OAAO;EAEb,KAAK,OAAO,OAAO,QAAQ,KAAK;EAChC,KAAK,WAAW,OAAO;EACvB,KAAK,OAAO,OAAO;CACpB;CAED,IAAI,OAAe;AACjB,SAAO,KAAK,QAAQ;CACrB;CAED,IAAI,WAAmB;AACrB,SAAO,KAAK,MAAM,QAAQ;CAC3B;CAED,IAAI,WAAmB;EACrB,MAAM,gBAAgB,KAAK,SAAS,QAAQ,WAAW;AACvD,SAAO,kBAAkB,KACrB,UACA,KAAK,SAAS,UAAU,gBAAgB,EAAE;CAC/C;CAED,IAAI,WAAmB;EACrB,MAAM,YAAY,KAAK,SAAS,QAAQ,IAAI;AAC5C,SAAO,cAAc,KACjB,KAAK,WACL,KAAK,SAAS,UAAU,GAAG,UAAU;CAC1C;CAED,IAAI,UAAsB;AACxB,MAAI,CAAC,KAAK,KACR,QAAO,WAAW,KAAK,CAAE,EAAC;EAE5B,MAAM,YAAY,KAAK,KAAK,MAAM,MAAM;EACxC,MAAM,MAAM,IAAI,WAAW,UAAU;AACrC,OAAK,IAAI,KAAK,GAAG,KAAK,U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CAED,MAAM,KAAKsB,MAAoD;EAC7D,MAAM,UAAU,KAAK,IAAI,KAAK,OAAO;AACrC,SAAO;CACR;CAED,MAAM,QAAQO,OAAgC;EAC5C,KAAK,0BAA0B;CAChC;CAED,MAAM,KAAKH,gBAAsD;EAC/D,KAAK,0BAA0B;CAChC;CAED,OAAO,UAAUI,SAAqD;EACpE,KAAK,0BAA0B;EAC/B,MAAM;CACP;AACF;;;;;;;;AA4BD,IAAa,eAAb,MAA0B;CACxB;CAEA;CAEA,YAAYC,QAAmC;EAC7C,KAAK,QAAQ,OAAO;EACpB,KAAK,YAAY,OAAO;CACzB;CAED,mBAAgC;AAC9B,SAAO,CAAC,IAAI,cAAc,CAAE,IAAG,IAAI,mBAAmB,CAAE,EAAE;CAC3D;CAED,MAAM,WAAWC,MAA+C;AAC9D,SAAO,OAAO,SAAS;CACxB;;;;;;;CAQD,MAAM,gBAAgBC,KAA6C;EACjE,IAAIC;EAEJ,MAAM,YAAY,KAAK,aAAa,KAAK,kBAAkB;AAC3D,OAAK,IAAI,KAAK,GAAG,KAAK,UAAU,QAAQ,MAAM,GAAG;GAC/C,MAAM,WAAW,UAAU;AAC3B,OAAI,MAAM,SAAS,aAAa,IAAI,EAClC,eAAe,MAAM,SAAS,MAAM,IAAI;EAE3C;AAED,MAAI,aACF,QAAO,MAAM,KAAK,MAAM,MAAM,aAAa;MAE3C,QAAO,IAAI,UAAU,CAAE;CAE1B;CAED,MAAM,aAAaD,KAA6C;EAC9D,MAAM,YAAY,MAAM,KAAK,MAAM,MAAM,IAAI;EAC7C,MAAM,MAAO,MAAM,KAAK,WAAW,UAAU,GACzC,MAAM,KAAK,gBAAgB,IAAI,GAC9B;AACL,SAAO;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"media_core.cjs","names":["Serializable","BaseStore"],"sources":["../../../src/experimental/utils/media_core.ts"],"sourcesContent":["import { v1, v4 } from \"uuid\"; // FIXME - it is importing the wrong uuid, so v6 and v7 aren't implemented\nimport { BaseStore } from \"@langchain/core/stores\";\nimport { Serializable } from \"@langchain/core/load/serializable\";\n\nexport type MediaBlobData = {\n value: string; // In Base64 encoding\n type: string; // The mime type and possibly encoding\n};\n\nexport interface MediaBlobParameters {\n data?: MediaBlobData;\n\n metadata?: Record<string, unknown>;\n\n path?: string;\n}\n\nfunction bytesToString(dataArray: Uint8Array): string {\n // Need to handle the array in smaller chunks to deal with stack size limits\n let ret = \"\";\n const chunkSize = 102400;\n for (let i = 0; i < dataArray.length; i += chunkSize) {\n const chunk = dataArray.subarray(i, i + chunkSize);\n ret += String.fromCharCode(...chunk);\n }\n\n return ret;\n}\n\n/**\n * Represents a chunk of data that can be identified by the path where the\n * data is (or will be) located, along with optional metadata about the data.\n */\nexport class MediaBlob extends Serializable implements MediaBlobParameters {\n lc_serializable = true;\n\n lc_namespace = [\n \"langchain\",\n \"google_common\",\n \"experimental\",\n \"utils\",\n \"media_core\",\n ];\n\n data: MediaBlobData = {\n value: \"\",\n type: \"text/plain\",\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>;\n\n path?: string;\n\n constructor(params: MediaBlobParameters) {\n super(params);\n\n this.data = params.data ?? this.data;\n this.metadata = params.metadata;\n this.path = params.path;\n }\n\n get size(): number {\n return this.asBytes.length;\n }\n\n get dataType(): string {\n return this.data?.type ?? \"\";\n }\n\n get encoding(): string {\n const charsetEquals = this.dataType.indexOf(\"charset=\");\n return charsetEquals === -1\n ? \"utf-8\"\n : this.dataType.substring(charsetEquals + 8);\n }\n\n get mimetype(): string {\n const semicolon = this.dataType.indexOf(\";\");\n return semicolon === -1\n ? this.dataType\n : this.dataType.substring(0, semicolon);\n }\n\n get asBytes(): Uint8Array {\n if (!this.data) {\n return Uint8Array.from([]);\n }\n const binString = atob(this.data?.value);\n const ret = new Uint8Array(binString.length);\n for (let co = 0; co < binString.length; co += 1) {\n ret[co] = binString.charCodeAt(co);\n }\n return ret;\n }\n\n async asString(): Promise<string> {\n return bytesToString(this.asBytes);\n }\n\n async asBase64(): Promise<string> {\n return this.data?.value ?? \"\";\n }\n\n async asDataUrl(): Promise<string> {\n return `data:${this.mimetype};base64,${await this.asBase64()}`;\n }\n\n async asUri(): Promise<string> {\n return this.path ?? (await this.asDataUrl());\n }\n\n async encode(): Promise<{ encoded: string; encoding: string }> {\n const dataUrl = await this.asDataUrl();\n const comma = dataUrl.indexOf(\",\");\n const encoded = dataUrl.substring(comma + 1);\n const encoding: string = dataUrl.indexOf(\"base64\") > -1 ? \"base64\" : \"8bit\";\n return {\n encoded,\n encoding,\n };\n }\n\n static fromDataUrl(url: string): MediaBlob {\n if (!url.startsWith(\"data:\")) {\n throw new Error(\"Not a data: URL\");\n }\n const colon = url.indexOf(\":\");\n const semicolon = url.indexOf(\";\");\n const mimeType = url.substring(colon + 1, semicolon);\n\n const comma = url.indexOf(\",\");\n const base64Data = url.substring(comma + 1);\n\n const data: MediaBlobData = {\n type: mimeType,\n value: base64Data,\n };\n\n return new MediaBlob({\n data,\n path: url,\n });\n }\n\n static async fromBlob(\n blob: Blob,\n other?: Omit<MediaBlobParameters, \"data\">\n ): Promise<MediaBlob> {\n const valueBuffer = await blob.arrayBuffer();\n const valueArray = new Uint8Array(valueBuffer);\n const valueStr = bytesToString(valueArray);\n const value = btoa(valueStr);\n\n return new MediaBlob({\n ...other,\n data: {\n value,\n type: blob.type,\n },\n });\n }\n}\n\nexport type ActionIfInvalidAction =\n | \"ignore\"\n | \"prefixPath\"\n | \"prefixUuid1\"\n | \"prefixUuid4\"\n | \"prefixUuid6\"\n | \"prefixUuid7\"\n | \"removePath\";\n\nexport interface BlobStoreStoreOptions {\n /**\n * If the path is missing or invalid in the blob, how should we create\n * a new path?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an emtpy string: Reject the blob\n * - \"ignore\": Attempt to store it anyway (but this may fail)\n * - \"prefixPath\": Use the default prefix for the BlobStore and get the\n * unique portion from the URL. The original path is stored in the metadata\n * - \"prefixUuid\": Use the default prefix for the BlobStore and get the\n * unique portion from a generated UUID. The original path is stored\n * in the metadata\n */\n actionIfInvalid?: ActionIfInvalidAction;\n\n /**\n * The expected prefix for URIs that are stored.\n * This may be used to test if a MediaBlob is valid and used to create a new\n * path if \"prefixPath\" or \"prefixUuid\" is set for actionIfInvalid.\n */\n pathPrefix?: string;\n}\n\nexport type ActionIfBlobMissingAction = \"emptyBlob\";\n\nexport interface BlobStoreFetchOptions {\n /**\n * If the blob is not found when fetching, what should we do?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an empty string: return undefined\n * - \"emptyBlob\": return a new MediaBlob that has the path set, but nothing else.\n */\n actionIfBlobMissing?: ActionIfBlobMissingAction;\n}\n\nexport interface BlobStoreOptions {\n defaultStoreOptions?: BlobStoreStoreOptions;\n\n defaultFetchOptions?: BlobStoreFetchOptions;\n}\n\n/**\n * A specialized Store that is designed to handle MediaBlobs and use the\n * key that is included in the blob to determine exactly how it is stored.\n *\n * The full details of a MediaBlob may be changed when it is stored.\n * For example, it may get additional or different Metadata. This should be\n * what is returned when the store() method is called.\n *\n * Although BlobStore extends BaseStore, not all of the methods from\n * BaseStore may be implemented (or even possible). Those that are not\n * implemented should be documented and throw an Error if called.\n */\nexport abstract class BlobStore extends BaseStore<string, MediaBlob> {\n lc_namespace = [\"langchain\", \"google-common\"]; // FIXME - What should this be? And why?\n\n defaultStoreOptions: BlobStoreStoreOptions;\n\n defaultFetchOptions: BlobStoreFetchOptions;\n\n constructor(opts?: BlobStoreOptions) {\n super(opts);\n this.defaultStoreOptions = opts?.defaultStoreOptions ?? {};\n this.defaultFetchOptions = opts?.defaultFetchOptions ?? {};\n }\n\n protected async _realKey(key: string | MediaBlob): Promise<string> {\n return typeof key === \"string\" ? key : await key.asUri();\n }\n\n /**\n * Is the path supported by this BlobStore?\n *\n * Although this is async, this is expected to be a relatively fast operation\n * (ie - you shouldn't make network calls).\n *\n * @param path The path to check\n * @param opts Any options (if needed) that may be used to determine if it is valid\n * @return If the path is supported\n */\n hasValidPath(\n path: string | undefined,\n opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n const prefix = opts?.pathPrefix ?? \"\";\n const isPrefixed = typeof path !== \"undefined\" && path.startsWith(prefix);\n return Promise.resolve(isPrefixed);\n }\n\n protected _blobPathSuffix(blob: MediaBlob): string {\n // Get the path currently set and make sure we treat it as a string\n const blobPath = `${blob.path}`;\n\n // Advance past the first set of /\n let pathStart = blobPath.indexOf(\"/\") + 1;\n while (blobPath.charAt(pathStart) === \"/\") {\n pathStart += 1;\n }\n\n // We will use the rest as the path for a replacement\n return blobPath.substring(pathStart);\n }\n\n protected async _newBlob(\n oldBlob: MediaBlob,\n newPath?: string\n ): Promise<MediaBlob> {\n const oldPath = oldBlob.path;\n const metadata = oldBlob?.metadata ?? {};\n metadata.langchainOldPath = oldPath;\n const newBlob = new MediaBlob({\n ...oldBlob,\n metadata,\n });\n if (newPath) {\n newBlob.path = newPath;\n } else if (newBlob.path) {\n delete newBlob.path;\n }\n return newBlob;\n }\n\n protected async _validBlobPrefixPath(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._blobPathSuffix(blob);\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected _validBlobPrefixUuidFunction(\n name: ActionIfInvalidAction | string\n ): string {\n switch (name) {\n case \"prefixUuid1\":\n return v1();\n case \"prefixUuid4\":\n return v4();\n // case \"prefixUuid6\": return v6();\n // case \"prefixUuid7\": return v7();\n default:\n throw new Error(`Unknown uuid function: ${name}`);\n }\n }\n\n protected async _validBlobPrefixUuid(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._validBlobPrefixUuidFunction(\n opts?.actionIfInvalid ?? \"prefixUuid4\"\n );\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected async _validBlobRemovePath(\n blob: MediaBlob,\n _opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n return this._newBlob(blob, undefined);\n }\n\n /**\n * Based on the blob and options, return a blob that has a valid path\n * that can be saved.\n * @param blob\n * @param opts\n */\n protected async _validStoreBlob(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob | undefined> {\n if (await this.hasValidPath(blob.path, opts)) {\n return blob;\n }\n switch (opts?.actionIfInvalid) {\n case \"ignore\":\n return blob;\n case \"prefixPath\":\n return this._validBlobPrefixPath(blob, opts);\n case \"prefixUuid1\":\n case \"prefixUuid4\":\n case \"prefixUuid6\":\n case \"prefixUuid7\":\n return this._validBlobPrefixUuid(blob, opts);\n case \"removePath\":\n return this._validBlobRemovePath(blob, opts);\n default:\n return undefined;\n }\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreStoreOptions = {\n ...this.defaultStoreOptions,\n ...opts,\n };\n const validBlob = await this._validStoreBlob(blob, allOpts);\n if (typeof validBlob !== \"undefined\") {\n const validKey = await validBlob.asUri();\n await this.mset([[validKey, validBlob]]);\n const savedKey = await validBlob.asUri();\n return await this.fetch(savedKey);\n }\n return undefined;\n }\n\n protected async _missingFetchBlobEmpty(\n path: string,\n _opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob> {\n return new MediaBlob({ path });\n }\n\n protected async _missingFetchBlob(\n path: string,\n opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob | undefined> {\n switch (opts?.actionIfBlobMissing) {\n case \"emptyBlob\":\n return this._missingFetchBlobEmpty(path, opts);\n default:\n return undefined;\n }\n }\n\n async fetch(\n key: string | MediaBlob,\n opts: BlobStoreFetchOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreFetchOptions = {\n ...this.defaultFetchOptions,\n ...opts,\n };\n const realKey = await this._realKey(key);\n const ret = await this.mget([realKey]);\n return ret?.[0] ?? (await this._missingFetchBlob(realKey, allOpts));\n }\n}\n\nexport interface BackedBlobStoreOptions extends BlobStoreOptions {\n backingStore: BaseStore<string, MediaBlob>;\n}\n\nexport class BackedBlobStore extends BlobStore {\n backingStore: BaseStore<string, MediaBlob>;\n\n constructor(opts: BackedBlobStoreOptions) {\n super(opts);\n this.backingStore = opts.backingStore;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.backingStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.backingStore.mget(keys);\n }\n\n mset(keyValuePairs: [string, MediaBlob][]): Promise<void> {\n return this.backingStore.mset(keyValuePairs);\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.backingStore.yieldKeys(prefix);\n }\n}\n\nexport interface ReadThroughBlobStoreOptions extends BlobStoreOptions {\n baseStore: BlobStore;\n backingStore: BlobStore;\n}\n\nexport class ReadThroughBlobStore extends BlobStore {\n baseStore: BlobStore;\n\n backingStore: BlobStore;\n\n constructor(opts: ReadThroughBlobStoreOptions) {\n super(opts);\n this.baseStore = opts.baseStore;\n this.backingStore = opts.backingStore;\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const originalUri = await blob.asUri();\n const newBlob = await this.backingStore.store(blob, opts);\n if (newBlob) {\n await this.baseStore.mset([[originalUri, newBlob]]);\n }\n return newBlob;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.baseStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.baseStore.mget(keys);\n }\n\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n throw new Error(\"Do not call ReadThroughBlobStore.mset directly\");\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.baseStore.yieldKeys(prefix);\n }\n}\n\nexport class SimpleWebBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for SimpleWebBlobStore\");\n }\n\n async hasValidPath(\n path: string | undefined,\n _opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n return (\n (await super.hasValidPath(path, { pathPrefix: \"https://\" })) ||\n (await super.hasValidPath(path, { pathPrefix: \"http://\" }))\n );\n }\n\n async _fetch(url: string): Promise<MediaBlob | undefined> {\n const ret = new MediaBlob({\n path: url,\n });\n const metadata: Record<string, unknown> = {};\n const fetchOptions = {\n method: \"GET\",\n };\n const res = await fetch(url, fetchOptions);\n metadata.status = res.status;\n\n const headers: Record<string, string> = {};\n for (const [key, value] of res.headers.entries()) {\n headers[key] = value;\n }\n metadata.headers = headers;\n\n metadata.ok = res.ok;\n if (res.ok) {\n const resMediaBlob = await MediaBlob.fromBlob(await res.blob());\n ret.data = resMediaBlob.data;\n }\n\n ret.metadata = metadata;\n return ret;\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return await Promise.all(blobMap);\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\n/**\n * A blob \"store\" that works with data: URLs that will turn the URL into\n * a blob.\n */\nexport class DataBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for DataBlobStore\");\n }\n\n hasValidPath(path: string, _opts?: BlobStoreStoreOptions): Promise<boolean> {\n return super.hasValidPath(path, { pathPrefix: \"data:\" });\n }\n\n _fetch(url: string): MediaBlob {\n return MediaBlob.fromDataUrl(url);\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return blobMap;\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\nexport interface MediaManagerConfiguration {\n /**\n * A store that, given a common URI, returns the corresponding MediaBlob.\n * The returned MediaBlob may have a different URI.\n * In many cases, this will be a ReadThroughStore or something similar\n * that has a cached version of the MediaBlob, but also a way to get\n * a new (or refreshed) version.\n */\n store: BlobStore;\n\n /**\n * BlobStores that can resolve a URL into the MediaBlob to save\n * in the canonical store. This list is evaluated in order.\n * If not provided, a default list (which involves a DataBlobStore\n * and a SimpleWebBlobStore) will be used.\n */\n resolvers?: BlobStore[];\n}\n\n/**\n * Responsible for converting a URI (typically a web URL) into a MediaBlob.\n * Allows for aliasing / caching of the requested URI and what it resolves to.\n * This MediaBlob is expected to be usable to provide to an LLM, either\n * through the Base64 of the media or through a canonical URI that the LLM\n * supports.\n */\nexport class MediaManager {\n store: BlobStore;\n\n resolvers: BlobStore[] | undefined;\n\n constructor(config: MediaManagerConfiguration) {\n this.store = config.store;\n this.resolvers = config.resolvers;\n }\n\n defaultResolvers(): BlobStore[] {\n return [new DataBlobStore({}), new SimpleWebBlobStore({})];\n }\n\n async _isInvalid(blob: MediaBlob | undefined): Promise<boolean> {\n return typeof blob === \"undefined\";\n }\n\n /**\n * Given the public URI, load what is at this URI and save it\n * in the store.\n * @param uri The URI to resolve using the resolver\n * @return A canonical MediaBlob for this URI\n */\n async _resolveAndSave(uri: string): Promise<MediaBlob | undefined> {\n let resolvedBlob: MediaBlob | undefined;\n\n const resolvers = this.resolvers || this.defaultResolvers();\n for (let co = 0; co < resolvers.length; co += 1) {\n const resolver = resolvers[co];\n if (await resolver.hasValidPath(uri)) {\n resolvedBlob = await resolver.fetch(uri);\n }\n }\n\n if (resolvedBlob) {\n return await this.store.store(resolvedBlob);\n } else {\n return new MediaBlob({});\n }\n }\n\n async getMediaBlob(uri: string): Promise<MediaBlob | undefined> {\n const aliasBlob = await this.store.fetch(uri);\n const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AAS;;;;;;;;CASzB,MAAM,gBAAgB,KAA6C;EACjE,IAAI;EAEJ,MAAM,YAAY,KAAK,aAAa,KAAK,kBAAkB;AAC3D,OAAK,IAAI,KAAK,GAAG,KAAK,UAAU,QAAQ,MAAM,GAAG;GAC/C,MAAM,WAAW,UAAU;AAC3B,OAAI,MAAM,SAAS,aAAa,IAAI,CAClC,gBAAe,MAAM,SAAS,MAAM,IAAI;;AAI5C,MAAI,aACF,QAAO,MAAM,KAAK,MAAM,MAAM,aAAa;MAE3C,QAAO,IAAI,UAAU,EAAE,CAAC;;CAI5B,MAAM,aAAa,KAA6C;EAC9D,MAAM,YAAY,MAAM,KAAK,MAAM,MAAM,IAAI;AAI7C,SAHa,MAAM,KAAK,WAAW,UAAU,GACzC,MAAM,KAAK,gBAAgB,IAAI,GAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media_core.d.cts","names":["BaseStore","Serializable","MediaBlobData","MediaBlobParameters","Record","MediaBlob","Uint8Array","Promise","Blob","Omit","ActionIfInvalidAction","BlobStoreStoreOptions","ActionIfBlobMissingAction","BlobStoreFetchOptions","BlobStoreOptions","BlobStore","BackedBlobStoreOptions","BackedBlobStore","AsyncGenerator","ReadThroughBlobStoreOptions","ReadThroughBlobStore","SimpleWebBlobStore","DataBlobStore","MediaManagerConfiguration","MediaManager"],"sources":["../../../src/experimental/utils/media_core.d.ts"],"sourcesContent":["import { BaseStore } from \"@langchain/core/stores\";\nimport { Serializable } from \"@langchain/core/load/serializable\";\nexport type MediaBlobData = {\n value: string;\n type: string;\n};\nexport interface MediaBlobParameters {\n data?: MediaBlobData;\n metadata?: Record<string, unknown>;\n path?: string;\n}\n/**\n * Represents a chunk of data that can be identified by the path where the\n * data is (or will be) located, along with optional metadata about the data.\n */\nexport declare class MediaBlob extends Serializable implements MediaBlobParameters {\n lc_serializable: boolean;\n lc_namespace: string[];\n data: MediaBlobData;\n metadata?: Record<string, any>;\n path?: string;\n constructor(params: MediaBlobParameters);\n get size(): number;\n get dataType(): string;\n get encoding(): string;\n get mimetype(): string;\n get asBytes(): Uint8Array;\n asString(): Promise<string>;\n asBase64(): Promise<string>;\n asDataUrl(): Promise<string>;\n asUri(): Promise<string>;\n encode(): Promise<{\n encoded: string;\n encoding: string;\n }>;\n static fromDataUrl(url: string): MediaBlob;\n static fromBlob(blob: Blob, other?: Omit<MediaBlobParameters, \"data\">): Promise<MediaBlob>;\n}\nexport type ActionIfInvalidAction = \"ignore\" | \"prefixPath\" | \"prefixUuid1\" | \"prefixUuid4\" | \"prefixUuid6\" | \"prefixUuid7\" | \"removePath\";\nexport interface BlobStoreStoreOptions {\n /**\n * If the path is missing or invalid in the blob, how should we create\n * a new path?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an emtpy string: Reject the blob\n * - \"ignore\": Attempt to store it anyway (but this may fail)\n * - \"prefixPath\": Use the default prefix for the BlobStore and get the\n * unique portion from the URL. The original path is stored in the metadata\n * - \"prefixUuid\": Use the default prefix for the BlobStore and get the\n * unique portion from a generated UUID. The original path is stored\n * in the metadata\n */\n actionIfInvalid?: ActionIfInvalidAction;\n /**\n * The expected prefix for URIs that are stored.\n * This may be used to test if a MediaBlob is valid and used to create a new\n * path if \"prefixPath\" or \"prefixUuid\" is set for actionIfInvalid.\n */\n pathPrefix?: string;\n}\nexport type ActionIfBlobMissingAction = \"emptyBlob\";\nexport interface BlobStoreFetchOptions {\n /**\n * If the blob is not found when fetching, what should we do?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an empty string: return undefined\n * - \"emptyBlob\": return a new MediaBlob that has the path set, but nothing else.\n */\n actionIfBlobMissing?: ActionIfBlobMissingAction;\n}\nexport interface BlobStoreOptions {\n defaultStoreOptions?: BlobStoreStoreOptions;\n defaultFetchOptions?: BlobStoreFetchOptions;\n}\n/**\n * A specialized Store that is designed to handle MediaBlobs and use the\n * key that is included in the blob to determine exactly how it is stored.\n *\n * The full details of a MediaBlob may be changed when it is stored.\n * For example, it may get additional or different Metadata. This should be\n * what is returned when the store() method is called.\n *\n * Although BlobStore extends BaseStore, not all of the methods from\n * BaseStore may be implemented (or even possible). Those that are not\n * implemented should be documented and throw an Error if called.\n */\nexport declare abstract class BlobStore extends BaseStore<string, MediaBlob> {\n lc_namespace: string[];\n defaultStoreOptions: BlobStoreStoreOptions;\n defaultFetchOptions: BlobStoreFetchOptions;\n constructor(opts?: BlobStoreOptions);\n protected _realKey(key: string | MediaBlob): Promise<string>;\n /**\n * Is the path supported by this BlobStore?\n *\n * Although this is async, this is expected to be a relatively fast operation\n * (ie - you shouldn't make network calls).\n *\n * @param path The path to check\n * @param opts Any options (if needed) that may be used to determine if it is valid\n * @return If the path is supported\n */\n hasValidPath(path: string | undefined, opts?: BlobStoreStoreOptions): Promise<boolean>;\n protected _blobPathSuffix(blob: MediaBlob): string;\n protected _newBlob(oldBlob: MediaBlob, newPath?: string): Promise<MediaBlob>;\n protected _validBlobPrefixPath(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob>;\n protected _validBlobPrefixUuidFunction(name: ActionIfInvalidAction | string): string;\n protected _validBlobPrefixUuid(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob>;\n protected _validBlobRemovePath(blob: MediaBlob, _opts?: BlobStoreStoreOptions): Promise<MediaBlob>;\n /**\n * Based on the blob and options, return a blob that has a valid path\n * that can be saved.\n * @param blob\n * @param opts\n */\n protected _validStoreBlob(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;\n store(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;\n protected _missingFetchBlobEmpty(path: string, _opts?: BlobStoreFetchOptions): Promise<MediaBlob>;\n protected _missingFetchBlob(path: string, opts?: BlobStoreFetchOptions): Promise<MediaBlob | undefined>;\n fetch(key: string | MediaBlob, opts?: BlobStoreFetchOptions): Promise<MediaBlob | undefined>;\n}\nexport interface BackedBlobStoreOptions extends BlobStoreOptions {\n backingStore: BaseStore<string, MediaBlob>;\n}\nexport declare class BackedBlobStore extends BlobStore {\n backingStore: BaseStore<string, MediaBlob>;\n constructor(opts: BackedBlobStoreOptions);\n mdelete(keys: string[]): Promise<void>;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mset(keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(prefix: string | undefined): AsyncGenerator<string>;\n}\nexport interface ReadThroughBlobStoreOptions extends BlobStoreOptions {\n baseStore: BlobStore;\n backingStore: BlobStore;\n}\nexport declare class ReadThroughBlobStore extends BlobStore {\n baseStore: BlobStore;\n backingStore: BlobStore;\n constructor(opts: ReadThroughBlobStoreOptions);\n store(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;\n mdelete(keys: string[]): Promise<void>;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(prefix: string | undefined): AsyncGenerator<string>;\n}\nexport declare class SimpleWebBlobStore extends BlobStore {\n _notImplementedException(): void;\n hasValidPath(path: string | undefined, _opts?: BlobStoreStoreOptions): Promise<boolean>;\n _fetch(url: string): Promise<MediaBlob | undefined>;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mdelete(_keys: string[]): Promise<void>;\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(_prefix: string | undefined): AsyncGenerator<string>;\n}\n/**\n * A blob \"store\" that works with data: URLs that will turn the URL into\n * a blob.\n */\nexport declare class DataBlobStore extends BlobStore {\n _notImplementedException(): void;\n hasValidPath(path: string, _opts?: BlobStoreStoreOptions): Promise<boolean>;\n _fetch(url: string): MediaBlob;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mdelete(_keys: string[]): Promise<void>;\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(_prefix: string | undefined): AsyncGenerator<string>;\n}\nexport interface MediaManagerConfiguration {\n /**\n * A store that, given a common URI, returns the corresponding MediaBlob.\n * The returned MediaBlob may have a different URI.\n * In many cases, this will be a ReadThroughStore or something similar\n * that has a cached version of the MediaBlob, but also a way to get\n * a new (or refreshed) version.\n */\n store: BlobStore;\n /**\n * BlobStores that can resolve a URL into the MediaBlob to save\n * in the canonical store. This list is evaluated in order.\n * If not provided, a default list (which involves a DataBlobStore\n * and a SimpleWebBlobStore) will be used.\n */\n resolvers?: BlobStore[];\n}\n/**\n * Responsible for converting a URI (typically a web URL) into a MediaBlob.\n * Allows for aliasing / caching of the requested URI and what it resolves to.\n * This MediaBlob is expected to be usable to provide to an LLM, either\n * through the Base64 of the media or through a canonical URI that the LLM\n * supports.\n */\nexport declare class MediaManager {\n store: BlobStore;\n resolvers: BlobStore[] | undefined;\n constructor(config: MediaManagerConfiguration);\n defaultResolvers(): BlobStore[];\n _isInvalid(blob: MediaBlob | undefined): Promise<boolean>;\n /**\n * Given the public URI, load what is at this URI and save it\n * in the store.\n * @param uri The URI to resolve using the resolver\n * @return A canonical MediaBlob for this URI\n */\n _resolveAndSave(uri: string): Promise<MediaBlob | undefined>;\n getMediaBlob(uri: string): Promise<MediaBlob | undefined>;\n}\n//# sourceMappingURL=media_core.d.ts.map"],"mappings":";;;;KAEYE,aAAAA;;EAAAA,IAAAA,EAAAA,MAAAA;AAIZ,CAAA;AASqBG,UATJF,mBAAAA,CASa;EAGpBD,IAAAA,CAAAA,EAXCA,aAWDA;EACKE,QAAAA,CAAAA,EAXAA,MAWAA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAESD,IAAAA,CAAAA,EAAAA,MAAAA;;;;;;AAUVI,cAhBOF,SAAAA,SAAkBJ,YAAAA,YAAwBE,mBAgBjDI,CAAAA;EAIuBF,eAAAA,EAAAA,OAAAA;EACXG,YAAAA,EAAAA,MAAAA,EAAAA;EAAmBL,IAAAA,EAlBnCD,aAkBmCC;EAALM,QAAAA,CAAAA,EAjBzBL,MAiByBK,CAAAA,MA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XA,KAAA,EAAO,SAAA;EAxWgC;;;;;;EAgXvC,SAAA,GAAY,SAAA;AAAA;;;;;;;;cAUD,YAAA;EACX,KAAA,EAAO,SAAA;EAEP,SAAA,EAAW,SAAA;EAEX,WAAA,CAAY,MAAA,EAAQ,yBAAA;EAKpB,gBAAA,CAAA,GAAoB,SAAA;EAId,UAAA,CAAW,IAAA,EAAM,SAAA,eAAwB,OAAA;EA9U7C;;;;;;EAwVI,eAAA,CAAgB,GAAA,WAAc,OAAA,CAAQ,SAAA;EAkBtC,YAAA,CAAa,GAAA,WAAc,OAAA,CAAQ,SAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media_core.d.ts","names":["BaseStore","Serializable","MediaBlobData","MediaBlobParameters","Record","MediaBlob","Uint8Array","Promise","Blob","Omit","ActionIfInvalidAction","BlobStoreStoreOptions","ActionIfBlobMissingAction","BlobStoreFetchOptions","BlobStoreOptions","BlobStore","BackedBlobStoreOptions","BackedBlobStore","AsyncGenerator","ReadThroughBlobStoreOptions","ReadThroughBlobStore","SimpleWebBlobStore","DataBlobStore","MediaManagerConfiguration","MediaManager"],"sources":["../../../src/experimental/utils/media_core.d.ts"],"sourcesContent":["import { BaseStore } from \"@langchain/core/stores\";\nimport { Serializable } from \"@langchain/core/load/serializable\";\nexport type MediaBlobData = {\n value: string;\n type: string;\n};\nexport interface MediaBlobParameters {\n data?: MediaBlobData;\n metadata?: Record<string, unknown>;\n path?: string;\n}\n/**\n * Represents a chunk of data that can be identified by the path where the\n * data is (or will be) located, along with optional metadata about the data.\n */\nexport declare class MediaBlob extends Serializable implements MediaBlobParameters {\n lc_serializable: boolean;\n lc_namespace: string[];\n data: MediaBlobData;\n metadata?: Record<string, any>;\n path?: string;\n constructor(params: MediaBlobParameters);\n get size(): number;\n get dataType(): string;\n get encoding(): string;\n get mimetype(): string;\n get asBytes(): Uint8Array;\n asString(): Promise<string>;\n asBase64(): Promise<string>;\n asDataUrl(): Promise<string>;\n asUri(): Promise<string>;\n encode(): Promise<{\n encoded: string;\n encoding: string;\n }>;\n static fromDataUrl(url: string): MediaBlob;\n static fromBlob(blob: Blob, other?: Omit<MediaBlobParameters, \"data\">): Promise<MediaBlob>;\n}\nexport type ActionIfInvalidAction = \"ignore\" | \"prefixPath\" | \"prefixUuid1\" | \"prefixUuid4\" | \"prefixUuid6\" | \"prefixUuid7\" | \"removePath\";\nexport interface BlobStoreStoreOptions {\n /**\n * If the path is missing or invalid in the blob, how should we create\n * a new path?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an emtpy string: Reject the blob\n * - \"ignore\": Attempt to store it anyway (but this may fail)\n * - \"prefixPath\": Use the default prefix for the BlobStore and get the\n * unique portion from the URL. The original path is stored in the metadata\n * - \"prefixUuid\": Use the default prefix for the BlobStore and get the\n * unique portion from a generated UUID. The original path is stored\n * in the metadata\n */\n actionIfInvalid?: ActionIfInvalidAction;\n /**\n * The expected prefix for URIs that are stored.\n * This may be used to test if a MediaBlob is valid and used to create a new\n * path if \"prefixPath\" or \"prefixUuid\" is set for actionIfInvalid.\n */\n pathPrefix?: string;\n}\nexport type ActionIfBlobMissingAction = \"emptyBlob\";\nexport interface BlobStoreFetchOptions {\n /**\n * If the blob is not found when fetching, what should we do?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an empty string: return undefined\n * - \"emptyBlob\": return a new MediaBlob that has the path set, but nothing else.\n */\n actionIfBlobMissing?: ActionIfBlobMissingAction;\n}\nexport interface BlobStoreOptions {\n defaultStoreOptions?: BlobStoreStoreOptions;\n defaultFetchOptions?: BlobStoreFetchOptions;\n}\n/**\n * A specialized Store that is designed to handle MediaBlobs and use the\n * key that is included in the blob to determine exactly how it is stored.\n *\n * The full details of a MediaBlob may be changed when it is stored.\n * For example, it may get additional or different Metadata. This should be\n * what is returned when the store() method is called.\n *\n * Although BlobStore extends BaseStore, not all of the methods from\n * BaseStore may be implemented (or even possible). Those that are not\n * implemented should be documented and throw an Error if called.\n */\nexport declare abstract class BlobStore extends BaseStore<string, MediaBlob> {\n lc_namespace: string[];\n defaultStoreOptions: BlobStoreStoreOptions;\n defaultFetchOptions: BlobStoreFetchOptions;\n constructor(opts?: BlobStoreOptions);\n protected _realKey(key: string | MediaBlob): Promise<string>;\n /**\n * Is the path supported by this BlobStore?\n *\n * Although this is async, this is expected to be a relatively fast operation\n * (ie - you shouldn't make network calls).\n *\n * @param path The path to check\n * @param opts Any options (if needed) that may be used to determine if it is valid\n * @return If the path is supported\n */\n hasValidPath(path: string | undefined, opts?: BlobStoreStoreOptions): Promise<boolean>;\n protected _blobPathSuffix(blob: MediaBlob): string;\n protected _newBlob(oldBlob: MediaBlob, newPath?: string): Promise<MediaBlob>;\n protected _validBlobPrefixPath(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob>;\n protected _validBlobPrefixUuidFunction(name: ActionIfInvalidAction | string): string;\n protected _validBlobPrefixUuid(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob>;\n protected _validBlobRemovePath(blob: MediaBlob, _opts?: BlobStoreStoreOptions): Promise<MediaBlob>;\n /**\n * Based on the blob and options, return a blob that has a valid path\n * that can be saved.\n * @param blob\n * @param opts\n */\n protected _validStoreBlob(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;\n store(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;\n protected _missingFetchBlobEmpty(path: string, _opts?: BlobStoreFetchOptions): Promise<MediaBlob>;\n protected _missingFetchBlob(path: string, opts?: BlobStoreFetchOptions): Promise<MediaBlob | undefined>;\n fetch(key: string | MediaBlob, opts?: BlobStoreFetchOptions): Promise<MediaBlob | undefined>;\n}\nexport interface BackedBlobStoreOptions extends BlobStoreOptions {\n backingStore: BaseStore<string, MediaBlob>;\n}\nexport declare class BackedBlobStore extends BlobStore {\n backingStore: BaseStore<string, MediaBlob>;\n constructor(opts: BackedBlobStoreOptions);\n mdelete(keys: string[]): Promise<void>;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mset(keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(prefix: string | undefined): AsyncGenerator<string>;\n}\nexport interface ReadThroughBlobStoreOptions extends BlobStoreOptions {\n baseStore: BlobStore;\n backingStore: BlobStore;\n}\nexport declare class ReadThroughBlobStore extends BlobStore {\n baseStore: BlobStore;\n backingStore: BlobStore;\n constructor(opts: ReadThroughBlobStoreOptions);\n store(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;\n mdelete(keys: string[]): Promise<void>;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(prefix: string | undefined): AsyncGenerator<string>;\n}\nexport declare class SimpleWebBlobStore extends BlobStore {\n _notImplementedException(): void;\n hasValidPath(path: string | undefined, _opts?: BlobStoreStoreOptions): Promise<boolean>;\n _fetch(url: string): Promise<MediaBlob | undefined>;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mdelete(_keys: string[]): Promise<void>;\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(_prefix: string | undefined): AsyncGenerator<string>;\n}\n/**\n * A blob \"store\" that works with data: URLs that will turn the URL into\n * a blob.\n */\nexport declare class DataBlobStore extends BlobStore {\n _notImplementedException(): void;\n hasValidPath(path: string, _opts?: BlobStoreStoreOptions): Promise<boolean>;\n _fetch(url: string): MediaBlob;\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;\n mdelete(_keys: string[]): Promise<void>;\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;\n yieldKeys(_prefix: string | undefined): AsyncGenerator<string>;\n}\nexport interface MediaManagerConfiguration {\n /**\n * A store that, given a common URI, returns the corresponding MediaBlob.\n * The returned MediaBlob may have a different URI.\n * In many cases, this will be a ReadThroughStore or something similar\n * that has a cached version of the MediaBlob, but also a way to get\n * a new (or refreshed) version.\n */\n store: BlobStore;\n /**\n * BlobStores that can resolve a URL into the MediaBlob to save\n * in the canonical store. This list is evaluated in order.\n * If not provided, a default list (which involves a DataBlobStore\n * and a SimpleWebBlobStore) will be used.\n */\n resolvers?: BlobStore[];\n}\n/**\n * Responsible for converting a URI (typically a web URL) into a MediaBlob.\n * Allows for aliasing / caching of the requested URI and what it resolves to.\n * This MediaBlob is expected to be usable to provide to an LLM, either\n * through the Base64 of the media or through a canonical URI that the LLM\n * supports.\n */\nexport declare class MediaManager {\n store: BlobStore;\n resolvers: BlobStore[] | undefined;\n constructor(config: MediaManagerConfiguration);\n defaultResolvers(): BlobStore[];\n _isInvalid(blob: MediaBlob | undefined): Promise<boolean>;\n /**\n * Given the public URI, load what is at this URI and save it\n * in the store.\n * @param uri The URI to resolve using the resolver\n * @return A canonical MediaBlob for this URI\n */\n _resolveAndSave(uri: string): Promise<MediaBlob | undefined>;\n getMediaBlob(uri: string): Promise<MediaBlob | undefined>;\n}\n//# sourceMappingURL=media_core.d.ts.map"],"mappings":";;;;KAEYE,aAAAA;;EAAAA,IAAAA,EAAAA,MAAAA;AAIZ,CAAA;AASqBG,UATJF,mBAAAA,CASa;EAGpBD,IAAAA,CAAAA,EAXCA,aAWDA;EACKE,QAAAA,CAAAA,EAXAA,MAWAA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAESD,IAAAA,CAAAA,EAAAA,MAAAA;;;;;;AAUVI,cAhBOF,SAAAA,SAAkBJ,YAAAA,YAAwBE,mBAgBjDI,CAAAA;EAIuBF,eAAAA,EAAAA,OAAAA;EACXG,YAAAA,EAAAA,MAAAA,EAAAA;EAAmBL,IAAAA,EAlBnCD,aAkBmCC;EAALM,QAAAA,CAAAA,EAjBzBL,MAiByBK,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;EAA4CJ,IAAAA,CAAAA,EAAAA,MAAAA;EAARE,WAAAA,CAAAA,MAAAA,EAfpDJ,mBAeoDI;EArBrCN,IAAAA,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W,SAAA;EAEX,WAAA,CAAY,MAAA,EAAQ,yBAAA;EAKpB,gBAAA,CAAA,GAAoB,SAAA;EAId,UAAA,CAAW,IAAA,EAAM,SAAA,eAAwB,OAAA;EA9U7C;;;;;;EAwVI,eAAA,CAAgB,GAAA,WAAc,OAAA,CAAQ,SAAA;EAkBtC,YAAA,CAAa,GAAA,WAAc,OAAA,CAAQ,SAAA;AAAA"}
|
|
@@ -73,11 +73,9 @@ var MediaBlob = class MediaBlob extends Serializable {
|
|
|
73
73
|
async encode() {
|
|
74
74
|
const dataUrl = await this.asDataUrl();
|
|
75
75
|
const comma = dataUrl.indexOf(",");
|
|
76
|
-
const encoded = dataUrl.substring(comma + 1);
|
|
77
|
-
const encoding = dataUrl.indexOf("base64") > -1 ? "base64" : "8bit";
|
|
78
76
|
return {
|
|
79
|
-
encoded,
|
|
80
|
-
encoding
|
|
77
|
+
encoded: dataUrl.substring(comma + 1),
|
|
78
|
+
encoding: dataUrl.indexOf("base64") > -1 ? "base64" : "8bit"
|
|
81
79
|
};
|
|
82
80
|
}
|
|
83
81
|
static fromDataUrl(url) {
|
|
@@ -86,20 +84,17 @@ var MediaBlob = class MediaBlob extends Serializable {
|
|
|
86
84
|
const semicolon = url.indexOf(";");
|
|
87
85
|
const mimeType = url.substring(colon + 1, semicolon);
|
|
88
86
|
const comma = url.indexOf(",");
|
|
89
|
-
const base64Data = url.substring(comma + 1);
|
|
90
|
-
const data = {
|
|
91
|
-
type: mimeType,
|
|
92
|
-
value: base64Data
|
|
93
|
-
};
|
|
94
87
|
return new MediaBlob({
|
|
95
|
-
data
|
|
88
|
+
data: {
|
|
89
|
+
type: mimeType,
|
|
90
|
+
value: url.substring(comma + 1)
|
|
91
|
+
},
|
|
96
92
|
path: url
|
|
97
93
|
});
|
|
98
94
|
}
|
|
99
95
|
static async fromBlob(blob, other) {
|
|
100
96
|
const valueBuffer = await blob.arrayBuffer();
|
|
101
|
-
const
|
|
102
|
-
const valueStr = bytesToString(valueArray);
|
|
97
|
+
const valueStr = bytesToString(new Uint8Array(valueBuffer));
|
|
103
98
|
const value = btoa(valueStr);
|
|
104
99
|
return new MediaBlob({
|
|
105
100
|
...other,
|
|
@@ -168,9 +163,7 @@ var BlobStore = class extends BaseStore {
|
|
|
168
163
|
return newBlob;
|
|
169
164
|
}
|
|
170
165
|
async _validBlobPrefixPath(blob, opts) {
|
|
171
|
-
const
|
|
172
|
-
const suffix = this._blobPathSuffix(blob);
|
|
173
|
-
const newPath = `${prefix}${suffix}`;
|
|
166
|
+
const newPath = `${opts?.pathPrefix ?? ""}${this._blobPathSuffix(blob)}`;
|
|
174
167
|
return this._newBlob(blob, newPath);
|
|
175
168
|
}
|
|
176
169
|
_validBlobPrefixUuidFunction(name) {
|
|
@@ -181,9 +174,7 @@ var BlobStore = class extends BaseStore {
|
|
|
181
174
|
}
|
|
182
175
|
}
|
|
183
176
|
async _validBlobPrefixUuid(blob, opts) {
|
|
184
|
-
const
|
|
185
|
-
const suffix = this._validBlobPrefixUuidFunction(opts?.actionIfInvalid ?? "prefixUuid4");
|
|
186
|
-
const newPath = `${prefix}${suffix}`;
|
|
177
|
+
const newPath = `${opts?.pathPrefix ?? ""}${this._validBlobPrefixUuidFunction(opts?.actionIfInvalid ?? "prefixUuid4")}`;
|
|
187
178
|
return this._newBlob(blob, newPath);
|
|
188
179
|
}
|
|
189
180
|
async _validBlobRemovePath(blob, _opts) {
|
|
@@ -205,7 +196,7 @@ var BlobStore = class extends BaseStore {
|
|
|
205
196
|
case "prefixUuid6":
|
|
206
197
|
case "prefixUuid7": return this._validBlobPrefixUuid(blob, opts);
|
|
207
198
|
case "removePath": return this._validBlobRemovePath(blob, opts);
|
|
208
|
-
default: return
|
|
199
|
+
default: return;
|
|
209
200
|
}
|
|
210
201
|
}
|
|
211
202
|
async store(blob, opts = {}) {
|
|
@@ -220,7 +211,6 @@ var BlobStore = class extends BaseStore {
|
|
|
220
211
|
const savedKey = await validBlob.asUri();
|
|
221
212
|
return await this.fetch(savedKey);
|
|
222
213
|
}
|
|
223
|
-
return void 0;
|
|
224
214
|
}
|
|
225
215
|
async _missingFetchBlobEmpty(path, _opts) {
|
|
226
216
|
return new MediaBlob({ path });
|
|
@@ -228,7 +218,7 @@ var BlobStore = class extends BaseStore {
|
|
|
228
218
|
async _missingFetchBlob(path, opts) {
|
|
229
219
|
switch (opts?.actionIfBlobMissing) {
|
|
230
220
|
case "emptyBlob": return this._missingFetchBlobEmpty(path, opts);
|
|
231
|
-
default: return
|
|
221
|
+
default: return;
|
|
232
222
|
}
|
|
233
223
|
}
|
|
234
224
|
async fetch(key, opts = {}) {
|
|
@@ -237,8 +227,7 @@ var BlobStore = class extends BaseStore {
|
|
|
237
227
|
...opts
|
|
238
228
|
};
|
|
239
229
|
const realKey = await this._realKey(key);
|
|
240
|
-
|
|
241
|
-
return ret?.[0] ?? await this._missingFetchBlob(realKey, allOpts);
|
|
230
|
+
return (await this.mget([realKey]))?.[0] ?? await this._missingFetchBlob(realKey, allOpts);
|
|
242
231
|
}
|
|
243
232
|
};
|
|
244
233
|
var BackedBlobStore = class extends BlobStore {
|
|
@@ -297,17 +286,13 @@ var SimpleWebBlobStore = class extends BlobStore {
|
|
|
297
286
|
async _fetch(url) {
|
|
298
287
|
const ret = new MediaBlob({ path: url });
|
|
299
288
|
const metadata = {};
|
|
300
|
-
const
|
|
301
|
-
const res = await fetch(url, fetchOptions);
|
|
289
|
+
const res = await fetch(url, { method: "GET" });
|
|
302
290
|
metadata.status = res.status;
|
|
303
291
|
const headers = {};
|
|
304
292
|
for (const [key, value] of res.headers.entries()) headers[key] = value;
|
|
305
293
|
metadata.headers = headers;
|
|
306
294
|
metadata.ok = res.ok;
|
|
307
|
-
if (res.ok)
|
|
308
|
-
const resMediaBlob = await MediaBlob.fromBlob(await res.blob());
|
|
309
|
-
ret.data = resMediaBlob.data;
|
|
310
|
-
}
|
|
295
|
+
if (res.ok) ret.data = (await MediaBlob.fromBlob(await res.blob())).data;
|
|
311
296
|
ret.metadata = metadata;
|
|
312
297
|
return ret;
|
|
313
298
|
}
|
|
@@ -341,8 +326,7 @@ var DataBlobStore = class extends BlobStore {
|
|
|
341
326
|
return MediaBlob.fromDataUrl(url);
|
|
342
327
|
}
|
|
343
328
|
async mget(keys) {
|
|
344
|
-
|
|
345
|
-
return blobMap;
|
|
329
|
+
return keys.map(this._fetch);
|
|
346
330
|
}
|
|
347
331
|
async mdelete(_keys) {
|
|
348
332
|
this._notImplementedException();
|
|
@@ -393,8 +377,7 @@ var MediaManager = class {
|
|
|
393
377
|
}
|
|
394
378
|
async getMediaBlob(uri) {
|
|
395
379
|
const aliasBlob = await this.store.fetch(uri);
|
|
396
|
-
|
|
397
|
-
return ret;
|
|
380
|
+
return await this._isInvalid(aliasBlob) ? await this._resolveAndSave(uri) : aliasBlob;
|
|
398
381
|
}
|
|
399
382
|
};
|
|
400
383
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media_core.js","names":["dataArray: Uint8Array","params: MediaBlobParameters","encoding: string","url: string","data: MediaBlobData","blob: Blob","other?: Omit<MediaBlobParameters, \"data\">","opts?: BlobStoreOptions","key: string | MediaBlob","path: string | undefined","opts?: BlobStoreStoreOptions","blob: MediaBlob","oldBlob: MediaBlob","newPath?: string","name: ActionIfInvalidAction | string","_opts?: BlobStoreStoreOptions","opts: BlobStoreStoreOptions","allOpts: BlobStoreStoreOptions","path: string","_opts?: BlobStoreFetchOptions","opts?: BlobStoreFetchOptions","opts: BlobStoreFetchOptions","allOpts: BlobStoreFetchOptions","opts: BackedBlobStoreOptions","keys: string[]","keyValuePairs: [string, MediaBlob][]","prefix: string | undefined","opts: ReadThroughBlobStoreOptions","_keyValuePairs: [string, MediaBlob][]","metadata: Record<string, unknown>","headers: Record<string, string>","_keys: string[]","_prefix: string | undefined","config: MediaManagerConfiguration","blob: MediaBlob | undefined","uri: string","resolvedBlob: MediaBlob | undefined"],"sources":["../../../src/experimental/utils/media_core.ts"],"sourcesContent":["import { v1, v4 } from \"uuid\"; // FIXME - it is importing the wrong uuid, so v6 and v7 aren't implemented\nimport { BaseStore } from \"@langchain/core/stores\";\nimport { Serializable } from \"@langchain/core/load/serializable\";\n\nexport type MediaBlobData = {\n value: string; // In Base64 encoding\n type: string; // The mime type and possibly encoding\n};\n\nexport interface MediaBlobParameters {\n data?: MediaBlobData;\n\n metadata?: Record<string, unknown>;\n\n path?: string;\n}\n\nfunction bytesToString(dataArray: Uint8Array): string {\n // Need to handle the array in smaller chunks to deal with stack size limits\n let ret = \"\";\n const chunkSize = 102400;\n for (let i = 0; i < dataArray.length; i += chunkSize) {\n const chunk = dataArray.subarray(i, i + chunkSize);\n ret += String.fromCharCode(...chunk);\n }\n\n return ret;\n}\n\n/**\n * Represents a chunk of data that can be identified by the path where the\n * data is (or will be) located, along with optional metadata about the data.\n */\nexport class MediaBlob extends Serializable implements MediaBlobParameters {\n lc_serializable = true;\n\n lc_namespace = [\n \"langchain\",\n \"google_common\",\n \"experimental\",\n \"utils\",\n \"media_core\",\n ];\n\n data: MediaBlobData = {\n value: \"\",\n type: \"text/plain\",\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>;\n\n path?: string;\n\n constructor(params: MediaBlobParameters) {\n super(params);\n\n this.data = params.data ?? this.data;\n this.metadata = params.metadata;\n this.path = params.path;\n }\n\n get size(): number {\n return this.asBytes.length;\n }\n\n get dataType(): string {\n return this.data?.type ?? \"\";\n }\n\n get encoding(): string {\n const charsetEquals = this.dataType.indexOf(\"charset=\");\n return charsetEquals === -1\n ? \"utf-8\"\n : this.dataType.substring(charsetEquals + 8);\n }\n\n get mimetype(): string {\n const semicolon = this.dataType.indexOf(\";\");\n return semicolon === -1\n ? this.dataType\n : this.dataType.substring(0, semicolon);\n }\n\n get asBytes(): Uint8Array {\n if (!this.data) {\n return Uint8Array.from([]);\n }\n const binString = atob(this.data?.value);\n const ret = new Uint8Array(binString.length);\n for (let co = 0; co < binString.length; co += 1) {\n ret[co] = binString.charCodeAt(co);\n }\n return ret;\n }\n\n async asString(): Promise<string> {\n return bytesToString(this.asBytes);\n }\n\n async asBase64(): Promise<string> {\n return this.data?.value ?? \"\";\n }\n\n async asDataUrl(): Promise<string> {\n return `data:${this.mimetype};base64,${await this.asBase64()}`;\n }\n\n async asUri(): Promise<string> {\n return this.path ?? (await this.asDataUrl());\n }\n\n async encode(): Promise<{ encoded: string; encoding: string }> {\n const dataUrl = await this.asDataUrl();\n const comma = dataUrl.indexOf(\",\");\n const encoded = dataUrl.substring(comma + 1);\n const encoding: string = dataUrl.indexOf(\"base64\") > -1 ? \"base64\" : \"8bit\";\n return {\n encoded,\n encoding,\n };\n }\n\n static fromDataUrl(url: string): MediaBlob {\n if (!url.startsWith(\"data:\")) {\n throw new Error(\"Not a data: URL\");\n }\n const colon = url.indexOf(\":\");\n const semicolon = url.indexOf(\";\");\n const mimeType = url.substring(colon + 1, semicolon);\n\n const comma = url.indexOf(\",\");\n const base64Data = url.substring(comma + 1);\n\n const data: MediaBlobData = {\n type: mimeType,\n value: base64Data,\n };\n\n return new MediaBlob({\n data,\n path: url,\n });\n }\n\n static async fromBlob(\n blob: Blob,\n other?: Omit<MediaBlobParameters, \"data\">\n ): Promise<MediaBlob> {\n const valueBuffer = await blob.arrayBuffer();\n const valueArray = new Uint8Array(valueBuffer);\n const valueStr = bytesToString(valueArray);\n const value = btoa(valueStr);\n\n return new MediaBlob({\n ...other,\n data: {\n value,\n type: blob.type,\n },\n });\n }\n}\n\nexport type ActionIfInvalidAction =\n | \"ignore\"\n | \"prefixPath\"\n | \"prefixUuid1\"\n | \"prefixUuid4\"\n | \"prefixUuid6\"\n | \"prefixUuid7\"\n | \"removePath\";\n\nexport interface BlobStoreStoreOptions {\n /**\n * If the path is missing or invalid in the blob, how should we create\n * a new path?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an emtpy string: Reject the blob\n * - \"ignore\": Attempt to store it anyway (but this may fail)\n * - \"prefixPath\": Use the default prefix for the BlobStore and get the\n * unique portion from the URL. The original path is stored in the metadata\n * - \"prefixUuid\": Use the default prefix for the BlobStore and get the\n * unique portion from a generated UUID. The original path is stored\n * in the metadata\n */\n actionIfInvalid?: ActionIfInvalidAction;\n\n /**\n * The expected prefix for URIs that are stored.\n * This may be used to test if a MediaBlob is valid and used to create a new\n * path if \"prefixPath\" or \"prefixUuid\" is set for actionIfInvalid.\n */\n pathPrefix?: string;\n}\n\nexport type ActionIfBlobMissingAction = \"emptyBlob\";\n\nexport interface BlobStoreFetchOptions {\n /**\n * If the blob is not found when fetching, what should we do?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an empty string: return undefined\n * - \"emptyBlob\": return a new MediaBlob that has the path set, but nothing else.\n */\n actionIfBlobMissing?: ActionIfBlobMissingAction;\n}\n\nexport interface BlobStoreOptions {\n defaultStoreOptions?: BlobStoreStoreOptions;\n\n defaultFetchOptions?: BlobStoreFetchOptions;\n}\n\n/**\n * A specialized Store that is designed to handle MediaBlobs and use the\n * key that is included in the blob to determine exactly how it is stored.\n *\n * The full details of a MediaBlob may be changed when it is stored.\n * For example, it may get additional or different Metadata. This should be\n * what is returned when the store() method is called.\n *\n * Although BlobStore extends BaseStore, not all of the methods from\n * BaseStore may be implemented (or even possible). Those that are not\n * implemented should be documented and throw an Error if called.\n */\nexport abstract class BlobStore extends BaseStore<string, MediaBlob> {\n lc_namespace = [\"langchain\", \"google-common\"]; // FIXME - What should this be? And why?\n\n defaultStoreOptions: BlobStoreStoreOptions;\n\n defaultFetchOptions: BlobStoreFetchOptions;\n\n constructor(opts?: BlobStoreOptions) {\n super(opts);\n this.defaultStoreOptions = opts?.defaultStoreOptions ?? {};\n this.defaultFetchOptions = opts?.defaultFetchOptions ?? {};\n }\n\n protected async _realKey(key: string | MediaBlob): Promise<string> {\n return typeof key === \"string\" ? key : await key.asUri();\n }\n\n /**\n * Is the path supported by this BlobStore?\n *\n * Although this is async, this is expected to be a relatively fast operation\n * (ie - you shouldn't make network calls).\n *\n * @param path The path to check\n * @param opts Any options (if needed) that may be used to determine if it is valid\n * @return If the path is supported\n */\n hasValidPath(\n path: string | undefined,\n opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n const prefix = opts?.pathPrefix ?? \"\";\n const isPrefixed = typeof path !== \"undefined\" && path.startsWith(prefix);\n return Promise.resolve(isPrefixed);\n }\n\n protected _blobPathSuffix(blob: MediaBlob): string {\n // Get the path currently set and make sure we treat it as a string\n const blobPath = `${blob.path}`;\n\n // Advance past the first set of /\n let pathStart = blobPath.indexOf(\"/\") + 1;\n while (blobPath.charAt(pathStart) === \"/\") {\n pathStart += 1;\n }\n\n // We will use the rest as the path for a replacement\n return blobPath.substring(pathStart);\n }\n\n protected async _newBlob(\n oldBlob: MediaBlob,\n newPath?: string\n ): Promise<MediaBlob> {\n const oldPath = oldBlob.path;\n const metadata = oldBlob?.metadata ?? {};\n metadata.langchainOldPath = oldPath;\n const newBlob = new MediaBlob({\n ...oldBlob,\n metadata,\n });\n if (newPath) {\n newBlob.path = newPath;\n } else if (newBlob.path) {\n delete newBlob.path;\n }\n return newBlob;\n }\n\n protected async _validBlobPrefixPath(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._blobPathSuffix(blob);\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected _validBlobPrefixUuidFunction(\n name: ActionIfInvalidAction | string\n ): string {\n switch (name) {\n case \"prefixUuid1\":\n return v1();\n case \"prefixUuid4\":\n return v4();\n // case \"prefixUuid6\": return v6();\n // case \"prefixUuid7\": return v7();\n default:\n throw new Error(`Unknown uuid function: ${name}`);\n }\n }\n\n protected async _validBlobPrefixUuid(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._validBlobPrefixUuidFunction(\n opts?.actionIfInvalid ?? \"prefixUuid4\"\n );\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected async _validBlobRemovePath(\n blob: MediaBlob,\n _opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n return this._newBlob(blob, undefined);\n }\n\n /**\n * Based on the blob and options, return a blob that has a valid path\n * that can be saved.\n * @param blob\n * @param opts\n */\n protected async _validStoreBlob(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob | undefined> {\n if (await this.hasValidPath(blob.path, opts)) {\n return blob;\n }\n switch (opts?.actionIfInvalid) {\n case \"ignore\":\n return blob;\n case \"prefixPath\":\n return this._validBlobPrefixPath(blob, opts);\n case \"prefixUuid1\":\n case \"prefixUuid4\":\n case \"prefixUuid6\":\n case \"prefixUuid7\":\n return this._validBlobPrefixUuid(blob, opts);\n case \"removePath\":\n return this._validBlobRemovePath(blob, opts);\n default:\n return undefined;\n }\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreStoreOptions = {\n ...this.defaultStoreOptions,\n ...opts,\n };\n const validBlob = await this._validStoreBlob(blob, allOpts);\n if (typeof validBlob !== \"undefined\") {\n const validKey = await validBlob.asUri();\n await this.mset([[validKey, validBlob]]);\n const savedKey = await validBlob.asUri();\n return await this.fetch(savedKey);\n }\n return undefined;\n }\n\n protected async _missingFetchBlobEmpty(\n path: string,\n _opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob> {\n return new MediaBlob({ path });\n }\n\n protected async _missingFetchBlob(\n path: string,\n opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob | undefined> {\n switch (opts?.actionIfBlobMissing) {\n case \"emptyBlob\":\n return this._missingFetchBlobEmpty(path, opts);\n default:\n return undefined;\n }\n }\n\n async fetch(\n key: string | MediaBlob,\n opts: BlobStoreFetchOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreFetchOptions = {\n ...this.defaultFetchOptions,\n ...opts,\n };\n const realKey = await this._realKey(key);\n const ret = await this.mget([realKey]);\n return ret?.[0] ?? (await this._missingFetchBlob(realKey, allOpts));\n }\n}\n\nexport interface BackedBlobStoreOptions extends BlobStoreOptions {\n backingStore: BaseStore<string, MediaBlob>;\n}\n\nexport class BackedBlobStore extends BlobStore {\n backingStore: BaseStore<string, MediaBlob>;\n\n constructor(opts: BackedBlobStoreOptions) {\n super(opts);\n this.backingStore = opts.backingStore;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.backingStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.backingStore.mget(keys);\n }\n\n mset(keyValuePairs: [string, MediaBlob][]): Promise<void> {\n return this.backingStore.mset(keyValuePairs);\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.backingStore.yieldKeys(prefix);\n }\n}\n\nexport interface ReadThroughBlobStoreOptions extends BlobStoreOptions {\n baseStore: BlobStore;\n backingStore: BlobStore;\n}\n\nexport class ReadThroughBlobStore extends BlobStore {\n baseStore: BlobStore;\n\n backingStore: BlobStore;\n\n constructor(opts: ReadThroughBlobStoreOptions) {\n super(opts);\n this.baseStore = opts.baseStore;\n this.backingStore = opts.backingStore;\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const originalUri = await blob.asUri();\n const newBlob = await this.backingStore.store(blob, opts);\n if (newBlob) {\n await this.baseStore.mset([[originalUri, newBlob]]);\n }\n return newBlob;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.baseStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.baseStore.mget(keys);\n }\n\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n throw new Error(\"Do not call ReadThroughBlobStore.mset directly\");\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.baseStore.yieldKeys(prefix);\n }\n}\n\nexport class SimpleWebBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for SimpleWebBlobStore\");\n }\n\n async hasValidPath(\n path: string | undefined,\n _opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n return (\n (await super.hasValidPath(path, { pathPrefix: \"https://\" })) ||\n (await super.hasValidPath(path, { pathPrefix: \"http://\" }))\n );\n }\n\n async _fetch(url: string): Promise<MediaBlob | undefined> {\n const ret = new MediaBlob({\n path: url,\n });\n const metadata: Record<string, unknown> = {};\n const fetchOptions = {\n method: \"GET\",\n };\n const res = await fetch(url, fetchOptions);\n metadata.status = res.status;\n\n const headers: Record<string, string> = {};\n for (const [key, value] of res.headers.entries()) {\n headers[key] = value;\n }\n metadata.headers = headers;\n\n metadata.ok = res.ok;\n if (res.ok) {\n const resMediaBlob = await MediaBlob.fromBlob(await res.blob());\n ret.data = resMediaBlob.data;\n }\n\n ret.metadata = metadata;\n return ret;\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return await Promise.all(blobMap);\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\n/**\n * A blob \"store\" that works with data: URLs that will turn the URL into\n * a blob.\n */\nexport class DataBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for DataBlobStore\");\n }\n\n hasValidPath(path: string, _opts?: BlobStoreStoreOptions): Promise<boolean> {\n return super.hasValidPath(path, { pathPrefix: \"data:\" });\n }\n\n _fetch(url: string): MediaBlob {\n return MediaBlob.fromDataUrl(url);\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return blobMap;\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\nexport interface MediaManagerConfiguration {\n /**\n * A store that, given a common URI, returns the corresponding MediaBlob.\n * The returned MediaBlob may have a different URI.\n * In many cases, this will be a ReadThroughStore or something similar\n * that has a cached version of the MediaBlob, but also a way to get\n * a new (or refreshed) version.\n */\n store: BlobStore;\n\n /**\n * BlobStores that can resolve a URL into the MediaBlob to save\n * in the canonical store. This list is evaluated in order.\n * If not provided, a default list (which involves a DataBlobStore\n * and a SimpleWebBlobStore) will be used.\n */\n resolvers?: BlobStore[];\n}\n\n/**\n * Responsible for converting a URI (typically a web URL) into a MediaBlob.\n * Allows for aliasing / caching of the requested URI and what it resolves to.\n * This MediaBlob is expected to be usable to provide to an LLM, either\n * through the Base64 of the media or through a canonical URI that the LLM\n * supports.\n */\nexport class MediaManager {\n store: BlobStore;\n\n resolvers: BlobStore[] | undefined;\n\n constructor(config: MediaManagerConfiguration) {\n this.store = config.store;\n this.resolvers = config.resolvers;\n }\n\n defaultResolvers(): BlobStore[] {\n return [new DataBlobStore({}), new SimpleWebBlobStore({})];\n }\n\n async _isInvalid(blob: MediaBlob | undefined): Promise<boolean> {\n return typeof blob === \"undefined\";\n }\n\n /**\n * Given the public URI, load what is at this URI and save it\n * in the store.\n * @param uri The URI to resolve using the resolver\n * @return A canonical MediaBlob for this URI\n */\n async _resolveAndSave(uri: string): Promise<MediaBlob | undefined> {\n let resolvedBlob: MediaBlob | undefined;\n\n const resolvers = this.resolvers || this.defaultResolvers();\n for (let co = 0; co < resolvers.length; co += 1) {\n const resolver = resolvers[co];\n if (await resolver.hasValidPath(uri)) {\n resolvedBlob = await resolver.fetch(uri);\n }\n }\n\n if (resolvedBlob) {\n return await this.store.store(resolvedBlob);\n } else {\n return new MediaBlob({});\n }\n }\n\n async getMediaBlob(uri: string): Promise<MediaBlob | undefined> {\n const aliasBlob = await this.store.fetch(uri);\n const ret = (await this._isInvalid(aliasBlob))\n ? await this._resolveAndSave(uri)\n : (aliasBlob as MediaBlob);\n return ret;\n }\n}\n"],"mappings":";;;;;AAiBA,SAAS,cAAcA,WAA+B;CAEpD,IAAI,MAAM;CACV,MAAM,YAAY;AAClB,MAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK,WAAW;EACpD,MAAM,QAAQ,UAAU,SAAS,GAAG,IAAI,UAAU;EAClD,OAAO,OAAO,aAAa,GAAG,MAAM;CACrC;AAED,QAAO;AACR;;;;;AAMD,IAAa,YAAb,MAAa,kBAAkB,aAA4C;CACzE,kBAAkB;CAElB,eAAe;EACb;EACA;EACA;EACA;EACA;CACD;CAED,OAAsB;EACpB,OAAO;EACP,MAAM;CACP;CAGD;CAEA;CAEA,YAAYC,QAA6B;EACvC,MAAM,OAAO;EAEb,KAAK,OAAO,OAAO,QAAQ,KAAK;EAChC,KAAK,WAAW,OAAO;EACvB,KAAK,OAAO,OAAO;CACpB;CAED,IAAI,OAAe;AACjB,SAAO,KAAK,QAAQ;CACrB;CAED,IAAI,WAAmB;AACrB,SAAO,KAAK,MAAM,QAAQ;CAC3B;CAED,IAAI,WAAmB;EACrB,MAAM,gBAAgB,KAAK,SAAS,QAAQ,WAAW;AACvD,SAAO,kBAAkB,KACrB,UACA,KAAK,SAAS,UAAU,gBAAgB,EAAE;CAC/C;CAED,IAAI,WAAmB;EACrB,MAAM,YAAY,KAAK,SAAS,QAAQ,IAAI;AAC5C,SAAO,cAAc,KACjB,KAAK,WACL,KAAK,SAAS,UAAU,GAAG,UAAU;CAC1C;CAED,IAAI,UAAsB;AACxB,MAAI,CAAC,KAAK,KACR,QAAO,WAAW,KAAK,CAAE,EAAC;EAE5B,MAAM,YAAY,KAAK,KAAK,MAAM,MAAM;EACxC,MAAM,MAAM,IAAI,WAAW,UAAU;AACrC,OAAK,IAAI,KAAK,GAA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,YAAY,IAAI;CAClC;CAED,MAAM,KAAKqB,MAAoD;EAC7D,MAAM,UAAU,KAAK,IAAI,KAAK,OAAO;AACrC,SAAO;CACR;CAED,MAAM,QAAQO,OAAgC;EAC5C,KAAK,0BAA0B;CAChC;CAED,MAAM,KAAKH,gBAAsD;EAC/D,KAAK,0BAA0B;CAChC;CAED,OAAO,UAAUI,SAAqD;EACpE,KAAK,0BAA0B;EAC/B,MAAM;CACP;AACF;;;;;;;;AA4BD,IAAa,eAAb,MAA0B;CACxB;CAEA;CAEA,YAAYC,QAAmC;EAC7C,KAAK,QAAQ,OAAO;EACpB,KAAK,YAAY,OAAO;CACzB;CAED,mBAAgC;AAC9B,SAAO,CAAC,IAAI,cAAc,CAAE,IAAG,IAAI,mBAAmB,CAAE,EAAE;CAC3D;CAED,MAAM,WAAWC,MAA+C;AAC9D,SAAO,OAAO,SAAS;CACxB;;;;;;;CAQD,MAAM,gBAAgBC,KAA6C;EACjE,IAAIC;EAEJ,MAAM,YAAY,KAAK,aAAa,KAAK,kBAAkB;AAC3D,OAAK,IAAI,KAAK,GAAG,KAAK,UAAU,QAAQ,MAAM,GAAG;GAC/C,MAAM,WAAW,UAAU;AAC3B,OAAI,MAAM,SAAS,aAAa,IAAI,EAClC,eAAe,MAAM,SAAS,MAAM,IAAI;EAE3C;AAED,MAAI,aACF,QAAO,MAAM,KAAK,MAAM,MAAM,aAAa;MAE3C,QAAO,IAAI,UAAU,CAAE;CAE1B;CAED,MAAM,aAAaD,KAA6C;EAC9D,MAAM,YAAY,MAAM,KAAK,MAAM,MAAM,IAAI;EAC7C,MAAM,MAAO,MAAM,KAAK,WAAW,UAAU,GACzC,MAAM,KAAK,gBAAgB,IAAI,GAC9B;AACL,SAAO;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"media_core.js","names":[],"sources":["../../../src/experimental/utils/media_core.ts"],"sourcesContent":["import { v1, v4 } from \"uuid\"; // FIXME - it is importing the wrong uuid, so v6 and v7 aren't implemented\nimport { BaseStore } from \"@langchain/core/stores\";\nimport { Serializable } from \"@langchain/core/load/serializable\";\n\nexport type MediaBlobData = {\n value: string; // In Base64 encoding\n type: string; // The mime type and possibly encoding\n};\n\nexport interface MediaBlobParameters {\n data?: MediaBlobData;\n\n metadata?: Record<string, unknown>;\n\n path?: string;\n}\n\nfunction bytesToString(dataArray: Uint8Array): string {\n // Need to handle the array in smaller chunks to deal with stack size limits\n let ret = \"\";\n const chunkSize = 102400;\n for (let i = 0; i < dataArray.length; i += chunkSize) {\n const chunk = dataArray.subarray(i, i + chunkSize);\n ret += String.fromCharCode(...chunk);\n }\n\n return ret;\n}\n\n/**\n * Represents a chunk of data that can be identified by the path where the\n * data is (or will be) located, along with optional metadata about the data.\n */\nexport class MediaBlob extends Serializable implements MediaBlobParameters {\n lc_serializable = true;\n\n lc_namespace = [\n \"langchain\",\n \"google_common\",\n \"experimental\",\n \"utils\",\n \"media_core\",\n ];\n\n data: MediaBlobData = {\n value: \"\",\n type: \"text/plain\",\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata?: Record<string, any>;\n\n path?: string;\n\n constructor(params: MediaBlobParameters) {\n super(params);\n\n this.data = params.data ?? this.data;\n this.metadata = params.metadata;\n this.path = params.path;\n }\n\n get size(): number {\n return this.asBytes.length;\n }\n\n get dataType(): string {\n return this.data?.type ?? \"\";\n }\n\n get encoding(): string {\n const charsetEquals = this.dataType.indexOf(\"charset=\");\n return charsetEquals === -1\n ? \"utf-8\"\n : this.dataType.substring(charsetEquals + 8);\n }\n\n get mimetype(): string {\n const semicolon = this.dataType.indexOf(\";\");\n return semicolon === -1\n ? this.dataType\n : this.dataType.substring(0, semicolon);\n }\n\n get asBytes(): Uint8Array {\n if (!this.data) {\n return Uint8Array.from([]);\n }\n const binString = atob(this.data?.value);\n const ret = new Uint8Array(binString.length);\n for (let co = 0; co < binString.length; co += 1) {\n ret[co] = binString.charCodeAt(co);\n }\n return ret;\n }\n\n async asString(): Promise<string> {\n return bytesToString(this.asBytes);\n }\n\n async asBase64(): Promise<string> {\n return this.data?.value ?? \"\";\n }\n\n async asDataUrl(): Promise<string> {\n return `data:${this.mimetype};base64,${await this.asBase64()}`;\n }\n\n async asUri(): Promise<string> {\n return this.path ?? (await this.asDataUrl());\n }\n\n async encode(): Promise<{ encoded: string; encoding: string }> {\n const dataUrl = await this.asDataUrl();\n const comma = dataUrl.indexOf(\",\");\n const encoded = dataUrl.substring(comma + 1);\n const encoding: string = dataUrl.indexOf(\"base64\") > -1 ? \"base64\" : \"8bit\";\n return {\n encoded,\n encoding,\n };\n }\n\n static fromDataUrl(url: string): MediaBlob {\n if (!url.startsWith(\"data:\")) {\n throw new Error(\"Not a data: URL\");\n }\n const colon = url.indexOf(\":\");\n const semicolon = url.indexOf(\";\");\n const mimeType = url.substring(colon + 1, semicolon);\n\n const comma = url.indexOf(\",\");\n const base64Data = url.substring(comma + 1);\n\n const data: MediaBlobData = {\n type: mimeType,\n value: base64Data,\n };\n\n return new MediaBlob({\n data,\n path: url,\n });\n }\n\n static async fromBlob(\n blob: Blob,\n other?: Omit<MediaBlobParameters, \"data\">\n ): Promise<MediaBlob> {\n const valueBuffer = await blob.arrayBuffer();\n const valueArray = new Uint8Array(valueBuffer);\n const valueStr = bytesToString(valueArray);\n const value = btoa(valueStr);\n\n return new MediaBlob({\n ...other,\n data: {\n value,\n type: blob.type,\n },\n });\n }\n}\n\nexport type ActionIfInvalidAction =\n | \"ignore\"\n | \"prefixPath\"\n | \"prefixUuid1\"\n | \"prefixUuid4\"\n | \"prefixUuid6\"\n | \"prefixUuid7\"\n | \"removePath\";\n\nexport interface BlobStoreStoreOptions {\n /**\n * If the path is missing or invalid in the blob, how should we create\n * a new path?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an emtpy string: Reject the blob\n * - \"ignore\": Attempt to store it anyway (but this may fail)\n * - \"prefixPath\": Use the default prefix for the BlobStore and get the\n * unique portion from the URL. The original path is stored in the metadata\n * - \"prefixUuid\": Use the default prefix for the BlobStore and get the\n * unique portion from a generated UUID. The original path is stored\n * in the metadata\n */\n actionIfInvalid?: ActionIfInvalidAction;\n\n /**\n * The expected prefix for URIs that are stored.\n * This may be used to test if a MediaBlob is valid and used to create a new\n * path if \"prefixPath\" or \"prefixUuid\" is set for actionIfInvalid.\n */\n pathPrefix?: string;\n}\n\nexport type ActionIfBlobMissingAction = \"emptyBlob\";\n\nexport interface BlobStoreFetchOptions {\n /**\n * If the blob is not found when fetching, what should we do?\n * Subclasses may define their own methods, but the following are supported\n * by default:\n * - Undefined or an empty string: return undefined\n * - \"emptyBlob\": return a new MediaBlob that has the path set, but nothing else.\n */\n actionIfBlobMissing?: ActionIfBlobMissingAction;\n}\n\nexport interface BlobStoreOptions {\n defaultStoreOptions?: BlobStoreStoreOptions;\n\n defaultFetchOptions?: BlobStoreFetchOptions;\n}\n\n/**\n * A specialized Store that is designed to handle MediaBlobs and use the\n * key that is included in the blob to determine exactly how it is stored.\n *\n * The full details of a MediaBlob may be changed when it is stored.\n * For example, it may get additional or different Metadata. This should be\n * what is returned when the store() method is called.\n *\n * Although BlobStore extends BaseStore, not all of the methods from\n * BaseStore may be implemented (or even possible). Those that are not\n * implemented should be documented and throw an Error if called.\n */\nexport abstract class BlobStore extends BaseStore<string, MediaBlob> {\n lc_namespace = [\"langchain\", \"google-common\"]; // FIXME - What should this be? And why?\n\n defaultStoreOptions: BlobStoreStoreOptions;\n\n defaultFetchOptions: BlobStoreFetchOptions;\n\n constructor(opts?: BlobStoreOptions) {\n super(opts);\n this.defaultStoreOptions = opts?.defaultStoreOptions ?? {};\n this.defaultFetchOptions = opts?.defaultFetchOptions ?? {};\n }\n\n protected async _realKey(key: string | MediaBlob): Promise<string> {\n return typeof key === \"string\" ? key : await key.asUri();\n }\n\n /**\n * Is the path supported by this BlobStore?\n *\n * Although this is async, this is expected to be a relatively fast operation\n * (ie - you shouldn't make network calls).\n *\n * @param path The path to check\n * @param opts Any options (if needed) that may be used to determine if it is valid\n * @return If the path is supported\n */\n hasValidPath(\n path: string | undefined,\n opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n const prefix = opts?.pathPrefix ?? \"\";\n const isPrefixed = typeof path !== \"undefined\" && path.startsWith(prefix);\n return Promise.resolve(isPrefixed);\n }\n\n protected _blobPathSuffix(blob: MediaBlob): string {\n // Get the path currently set and make sure we treat it as a string\n const blobPath = `${blob.path}`;\n\n // Advance past the first set of /\n let pathStart = blobPath.indexOf(\"/\") + 1;\n while (blobPath.charAt(pathStart) === \"/\") {\n pathStart += 1;\n }\n\n // We will use the rest as the path for a replacement\n return blobPath.substring(pathStart);\n }\n\n protected async _newBlob(\n oldBlob: MediaBlob,\n newPath?: string\n ): Promise<MediaBlob> {\n const oldPath = oldBlob.path;\n const metadata = oldBlob?.metadata ?? {};\n metadata.langchainOldPath = oldPath;\n const newBlob = new MediaBlob({\n ...oldBlob,\n metadata,\n });\n if (newPath) {\n newBlob.path = newPath;\n } else if (newBlob.path) {\n delete newBlob.path;\n }\n return newBlob;\n }\n\n protected async _validBlobPrefixPath(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._blobPathSuffix(blob);\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected _validBlobPrefixUuidFunction(\n name: ActionIfInvalidAction | string\n ): string {\n switch (name) {\n case \"prefixUuid1\":\n return v1();\n case \"prefixUuid4\":\n return v4();\n // case \"prefixUuid6\": return v6();\n // case \"prefixUuid7\": return v7();\n default:\n throw new Error(`Unknown uuid function: ${name}`);\n }\n }\n\n protected async _validBlobPrefixUuid(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n const prefix = opts?.pathPrefix ?? \"\";\n const suffix = this._validBlobPrefixUuidFunction(\n opts?.actionIfInvalid ?? \"prefixUuid4\"\n );\n const newPath = `${prefix}${suffix}`;\n return this._newBlob(blob, newPath);\n }\n\n protected async _validBlobRemovePath(\n blob: MediaBlob,\n _opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob> {\n return this._newBlob(blob, undefined);\n }\n\n /**\n * Based on the blob and options, return a blob that has a valid path\n * that can be saved.\n * @param blob\n * @param opts\n */\n protected async _validStoreBlob(\n blob: MediaBlob,\n opts?: BlobStoreStoreOptions\n ): Promise<MediaBlob | undefined> {\n if (await this.hasValidPath(blob.path, opts)) {\n return blob;\n }\n switch (opts?.actionIfInvalid) {\n case \"ignore\":\n return blob;\n case \"prefixPath\":\n return this._validBlobPrefixPath(blob, opts);\n case \"prefixUuid1\":\n case \"prefixUuid4\":\n case \"prefixUuid6\":\n case \"prefixUuid7\":\n return this._validBlobPrefixUuid(blob, opts);\n case \"removePath\":\n return this._validBlobRemovePath(blob, opts);\n default:\n return undefined;\n }\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreStoreOptions = {\n ...this.defaultStoreOptions,\n ...opts,\n };\n const validBlob = await this._validStoreBlob(blob, allOpts);\n if (typeof validBlob !== \"undefined\") {\n const validKey = await validBlob.asUri();\n await this.mset([[validKey, validBlob]]);\n const savedKey = await validBlob.asUri();\n return await this.fetch(savedKey);\n }\n return undefined;\n }\n\n protected async _missingFetchBlobEmpty(\n path: string,\n _opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob> {\n return new MediaBlob({ path });\n }\n\n protected async _missingFetchBlob(\n path: string,\n opts?: BlobStoreFetchOptions\n ): Promise<MediaBlob | undefined> {\n switch (opts?.actionIfBlobMissing) {\n case \"emptyBlob\":\n return this._missingFetchBlobEmpty(path, opts);\n default:\n return undefined;\n }\n }\n\n async fetch(\n key: string | MediaBlob,\n opts: BlobStoreFetchOptions = {}\n ): Promise<MediaBlob | undefined> {\n const allOpts: BlobStoreFetchOptions = {\n ...this.defaultFetchOptions,\n ...opts,\n };\n const realKey = await this._realKey(key);\n const ret = await this.mget([realKey]);\n return ret?.[0] ?? (await this._missingFetchBlob(realKey, allOpts));\n }\n}\n\nexport interface BackedBlobStoreOptions extends BlobStoreOptions {\n backingStore: BaseStore<string, MediaBlob>;\n}\n\nexport class BackedBlobStore extends BlobStore {\n backingStore: BaseStore<string, MediaBlob>;\n\n constructor(opts: BackedBlobStoreOptions) {\n super(opts);\n this.backingStore = opts.backingStore;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.backingStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.backingStore.mget(keys);\n }\n\n mset(keyValuePairs: [string, MediaBlob][]): Promise<void> {\n return this.backingStore.mset(keyValuePairs);\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.backingStore.yieldKeys(prefix);\n }\n}\n\nexport interface ReadThroughBlobStoreOptions extends BlobStoreOptions {\n baseStore: BlobStore;\n backingStore: BlobStore;\n}\n\nexport class ReadThroughBlobStore extends BlobStore {\n baseStore: BlobStore;\n\n backingStore: BlobStore;\n\n constructor(opts: ReadThroughBlobStoreOptions) {\n super(opts);\n this.baseStore = opts.baseStore;\n this.backingStore = opts.backingStore;\n }\n\n async store(\n blob: MediaBlob,\n opts: BlobStoreStoreOptions = {}\n ): Promise<MediaBlob | undefined> {\n const originalUri = await blob.asUri();\n const newBlob = await this.backingStore.store(blob, opts);\n if (newBlob) {\n await this.baseStore.mset([[originalUri, newBlob]]);\n }\n return newBlob;\n }\n\n mdelete(keys: string[]): Promise<void> {\n return this.baseStore.mdelete(keys);\n }\n\n mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n return this.baseStore.mget(keys);\n }\n\n mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n throw new Error(\"Do not call ReadThroughBlobStore.mset directly\");\n }\n\n yieldKeys(prefix: string | undefined): AsyncGenerator<string> {\n return this.baseStore.yieldKeys(prefix);\n }\n}\n\nexport class SimpleWebBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for SimpleWebBlobStore\");\n }\n\n async hasValidPath(\n path: string | undefined,\n _opts?: BlobStoreStoreOptions\n ): Promise<boolean> {\n return (\n (await super.hasValidPath(path, { pathPrefix: \"https://\" })) ||\n (await super.hasValidPath(path, { pathPrefix: \"http://\" }))\n );\n }\n\n async _fetch(url: string): Promise<MediaBlob | undefined> {\n const ret = new MediaBlob({\n path: url,\n });\n const metadata: Record<string, unknown> = {};\n const fetchOptions = {\n method: \"GET\",\n };\n const res = await fetch(url, fetchOptions);\n metadata.status = res.status;\n\n const headers: Record<string, string> = {};\n for (const [key, value] of res.headers.entries()) {\n headers[key] = value;\n }\n metadata.headers = headers;\n\n metadata.ok = res.ok;\n if (res.ok) {\n const resMediaBlob = await MediaBlob.fromBlob(await res.blob());\n ret.data = resMediaBlob.data;\n }\n\n ret.metadata = metadata;\n return ret;\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return await Promise.all(blobMap);\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\n/**\n * A blob \"store\" that works with data: URLs that will turn the URL into\n * a blob.\n */\nexport class DataBlobStore extends BlobStore {\n _notImplementedException() {\n throw new Error(\"Not implemented for DataBlobStore\");\n }\n\n hasValidPath(path: string, _opts?: BlobStoreStoreOptions): Promise<boolean> {\n return super.hasValidPath(path, { pathPrefix: \"data:\" });\n }\n\n _fetch(url: string): MediaBlob {\n return MediaBlob.fromDataUrl(url);\n }\n\n async mget(keys: string[]): Promise<(MediaBlob | undefined)[]> {\n const blobMap = keys.map(this._fetch);\n return blobMap;\n }\n\n async mdelete(_keys: string[]): Promise<void> {\n this._notImplementedException();\n }\n\n async mset(_keyValuePairs: [string, MediaBlob][]): Promise<void> {\n this._notImplementedException();\n }\n\n async *yieldKeys(_prefix: string | undefined): AsyncGenerator<string> {\n this._notImplementedException();\n yield \"\";\n }\n}\n\nexport interface MediaManagerConfiguration {\n /**\n * A store that, given a common URI, returns the corresponding MediaBlob.\n * The returned MediaBlob may have a different URI.\n * In many cases, this will be a ReadThroughStore or something similar\n * that has a cached version of the MediaBlob, but also a way to get\n * a new (or refreshed) version.\n */\n store: BlobStore;\n\n /**\n * BlobStores that can resolve a URL into the MediaBlob to save\n * in the canonical store. This list is evaluated in order.\n * If not provided, a default list (which involves a DataBlobStore\n * and a SimpleWebBlobStore) will be used.\n */\n resolvers?: BlobStore[];\n}\n\n/**\n * Responsible for converting a URI (typically a web URL) into a MediaBlob.\n * Allows for aliasing / caching of the requested URI and what it resolves to.\n * This MediaBlob is expected to be usable to provide to an LLM, either\n * through the Base64 of the media or through a canonical URI that the LLM\n * supports.\n */\nexport class MediaManager {\n store: BlobStore;\n\n resolvers: BlobStore[] | undefined;\n\n constructor(config: MediaManagerConfiguration) {\n this.store = config.store;\n this.resolvers = config.resolvers;\n }\n\n defaultResolvers(): BlobStore[] {\n return [new DataBlobStore({}), new SimpleWebBlobStore({})];\n }\n\n async _isInvalid(blob: MediaBlob | undefined): Promise<boolean> {\n return typeof blob === \"undefined\";\n }\n\n /**\n * Given the public URI, load what is at this URI and save it\n * in the store.\n * @param uri The URI to resolve using the resolver\n * @return A canonical MediaBlob for this URI\n */\n async _resolveAndSave(uri: string): Promise<MediaBlob | undefined> {\n let resolvedBlob: MediaBlob | undefined;\n\n const resolvers = this.resolvers || this.defaultResolvers();\n for (let co = 0; co < resolvers.length; co += 1) {\n const resolver = resolvers[co];\n if (await resolver.hasValidPath(uri)) {\n resolvedBlob = await resolver.fetch(uri);\n }\n }\n\n if (resolvedBlob) {\n return await this.store.store(resolvedBlob);\n } else {\n return new MediaBlob({});\n }\n }\n\n async getMediaBlob(uri: string): Promise<MediaBlob | undefined> {\n const aliasBlob = await this.store.fetch(uri);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OAAO,SAAS;;;;;;;;CASzB,MAAM,gBAAgB,KAA6C;EACjE,IAAI;EAEJ,MAAM,YAAY,KAAK,aAAa,KAAK,kBAAkB;AAC3D,OAAK,IAAI,KAAK,GAAG,KAAK,UAAU,QAAQ,MAAM,GAAG;GAC/C,MAAM,WAAW,UAAU;AAC3B,OAAI,MAAM,SAAS,aAAa,IAAI,CAClC,gBAAe,MAAM,SAAS,MAAM,IAAI;;AAI5C,MAAI,aACF,QAAO,MAAM,KAAK,MAAM,MAAM,aAAa;MAE3C,QAAO,IAAI,UAAU,EAAE,CAAC;;CAI5B,MAAM,aAAa,KAA6C;EAC9D,MAAM,YAAY,MAAM,KAAK,MAAM,MAAM,IAAI;AAI7C,SAHa,MAAM,KAAK,WAAW,UAAU,GACzC,MAAM,KAAK,gBAAgB,IAAI,GAC9B"}
|
package/dist/index.cjs
CHANGED
package/dist/llms.cjs
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
1
|
const require_gemini = require('./utils/gemini.cjs');
|
|
3
2
|
const require_common = require('./utils/common.cjs');
|
|
4
3
|
const require_failed_handler = require('./utils/failed_handler.cjs');
|
|
5
4
|
const require_connection = require('./connection.cjs');
|
|
6
5
|
const require_auth = require('./auth.cjs');
|
|
7
6
|
const require_chat_models = require('./chat_models.cjs');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
let _langchain_core_utils_env = require("@langchain/core/utils/env");
|
|
8
|
+
let _langchain_core_outputs = require("@langchain/core/outputs");
|
|
9
|
+
let _langchain_core_callbacks_manager = require("@langchain/core/callbacks/manager");
|
|
10
|
+
let _langchain_core_language_models_llms = require("@langchain/core/language_models/llms");
|
|
12
11
|
|
|
13
12
|
//#region src/llms.ts
|
|
14
13
|
var GoogleLLMConnection = class extends require_connection.AbstractGoogleLLMConnection {
|
|
15
14
|
async formatContents(input, _parameters) {
|
|
16
|
-
|
|
17
|
-
const contents = [{
|
|
15
|
+
return [{
|
|
18
16
|
role: "user",
|
|
19
|
-
parts
|
|
17
|
+
parts: await this.api.messageContentToParts(input)
|
|
20
18
|
}];
|
|
21
|
-
return contents;
|
|
22
19
|
}
|
|
23
20
|
};
|
|
24
21
|
var ProxyChatGoogle = class extends require_chat_models.ChatGoogleBase {
|
|
@@ -32,7 +29,7 @@ var ProxyChatGoogle = class extends require_chat_models.ChatGoogleBase {
|
|
|
32
29
|
/**
|
|
33
30
|
* Integration with an LLM.
|
|
34
31
|
*/
|
|
35
|
-
var GoogleBaseLLM = class extends
|
|
32
|
+
var GoogleBaseLLM = class extends _langchain_core_language_models_llms.LLM {
|
|
36
33
|
static lc_name() {
|
|
37
34
|
return "GoogleLLM";
|
|
38
35
|
}
|
|
@@ -65,7 +62,7 @@ var GoogleBaseLLM = class extends __langchain_core_language_models_llms.LLM {
|
|
|
65
62
|
return new require_auth.ApiKeyGoogleAuth(apiKey);
|
|
66
63
|
}
|
|
67
64
|
buildApiKey(fields) {
|
|
68
|
-
return fields?.apiKey ?? (0,
|
|
65
|
+
return fields?.apiKey ?? (0, _langchain_core_utils_env.getEnvironmentVariable)("GOOGLE_API_KEY");
|
|
69
66
|
}
|
|
70
67
|
buildClient(fields) {
|
|
71
68
|
const apiKey = this.buildApiKey(fields);
|
|
@@ -100,25 +97,24 @@ var GoogleBaseLLM = class extends __langchain_core_language_models_llms.LLM {
|
|
|
100
97
|
async _call(prompt, options) {
|
|
101
98
|
const parameters = require_common.copyAIModelParams(this, options);
|
|
102
99
|
const result = await this.connection.request(prompt, parameters, options);
|
|
103
|
-
|
|
104
|
-
return ret;
|
|
100
|
+
return this.connection.api.responseToString(result);
|
|
105
101
|
}
|
|
106
102
|
async *_streamIterator(input, options) {
|
|
107
|
-
const prompt =
|
|
103
|
+
const prompt = _langchain_core_language_models_llms.BaseLLM._convertInputToPromptValue(input);
|
|
108
104
|
const [runnableConfig, callOptions] = this._separateRunnableConfigFromCallOptions(options);
|
|
109
|
-
const callbackManager_ = await
|
|
105
|
+
const callbackManager_ = await _langchain_core_callbacks_manager.CallbackManager.configure(runnableConfig.callbacks, this.callbacks, runnableConfig.tags, this.tags, runnableConfig.metadata, this.metadata, { verbose: this.verbose });
|
|
110
106
|
const extra = {
|
|
111
107
|
options: callOptions,
|
|
112
108
|
invocation_params: this?.invocationParams(callOptions),
|
|
113
109
|
batch_size: 1
|
|
114
110
|
};
|
|
115
111
|
const runManagers = await callbackManager_?.handleLLMStart(this.toJSON(), [prompt.toString()], void 0, void 0, extra, void 0, void 0, runnableConfig.runName);
|
|
116
|
-
let generation = new
|
|
112
|
+
let generation = new _langchain_core_outputs.GenerationChunk({ text: "" });
|
|
117
113
|
const proxyChat = this.createProxyChat();
|
|
118
114
|
try {
|
|
119
115
|
for await (const chunk of proxyChat._streamIterator(input, options)) {
|
|
120
116
|
const stringValue = this.connection.api.chunkToString(chunk);
|
|
121
|
-
const generationChunk = new
|
|
117
|
+
const generationChunk = new _langchain_core_outputs.GenerationChunk({ text: stringValue });
|
|
122
118
|
generation = generation.concat(generationChunk);
|
|
123
119
|
yield stringValue;
|
|
124
120
|
}
|
|
@@ -131,8 +127,7 @@ var GoogleBaseLLM = class extends __langchain_core_language_models_llms.LLM {
|
|
|
131
127
|
async predictMessages(messages, options, _callbacks) {
|
|
132
128
|
const { content } = messages[0];
|
|
133
129
|
const result = await this.connection.request(content, {}, options);
|
|
134
|
-
|
|
135
|
-
return ret;
|
|
130
|
+
return this.connection.api.responseToBaseMessage(result);
|
|
136
131
|
}
|
|
137
132
|
/**
|
|
138
133
|
* Internal implementation detail to allow Google LLMs to support
|