UNPKG

@langchain/langgraph-sdk

Version:

Client library for interacting with the LangGraph API

1 lines • 7.19 kB
{"version":3,"file":"index.cjs","names":["BaseClient"],"sources":["../../../src/client/store/index.ts"],"sourcesContent":["import {\n Item,\n ListNamespaceResponse,\n SearchItemsResponse,\n} from \"../../schema.js\";\nimport { BaseClient } from \"../base.js\";\n\ninterface APIItem {\n namespace: string[];\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: Record<string, any>;\n created_at: string;\n updated_at: string;\n}\ninterface APISearchItemsResponse {\n items: APIItem[];\n}\n\nexport class StoreClient extends BaseClient {\n /**\n * Store or update an item.\n *\n * @param namespace A list of strings representing the namespace path.\n * @param key The unique identifier for the item within the namespace.\n * @param value A dictionary containing the item's data.\n * @param options.index Controls search indexing - null (use defaults), false (disable), or list of field paths to index.\n * @param options.ttl Optional time-to-live in minutes for the item, or null for no expiration.\n * @returns Promise<void>\n */\n async putItem(\n namespace: string[],\n key: string,\n value: Record<string, unknown>,\n options?: {\n index?: false | string[] | null;\n ttl?: number | null;\n signal?: AbortSignal;\n }\n ): Promise<void> {\n namespace.forEach((label) => {\n if (label.includes(\".\")) {\n throw new Error(\n `Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`\n );\n }\n });\n\n const payload = {\n namespace,\n key,\n value,\n index: options?.index,\n ttl: options?.ttl,\n };\n\n return this.fetch<void>(\"/store/items\", {\n method: \"PUT\",\n json: payload,\n signal: options?.signal,\n });\n }\n\n /**\n * Retrieve a single item.\n *\n * @param namespace A list of strings representing the namespace path.\n * @param key The unique identifier for the item.\n * @param options.refreshTtl Whether to refresh the TTL on this read operation.\n * @returns Promise<Item>\n */\n async getItem(\n namespace: string[],\n key: string,\n options?: {\n refreshTtl?: boolean | null;\n signal?: AbortSignal;\n }\n ): Promise<Item | null> {\n namespace.forEach((label) => {\n if (label.includes(\".\")) {\n throw new Error(\n `Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`\n );\n }\n });\n\n const params: Record<string, unknown> = {\n namespace: namespace.join(\".\"),\n key,\n };\n\n if (options?.refreshTtl !== undefined) {\n params.refresh_ttl = options.refreshTtl;\n }\n\n const response = await this.fetch<APIItem>(\"/store/items\", {\n params,\n signal: options?.signal,\n });\n\n return response\n ? {\n ...response,\n createdAt: response.created_at,\n updatedAt: response.updated_at,\n }\n : null;\n }\n\n /**\n * Delete an item.\n *\n * @param namespace A list of strings representing the namespace path.\n * @param key The unique identifier for the item.\n * @returns Promise<void>\n */\n async deleteItem(\n namespace: string[],\n key: string,\n options?: { signal?: AbortSignal }\n ): Promise<void> {\n namespace.forEach((label) => {\n if (label.includes(\".\")) {\n throw new Error(\n `Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`\n );\n }\n });\n\n return this.fetch<void>(\"/store/items\", {\n method: \"DELETE\",\n json: { namespace, key },\n signal: options?.signal,\n });\n }\n\n /**\n * Search for items within a namespace prefix.\n *\n * @param namespacePrefix List of strings representing the namespace prefix.\n * @param options Search options including filter, pagination, and query.\n * @returns Promise<SearchItemsResponse>\n */\n async searchItems(\n namespacePrefix: string[],\n options?: {\n filter?: Record<string, unknown>;\n limit?: number;\n offset?: number;\n query?: string;\n refreshTtl?: boolean | null;\n signal?: AbortSignal;\n }\n ): Promise<SearchItemsResponse> {\n const payload = {\n namespace_prefix: namespacePrefix,\n filter: options?.filter,\n limit: options?.limit ?? 10,\n offset: options?.offset ?? 0,\n query: options?.query,\n refresh_ttl: options?.refreshTtl,\n };\n\n const response = await this.fetch<APISearchItemsResponse>(\n \"/store/items/search\",\n {\n method: \"POST\",\n json: payload,\n signal: options?.signal,\n }\n );\n return {\n items: response.items.map((item) => ({\n ...item,\n createdAt: item.created_at,\n updatedAt: item.updated_at,\n })),\n };\n }\n\n /**\n * List namespaces with optional match conditions.\n *\n * @param options Filtering and pagination options for namespaces.\n * @returns Promise<ListNamespaceResponse>\n */\n async listNamespaces(options?: {\n prefix?: string[];\n suffix?: string[];\n maxDepth?: number;\n limit?: number;\n offset?: number;\n signal?: AbortSignal;\n }): Promise<ListNamespaceResponse> {\n const payload = {\n prefix: options?.prefix,\n suffix: options?.suffix,\n max_depth: options?.maxDepth,\n limit: options?.limit ?? 100,\n offset: options?.offset ?? 0,\n };\n\n return this.fetch<ListNamespaceResponse>(\"/store/namespaces\", {\n method: \"POST\",\n json: payload,\n signal: options?.signal,\n });\n }\n}\n"],"mappings":";;AAmBA,IAAa,cAAb,cAAiCA,aAAAA,WAAW;;;;;;;;;;;CAW1C,MAAM,QACJ,WACA,KACA,OACA,SAKe;AACf,YAAU,SAAS,UAAU;AAC3B,OAAI,MAAM,SAAS,IAAI,CACrB,OAAM,IAAI,MACR,4BAA4B,MAAM,kDACnC;IAEH;EAEF,MAAM,UAAU;GACd;GACA;GACA;GACA,OAAO,SAAS;GAChB,KAAK,SAAS;GACf;AAED,SAAO,KAAK,MAAY,gBAAgB;GACtC,QAAQ;GACR,MAAM;GACN,QAAQ,SAAS;GAClB,CAAC;;;;;;;;;;CAWJ,MAAM,QACJ,WACA,KACA,SAIsB;AACtB,YAAU,SAAS,UAAU;AAC3B,OAAI,MAAM,SAAS,IAAI,CACrB,OAAM,IAAI,MACR,4BAA4B,MAAM,kDACnC;IAEH;EAEF,MAAM,SAAkC;GACtC,WAAW,UAAU,KAAK,IAAI;GAC9B;GACD;AAED,MAAI,SAAS,eAAe,KAAA,EAC1B,QAAO,cAAc,QAAQ;EAG/B,MAAM,WAAW,MAAM,KAAK,MAAe,gBAAgB;GACzD;GACA,QAAQ,SAAS;GAClB,CAAC;AAEF,SAAO,WACH;GACE,GAAG;GACH,WAAW,SAAS;GACpB,WAAW,SAAS;GACrB,GACD;;;;;;;;;CAUN,MAAM,WACJ,WACA,KACA,SACe;AACf,YAAU,SAAS,UAAU;AAC3B,OAAI,MAAM,SAAS,IAAI,CACrB,OAAM,IAAI,MACR,4BAA4B,MAAM,kDACnC;IAEH;AAEF,SAAO,KAAK,MAAY,gBAAgB;GACtC,QAAQ;GACR,MAAM;IAAE;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