@getzep/zep-js
Advanced tools
Comparing version 0.5.0-alpha.0 to 0.5.0
export { ZepClient } from "./zep-client"; | ||
export { Memory, Message, MessageData, Summary, SummaryData, MemoryData, MemorySearchPayload, MemorySearchPayloadData, MemorySearchResult, MemorySearchResultData, APIError, } from "./models"; | ||
export { Memory, Message, MessageData, Summary, SummaryData, MemoryData, MemorySearchPayload, MemorySearchPayloadData, MemorySearchResult, MemorySearchResultData, Session, SessionData, APIError, } from "./models"; | ||
export { UnexpectedResponseError, NotFoundError, AuthenticationError, } from "./exceptions"; |
export { ZepClient } from "./zep-client"; | ||
export { Memory, Message, Summary, MemorySearchPayload, MemorySearchResult, APIError, } from "./models"; | ||
export { Memory, Message, Summary, MemorySearchPayload, MemorySearchResult, Session, APIError, } from "./models"; | ||
export { UnexpectedResponseError, NotFoundError, AuthenticationError, } from "./exceptions"; |
/** | ||
* Interface for Session data. | ||
*/ | ||
export interface SessionData { | ||
uuid?: string; | ||
created_at?: string; | ||
updated_at?: string; | ||
deleted_at?: string; | ||
session_id: string; | ||
metadata: Record<string, any>; | ||
} | ||
/** | ||
* Represents a session object with a unique identifier, metadata, and other attributes. | ||
*/ | ||
export declare class Session { | ||
uuid?: string; | ||
created_at?: string; | ||
updated_at?: string; | ||
deleted_at?: string; | ||
session_id: string; | ||
metadata: Record<string, any>; | ||
/** | ||
* Constructs a new Session instance. | ||
* @param {SessionData} data - The data to create a Session instance. | ||
*/ | ||
constructor(data: SessionData); | ||
/** | ||
* Converts the Session instance to a dictionary. | ||
* @returns {SessionData} A dictionary representation of Session instance. | ||
*/ | ||
toDict(): SessionData; | ||
} | ||
/** | ||
* MessageData interface for providing input to create a Message instance. | ||
@@ -3,0 +35,0 @@ */ |
/** | ||
* Represents a session object with a unique identifier, metadata, and other attributes. | ||
*/ | ||
export class Session { | ||
/** | ||
* Constructs a new Session instance. | ||
* @param {SessionData} data - The data to create a Session instance. | ||
*/ | ||
constructor(data) { | ||
this.uuid = data.uuid; | ||
this.created_at = data.created_at; | ||
this.updated_at = data.updated_at; | ||
this.deleted_at = data.deleted_at; | ||
this.session_id = data.session_id; | ||
this.metadata = data.metadata; | ||
} | ||
/** | ||
* Converts the Session instance to a dictionary. | ||
* @returns {SessionData} A dictionary representation of Session instance. | ||
*/ | ||
toDict() { | ||
return { | ||
uuid: this.uuid, | ||
created_at: this.created_at, | ||
updated_at: this.updated_at, | ||
deleted_at: this.deleted_at, | ||
session_id: this.session_id, | ||
metadata: this.metadata, | ||
}; | ||
} | ||
} | ||
/** | ||
* Represents a message in the memory. | ||
@@ -3,0 +34,0 @@ */ |
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { Memory, Message, NotFoundError, Summary, UnexpectedResponseError, ZepClient } from "../"; | ||
import { Memory, Message, NotFoundError, Session, Summary, UnexpectedResponseError, ZepClient, } from "../"; | ||
const BASE_URL = "http://localhost:8000"; | ||
@@ -27,3 +27,3 @@ const fetchMock = global.fetch; | ||
status: 200, | ||
body: JSON.stringify({}) | ||
body: JSON.stringify({}), | ||
}); | ||
@@ -34,2 +34,31 @@ }); | ||
}); | ||
describe("ZepClient Session", () => { | ||
it("retrieves the correct session when sessionId is provided", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const expectedSessionId = "test-session"; | ||
const expectedSessionData = { | ||
uuid: "uuid", | ||
created_at: "2022-01-01T00:00:00Z", | ||
updated_at: "2022-01-01T00:00:00Z", | ||
session_id: expectedSessionId, | ||
metadata: {}, | ||
}; | ||
fetchMock.mockResponseOnce(JSON.stringify(expectedSessionData)); | ||
const session = yield client.getSession(expectedSessionId); | ||
expect(session.toDict()).toEqual(expectedSessionData); | ||
})); | ||
}); | ||
describe("ZepClient Session", () => { | ||
it("adds a session correctly when valid session data is provided", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const expectedSessionId = "test-session"; | ||
const sessionData = { | ||
session_id: expectedSessionId, | ||
metadata: { "foo": "bar" }, | ||
}; | ||
const session = new Session(sessionData); | ||
const expectedResponseText = "Session added successfully"; | ||
fetchMock.mockResponseOnce(expectedResponseText); | ||
const responseText = yield client.addSession(session); | ||
expect(responseText).toEqual(expectedResponseText); | ||
})); | ||
}); | ||
// Test Suite for getMemory() | ||
@@ -46,4 +75,4 @@ describe("getMemory", () => { | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
} | ||
token_count: 0, | ||
}, | ||
}; | ||
@@ -59,5 +88,5 @@ fetchMock.mockResponseOnce(JSON.stringify(responseData)); | ||
token_count: 0, | ||
uuid: "" | ||
uuid: "", | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
})); | ||
@@ -80,4 +109,4 @@ })); | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
} | ||
token_count: 0, | ||
}, | ||
}; | ||
@@ -93,5 +122,5 @@ fetchMock.mockResponseOnce(JSON.stringify(responseData)); | ||
token_count: 0, | ||
uuid: "" | ||
uuid: "", | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
})); | ||
@@ -109,3 +138,3 @@ })); | ||
{ role: "system", content: "How can I assist you?" }, | ||
{ role: "human", content: "What's the weather like?" } | ||
{ role: "human", content: "What's the weather like?" }, | ||
], | ||
@@ -117,4 +146,4 @@ summary: { | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
} | ||
token_count: 0, | ||
}, | ||
}; | ||
@@ -128,8 +157,8 @@ // Mock fetch call with specific URL and parameters | ||
role: "system", | ||
content: "How can I assist you?" | ||
content: "How can I assist you?", | ||
}), | ||
new Message({ | ||
role: "human", | ||
content: "What's the weather like?" | ||
}) | ||
content: "What's the weather like?", | ||
}), | ||
], | ||
@@ -141,5 +170,5 @@ summary: new Summary({ | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
token_count: 0, | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
})); | ||
@@ -157,5 +186,5 @@ })); | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
token_count: 0, | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
}); | ||
@@ -170,3 +199,3 @@ fetchMock.mockResponseOnce("OK"); | ||
messages: [ | ||
new Message({ role: "system", content: "System message" }) | ||
new Message({ role: "system", content: "System message" }), | ||
], | ||
@@ -178,5 +207,5 @@ summary: new Summary({ | ||
recent_message_uuid: "recent_message_uuid", | ||
token_count: 0 | ||
token_count: 0, | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
}); | ||
@@ -215,6 +244,6 @@ // Mock a status code that is unexpected (500 in this case) | ||
where: { | ||
jsonpath: '$.system.entities[*] ? (@.Label == "WORK_OF_ART")' | ||
} | ||
jsonpath: '$.system.entities[*] ? (@.Label == "WORK_OF_ART")', | ||
}, | ||
}, | ||
text: "system message" | ||
text: "system message", | ||
}; | ||
@@ -227,8 +256,8 @@ const responseData = [ | ||
uuid: "message_uuid", | ||
created_at: "2023-01-01T00:00:00Z" | ||
created_at: "2023-01-01T00:00:00Z", | ||
}, | ||
dist: undefined, | ||
summary: undefined, | ||
metadata: {} | ||
} | ||
metadata: {}, | ||
}, | ||
]; | ||
@@ -244,3 +273,3 @@ fetchMock.mockResponseOnce(JSON.stringify(responseData)); | ||
metadata: { metadata_key: "metadata_value" }, | ||
text: "search text" // Replace with actual text | ||
text: "search text", // Replace with actual text | ||
}; | ||
@@ -255,3 +284,3 @@ fetchMock.mockResponseOnce(JSON.stringify({}), { status: 404 }); | ||
metadata: { metadata_key: "metadata_value" }, | ||
text: "search text" // Replace with actual text | ||
text: "search text", // Replace with actual text | ||
}; | ||
@@ -258,0 +287,0 @@ fetchMock.mockResponseOnce(JSON.stringify({}), { status: 500 }); |
@@ -1,2 +0,2 @@ | ||
import { Memory, MemorySearchPayload, MemorySearchResult } from "./models"; | ||
import { Memory, MemorySearchPayload, MemorySearchResult, Session } from "./models"; | ||
/** | ||
@@ -15,2 +15,8 @@ * ZepClient is a Typescript class for interacting with the Zep. | ||
/** | ||
* Constructs the full URL for an API endpoint. | ||
* @param {string} endpoint - The endpoint of the API. | ||
* @returns {string} The full URL. | ||
*/ | ||
getFullUrl(endpoint: string): string; | ||
/** | ||
* Initializes the ZepClient instance by checking if the server is running. | ||
@@ -23,2 +29,21 @@ * @returns {Promise<boolean>} - A promise that returns true if the server | ||
/** | ||
* Retrieves a session with the specified ID. | ||
* | ||
* @param {string} sessionId - The ID of the session to retrieve. | ||
* @returns {Promise<Session>} A promise that resolves to the Session object. | ||
* @throws {Error} Will throw an error if the sessionId is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
getSession(sessionId: string): Promise<Session>; | ||
/** | ||
* Adds or updates a session. | ||
* | ||
* @param {Session} session - The Session object to add or update. | ||
* @returns {Promise<string>} A promise that resolves to the response text from the server. | ||
* @throws {Error} Will throw an error if the session is not provided. | ||
* @throws {Error} Will throw an error if the session.session_id is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
addSession(session: Session): Promise<string>; | ||
/** | ||
* Retrieves memory for a specific session. | ||
@@ -25,0 +50,0 @@ * @param {string} sessionID - The ID of the session to retrieve memory for. |
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { Memory, MemorySearchResult, Message, } from "./models"; | ||
import { Memory, MemorySearchResult, Message, Session, } from "./models"; | ||
import { AuthenticationError, NotFoundError, UnexpectedResponseError, } from "./exceptions"; | ||
@@ -64,2 +64,10 @@ const API_BASEURL = "/api/v1"; | ||
/** | ||
* Constructs the full URL for an API endpoint. | ||
* @param {string} endpoint - The endpoint of the API. | ||
* @returns {string} The full URL. | ||
*/ | ||
getFullUrl(endpoint) { | ||
return `${this.baseURL}${API_BASEURL}${endpoint}`; | ||
} | ||
/** | ||
* Initializes the ZepClient instance by checking if the server is running. | ||
@@ -79,2 +87,65 @@ * @returns {Promise<boolean>} - A promise that returns true if the server | ||
/** | ||
* Retrieves a session with the specified ID. | ||
* | ||
* @param {string} sessionId - The ID of the session to retrieve. | ||
* @returns {Promise<Session>} A promise that resolves to the Session object. | ||
* @throws {Error} Will throw an error if the sessionId is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
getSession(sessionId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!sessionId || sessionId.trim() === "") { | ||
throw new Error("sessionId must be provided"); | ||
} | ||
const url = this.getFullUrl(`/sessions/${sessionId}`); | ||
try { | ||
const response = yield handleRequest(fetch(url, { headers: this.headers }), `No session found for session ${sessionId}`); | ||
const responseData = yield response.json(); | ||
return new Session(responseData); | ||
} | ||
catch (error) { | ||
if (error instanceof TypeError && | ||
error.message === "Failed to fetch") { | ||
throw new Error("Failed to connect to server"); | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
/** | ||
* Adds or updates a session. | ||
* | ||
* @param {Session} session - The Session object to add or update. | ||
* @returns {Promise<string>} A promise that resolves to the response text from the server. | ||
* @throws {Error} Will throw an error if the session is not provided. | ||
* @throws {Error} Will throw an error if the session.session_id is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
addSession(session) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!session) { | ||
throw new Error("session must be provided"); | ||
} | ||
if (!session.session_id || session.session_id.trim() === "") { | ||
throw new Error("session.session_id must be provided"); | ||
} | ||
const url = this.getFullUrl(`/sessions/${session.session_id}`); | ||
try { | ||
const response = yield handleRequest(fetch(url, { | ||
method: "POST", | ||
headers: Object.assign(Object.assign({}, this.headers), { "Content-Type": "application/json" }), | ||
body: JSON.stringify(session.toDict()), | ||
}), `Failed to add session ${session.session_id}`); | ||
return yield response.text(); | ||
} | ||
catch (error) { | ||
if (error instanceof TypeError && | ||
error.message === "Failed to fetch") { | ||
throw new Error("Failed to connect to server"); | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
/** | ||
* Retrieves memory for a specific session. | ||
@@ -87,3 +158,3 @@ * @param {string} sessionID - The ID of the session to retrieve memory for. | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/memory`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/memory`); | ||
const params = lastn !== undefined ? `?lastn=${lastn}` : ""; | ||
@@ -113,3 +184,3 @@ const response = yield handleRequest(fetch(`${url}${params}`, { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/memory`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/memory`); | ||
const response = yield handleRequest(fetch(url, { | ||
@@ -132,3 +203,3 @@ method: "POST", | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/memory`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/memory`); | ||
const response = yield handleRequest(fetch(url, { | ||
@@ -152,3 +223,3 @@ method: "DELETE", | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/search`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/search`); | ||
const params = limit !== undefined ? `?limit=${limit}` : ""; | ||
@@ -155,0 +226,0 @@ const response = yield handleRequest(fetch(`${url}${params}`, { |
export { ZepClient } from "./zep-client"; | ||
export { Memory, Message, MessageData, Summary, SummaryData, MemoryData, MemorySearchPayload, MemorySearchPayloadData, MemorySearchResult, MemorySearchResultData, APIError, } from "./models"; | ||
export { Memory, Message, MessageData, Summary, SummaryData, MemoryData, MemorySearchPayload, MemorySearchPayloadData, MemorySearchResult, MemorySearchResultData, Session, SessionData, APIError, } from "./models"; | ||
export { UnexpectedResponseError, NotFoundError, AuthenticationError, } from "./exceptions"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AuthenticationError = exports.NotFoundError = exports.UnexpectedResponseError = exports.APIError = exports.MemorySearchResult = exports.MemorySearchPayload = exports.Summary = exports.Message = exports.Memory = exports.ZepClient = void 0; | ||
exports.AuthenticationError = exports.NotFoundError = exports.UnexpectedResponseError = exports.APIError = exports.Session = exports.MemorySearchResult = exports.MemorySearchPayload = exports.Summary = exports.Message = exports.Memory = exports.ZepClient = void 0; | ||
var zep_client_1 = require("./zep-client"); | ||
@@ -12,2 +12,3 @@ Object.defineProperty(exports, "ZepClient", { enumerable: true, get: function () { return zep_client_1.ZepClient; } }); | ||
Object.defineProperty(exports, "MemorySearchResult", { enumerable: true, get: function () { return models_1.MemorySearchResult; } }); | ||
Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return models_1.Session; } }); | ||
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return models_1.APIError; } }); | ||
@@ -14,0 +15,0 @@ var exceptions_1 = require("./exceptions"); |
/** | ||
* Interface for Session data. | ||
*/ | ||
export interface SessionData { | ||
uuid?: string; | ||
created_at?: string; | ||
updated_at?: string; | ||
deleted_at?: string; | ||
session_id: string; | ||
metadata: Record<string, any>; | ||
} | ||
/** | ||
* Represents a session object with a unique identifier, metadata, and other attributes. | ||
*/ | ||
export declare class Session { | ||
uuid?: string; | ||
created_at?: string; | ||
updated_at?: string; | ||
deleted_at?: string; | ||
session_id: string; | ||
metadata: Record<string, any>; | ||
/** | ||
* Constructs a new Session instance. | ||
* @param {SessionData} data - The data to create a Session instance. | ||
*/ | ||
constructor(data: SessionData); | ||
/** | ||
* Converts the Session instance to a dictionary. | ||
* @returns {SessionData} A dictionary representation of Session instance. | ||
*/ | ||
toDict(): SessionData; | ||
} | ||
/** | ||
* MessageData interface for providing input to create a Message instance. | ||
@@ -3,0 +35,0 @@ */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.APIError = exports.MemorySearchResult = exports.MemorySearchPayload = exports.Memory = exports.Summary = exports.Message = void 0; | ||
exports.APIError = exports.MemorySearchResult = exports.MemorySearchPayload = exports.Memory = exports.Summary = exports.Message = exports.Session = void 0; | ||
/** | ||
* Represents a session object with a unique identifier, metadata, and other attributes. | ||
*/ | ||
class Session { | ||
/** | ||
* Constructs a new Session instance. | ||
* @param {SessionData} data - The data to create a Session instance. | ||
*/ | ||
constructor(data) { | ||
this.uuid = data.uuid; | ||
this.created_at = data.created_at; | ||
this.updated_at = data.updated_at; | ||
this.deleted_at = data.deleted_at; | ||
this.session_id = data.session_id; | ||
this.metadata = data.metadata; | ||
} | ||
/** | ||
* Converts the Session instance to a dictionary. | ||
* @returns {SessionData} A dictionary representation of Session instance. | ||
*/ | ||
toDict() { | ||
return { | ||
uuid: this.uuid, | ||
created_at: this.created_at, | ||
updated_at: this.updated_at, | ||
deleted_at: this.deleted_at, | ||
session_id: this.session_id, | ||
metadata: this.metadata, | ||
}; | ||
} | ||
} | ||
exports.Session = Session; | ||
/** | ||
* Represents a message in the memory. | ||
@@ -6,0 +38,0 @@ */ |
@@ -28,3 +28,3 @@ "use strict"; | ||
status: 200, | ||
body: JSON.stringify({}) | ||
body: JSON.stringify({}), | ||
}); | ||
@@ -35,2 +35,31 @@ }); | ||
}); | ||
describe("ZepClient Session", () => { | ||
it("retrieves the correct session when sessionId is provided", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const expectedSessionId = "test-session"; | ||
const expectedSessionData = { | ||
uuid: "uuid", | ||
created_at: "2022-01-01T00:00:00Z", | ||
updated_at: "2022-01-01T00:00:00Z", | ||
session_id: expectedSessionId, | ||
metadata: {}, | ||
}; | ||
fetchMock.mockResponseOnce(JSON.stringify(expectedSessionData)); | ||
const session = yield client.getSession(expectedSessionId); | ||
expect(session.toDict()).toEqual(expectedSessionData); | ||
})); | ||
}); | ||
describe("ZepClient Session", () => { | ||
it("adds a session correctly when valid session data is provided", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const expectedSessionId = "test-session"; | ||
const sessionData = { | ||
session_id: expectedSessionId, | ||
metadata: { "foo": "bar" }, | ||
}; | ||
const session = new __1.Session(sessionData); | ||
const expectedResponseText = "Session added successfully"; | ||
fetchMock.mockResponseOnce(expectedResponseText); | ||
const responseText = yield client.addSession(session); | ||
expect(responseText).toEqual(expectedResponseText); | ||
})); | ||
}); | ||
// Test Suite for getMemory() | ||
@@ -47,4 +76,4 @@ describe("getMemory", () => { | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
} | ||
token_count: 0, | ||
}, | ||
}; | ||
@@ -60,5 +89,5 @@ fetchMock.mockResponseOnce(JSON.stringify(responseData)); | ||
token_count: 0, | ||
uuid: "" | ||
uuid: "", | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
})); | ||
@@ -81,4 +110,4 @@ })); | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
} | ||
token_count: 0, | ||
}, | ||
}; | ||
@@ -94,5 +123,5 @@ fetchMock.mockResponseOnce(JSON.stringify(responseData)); | ||
token_count: 0, | ||
uuid: "" | ||
uuid: "", | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
})); | ||
@@ -110,3 +139,3 @@ })); | ||
{ role: "system", content: "How can I assist you?" }, | ||
{ role: "human", content: "What's the weather like?" } | ||
{ role: "human", content: "What's the weather like?" }, | ||
], | ||
@@ -118,4 +147,4 @@ summary: { | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
} | ||
token_count: 0, | ||
}, | ||
}; | ||
@@ -129,8 +158,8 @@ // Mock fetch call with specific URL and parameters | ||
role: "system", | ||
content: "How can I assist you?" | ||
content: "How can I assist you?", | ||
}), | ||
new __1.Message({ | ||
role: "human", | ||
content: "What's the weather like?" | ||
}) | ||
content: "What's the weather like?", | ||
}), | ||
], | ||
@@ -142,5 +171,5 @@ summary: new __1.Summary({ | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
token_count: 0, | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
})); | ||
@@ -158,5 +187,5 @@ })); | ||
recent_message_uuid: "", | ||
token_count: 0 | ||
token_count: 0, | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
}); | ||
@@ -171,3 +200,3 @@ fetchMock.mockResponseOnce("OK"); | ||
messages: [ | ||
new __1.Message({ role: "system", content: "System message" }) | ||
new __1.Message({ role: "system", content: "System message" }), | ||
], | ||
@@ -179,5 +208,5 @@ summary: new __1.Summary({ | ||
recent_message_uuid: "recent_message_uuid", | ||
token_count: 0 | ||
token_count: 0, | ||
}), | ||
metadata: {} | ||
metadata: {}, | ||
}); | ||
@@ -216,6 +245,6 @@ // Mock a status code that is unexpected (500 in this case) | ||
where: { | ||
jsonpath: '$.system.entities[*] ? (@.Label == "WORK_OF_ART")' | ||
} | ||
jsonpath: '$.system.entities[*] ? (@.Label == "WORK_OF_ART")', | ||
}, | ||
}, | ||
text: "system message" | ||
text: "system message", | ||
}; | ||
@@ -228,8 +257,8 @@ const responseData = [ | ||
uuid: "message_uuid", | ||
created_at: "2023-01-01T00:00:00Z" | ||
created_at: "2023-01-01T00:00:00Z", | ||
}, | ||
dist: undefined, | ||
summary: undefined, | ||
metadata: {} | ||
} | ||
metadata: {}, | ||
}, | ||
]; | ||
@@ -245,3 +274,3 @@ fetchMock.mockResponseOnce(JSON.stringify(responseData)); | ||
metadata: { metadata_key: "metadata_value" }, | ||
text: "search text" // Replace with actual text | ||
text: "search text", // Replace with actual text | ||
}; | ||
@@ -256,3 +285,3 @@ fetchMock.mockResponseOnce(JSON.stringify({}), { status: 404 }); | ||
metadata: { metadata_key: "metadata_value" }, | ||
text: "search text" // Replace with actual text | ||
text: "search text", // Replace with actual text | ||
}; | ||
@@ -259,0 +288,0 @@ fetchMock.mockResponseOnce(JSON.stringify({}), { status: 500 }); |
@@ -1,2 +0,2 @@ | ||
import { Memory, MemorySearchPayload, MemorySearchResult } from "./models"; | ||
import { Memory, MemorySearchPayload, MemorySearchResult, Session } from "./models"; | ||
/** | ||
@@ -15,2 +15,8 @@ * ZepClient is a Typescript class for interacting with the Zep. | ||
/** | ||
* Constructs the full URL for an API endpoint. | ||
* @param {string} endpoint - The endpoint of the API. | ||
* @returns {string} The full URL. | ||
*/ | ||
getFullUrl(endpoint: string): string; | ||
/** | ||
* Initializes the ZepClient instance by checking if the server is running. | ||
@@ -23,2 +29,21 @@ * @returns {Promise<boolean>} - A promise that returns true if the server | ||
/** | ||
* Retrieves a session with the specified ID. | ||
* | ||
* @param {string} sessionId - The ID of the session to retrieve. | ||
* @returns {Promise<Session>} A promise that resolves to the Session object. | ||
* @throws {Error} Will throw an error if the sessionId is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
getSession(sessionId: string): Promise<Session>; | ||
/** | ||
* Adds or updates a session. | ||
* | ||
* @param {Session} session - The Session object to add or update. | ||
* @returns {Promise<string>} A promise that resolves to the response text from the server. | ||
* @throws {Error} Will throw an error if the session is not provided. | ||
* @throws {Error} Will throw an error if the session.session_id is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
addSession(session: Session): Promise<string>; | ||
/** | ||
* Retrieves memory for a specific session. | ||
@@ -25,0 +50,0 @@ * @param {string} sessionID - The ID of the session to retrieve memory for. |
@@ -66,2 +66,10 @@ "use strict"; | ||
/** | ||
* Constructs the full URL for an API endpoint. | ||
* @param {string} endpoint - The endpoint of the API. | ||
* @returns {string} The full URL. | ||
*/ | ||
getFullUrl(endpoint) { | ||
return `${this.baseURL}${API_BASEURL}${endpoint}`; | ||
} | ||
/** | ||
* Initializes the ZepClient instance by checking if the server is running. | ||
@@ -81,2 +89,65 @@ * @returns {Promise<boolean>} - A promise that returns true if the server | ||
/** | ||
* Retrieves a session with the specified ID. | ||
* | ||
* @param {string} sessionId - The ID of the session to retrieve. | ||
* @returns {Promise<Session>} A promise that resolves to the Session object. | ||
* @throws {Error} Will throw an error if the sessionId is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
getSession(sessionId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!sessionId || sessionId.trim() === "") { | ||
throw new Error("sessionId must be provided"); | ||
} | ||
const url = this.getFullUrl(`/sessions/${sessionId}`); | ||
try { | ||
const response = yield handleRequest(fetch(url, { headers: this.headers }), `No session found for session ${sessionId}`); | ||
const responseData = yield response.json(); | ||
return new models_1.Session(responseData); | ||
} | ||
catch (error) { | ||
if (error instanceof TypeError && | ||
error.message === "Failed to fetch") { | ||
throw new Error("Failed to connect to server"); | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
/** | ||
* Adds or updates a session. | ||
* | ||
* @param {Session} session - The Session object to add or update. | ||
* @returns {Promise<string>} A promise that resolves to the response text from the server. | ||
* @throws {Error} Will throw an error if the session is not provided. | ||
* @throws {Error} Will throw an error if the session.session_id is not provided. | ||
* @throws {Error} Will throw an error if the fetch request fails. | ||
*/ | ||
addSession(session) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!session) { | ||
throw new Error("session must be provided"); | ||
} | ||
if (!session.session_id || session.session_id.trim() === "") { | ||
throw new Error("session.session_id must be provided"); | ||
} | ||
const url = this.getFullUrl(`/sessions/${session.session_id}`); | ||
try { | ||
const response = yield handleRequest(fetch(url, { | ||
method: "POST", | ||
headers: Object.assign(Object.assign({}, this.headers), { "Content-Type": "application/json" }), | ||
body: JSON.stringify(session.toDict()), | ||
}), `Failed to add session ${session.session_id}`); | ||
return yield response.text(); | ||
} | ||
catch (error) { | ||
if (error instanceof TypeError && | ||
error.message === "Failed to fetch") { | ||
throw new Error("Failed to connect to server"); | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
/** | ||
* Retrieves memory for a specific session. | ||
@@ -89,3 +160,3 @@ * @param {string} sessionID - The ID of the session to retrieve memory for. | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/memory`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/memory`); | ||
const params = lastn !== undefined ? `?lastn=${lastn}` : ""; | ||
@@ -115,3 +186,3 @@ const response = yield handleRequest(fetch(`${url}${params}`, { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/memory`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/memory`); | ||
const response = yield handleRequest(fetch(url, { | ||
@@ -134,3 +205,3 @@ method: "POST", | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/memory`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/memory`); | ||
const response = yield handleRequest(fetch(url, { | ||
@@ -154,3 +225,3 @@ method: "DELETE", | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${this.baseURL}${API_BASEURL}/sessions/${sessionID}/search`; | ||
const url = this.getFullUrl(`/sessions/${sessionID}/search`); | ||
const params = limit !== undefined ? `?limit=${limit}` : ""; | ||
@@ -157,0 +228,0 @@ const response = yield handleRequest(fetch(`${url}${params}`, { |
{ | ||
"show-config": "tsc --showConfig", | ||
"name": "@getzep/zep-js", | ||
"version": "0.5.0-alpha.0", | ||
"version": "0.5.0", | ||
"description": "Zep JS Client", | ||
@@ -6,0 +6,0 @@ "private": false, |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
95766
2015
14