@langchain/langgraph-sdk
Version:
Client library for interacting with the LangGraph API
128 lines (127 loc) • 3.77 kB
JavaScript
const require_base = require("../base.cjs");
//#region src/client/store/index.ts
var StoreClient = class extends require_base.BaseClient {
/**
* Store or update an item.
*
* @param namespace A list of strings representing the namespace path.
* @param key The unique identifier for the item within the namespace.
* @param value A dictionary containing the item's data.
* @param options.index Controls search indexing - null (use defaults), false (disable), or list of field paths to index.
* @param options.ttl Optional time-to-live in minutes for the item, or null for no expiration.
* @returns Promise<void>
*/
async putItem(namespace, key, value, options) {
namespace.forEach((label) => {
if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
});
const payload = {
namespace,
key,
value,
index: options?.index,
ttl: options?.ttl
};
return this.fetch("/store/items", {
method: "PUT",
json: payload,
signal: options?.signal
});
}
/**
* Retrieve a single item.
*
* @param namespace A list of strings representing the namespace path.
* @param key The unique identifier for the item.
* @param options.refreshTtl Whether to refresh the TTL on this read operation.
* @returns Promise<Item>
*/
async getItem(namespace, key, options) {
namespace.forEach((label) => {
if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
});
const params = {
namespace: namespace.join("."),
key
};
if (options?.refreshTtl !== void 0) params.refresh_ttl = options.refreshTtl;
const response = await this.fetch("/store/items", {
params,
signal: options?.signal
});
return response ? {
...response,
createdAt: response.created_at,
updatedAt: response.updated_at
} : null;
}
/**
* Delete an item.
*
* @param namespace A list of strings representing the namespace path.
* @param key The unique identifier for the item.
* @returns Promise<void>
*/
async deleteItem(namespace, key, options) {
namespace.forEach((label) => {
if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
});
return this.fetch("/store/items", {
method: "DELETE",
json: {
namespace,
key
},
signal: options?.signal
});
}
/**
* Search for items within a namespace prefix.
*
* @param namespacePrefix List of strings representing the namespace prefix.
* @param options Search options including filter, pagination, and query.
* @returns Promise<SearchItemsResponse>
*/
async searchItems(namespacePrefix, options) {
const payload = {
namespace_prefix: namespacePrefix,
filter: options?.filter,
limit: options?.limit ?? 10,
offset: options?.offset ?? 0,
query: options?.query,
refresh_ttl: options?.refreshTtl
};
return { items: (await this.fetch("/store/items/search", {
method: "POST",
json: payload,
signal: options?.signal
})).items.map((item) => ({
...item,
createdAt: item.created_at,
updatedAt: item.updated_at
})) };
}
/**
* List namespaces with optional match conditions.
*
* @param options Filtering and pagination options for namespaces.
* @returns Promise<ListNamespaceResponse>
*/
async listNamespaces(options) {
const payload = {
prefix: options?.prefix,
suffix: options?.suffix,
max_depth: options?.maxDepth,
limit: options?.limit ?? 100,
offset: options?.offset ?? 0
};
return this.fetch("/store/namespaces", {
method: "POST",
json: payload,
signal: options?.signal
});
}
};
//#endregion
exports.StoreClient = StoreClient;
//# sourceMappingURL=index.cjs.map