@alexein/sdk 0.0.0-stage → 0.3.0
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 +35 -0
- package/LICENSE +21 -0
- package/README.md +238 -2
- package/dist/chunk-7KPDU3YV.cjs +920 -0
- package/dist/chunk-OVDZ3D4M.js +101 -0
- package/dist/chunk-TLAHP2PB.cjs +101 -0
- package/dist/chunk-UNVZ22EN.js +920 -0
- package/dist/client-YKZ4fkK-.d.cts +641 -0
- package/dist/client-YKZ4fkK-.d.ts +641 -0
- package/dist/index.cjs +36 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +36 -0
- package/dist/langgraph.cjs +185 -0
- package/dist/langgraph.d.cts +93 -0
- package/dist/langgraph.d.ts +93 -0
- package/dist/langgraph.js +185 -0
- package/dist/openai-agents.cjs +234 -0
- package/dist/openai-agents.d.cts +101 -0
- package/dist/openai-agents.d.ts +101 -0
- package/dist/openai-agents.js +234 -0
- package/dist/shared-Btg8LbKC.d.cts +23 -0
- package/dist/shared-Btg8LbKC.d.ts +23 -0
- package/package.json +127 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export { A as AddOptions, a as AddResult, b as AddedItem, c as Adding, d as AppUser, e as Author, C as Correction, D as DEFAULT_BASE_URL, f as DEFAULT_RETRIES, g as DEFAULT_TIMEOUT_MS, h as Deleted, E as Erased, i as Excerpt, j as ExportPage, k as ExportRecord, F as Fact, l as FactsPage, m as Filters, n as FollowUp, o as ForgetOptions, p as Forgotten, G as GrepOptions, H as History, I as Item, q as ItemDefaults, r as ItemStatus, s as ItemsOptions, t as ItemsPage, J as Json, K as Known, L as LatestOptions, M as Me, u as Memories, v as Memory, w as MemoryEntry, x as MemoryOptions, O as OpenItem, y as OpenItems, z as OpenItemsOptions, B as Opened, N as Origin, P as PageOptions, S as SearchOptions, Q as SearchResult, R as Source, T as Sources, U as Statuses, V as StoredItem, W as Summary, X as User, Y as UsersPage, Z as Value, _ as VersionEntry, $ as Versions } from './client-YKZ4fkK-.cjs';
|
|
2
|
+
|
|
3
|
+
declare const VERSION = "0.3.0";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What can go wrong, one class per thing a caller would handle differently: the same classes as
|
|
7
|
+
* the Python client's, so what is true of an error there is true here.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** One field a 422 named, and what it takes. */
|
|
11
|
+
interface FieldError {
|
|
12
|
+
/** Where in the body: `query`, `items[0].text`; empty for the body itself. */
|
|
13
|
+
field: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
interface ErrorFields {
|
|
17
|
+
status?: number | null;
|
|
18
|
+
detail?: string;
|
|
19
|
+
errors?: FieldError[];
|
|
20
|
+
requestId?: string | null;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Every error this client throws. */
|
|
24
|
+
declare class AlexeinError extends Error {
|
|
25
|
+
/** The HTTP status, or null when no response came back. */
|
|
26
|
+
readonly status: number | null;
|
|
27
|
+
/** The API's own explanation; for a transport failure, what went wrong. */
|
|
28
|
+
readonly detail: string;
|
|
29
|
+
/** On a 422: each field the body got wrong. Empty otherwise. */
|
|
30
|
+
readonly errors: FieldError[];
|
|
31
|
+
/**
|
|
32
|
+
* The request's id: the `X-Request-Id` this client sent, which the API logs and answers with.
|
|
33
|
+
* Quote it when you ask for help, or find the request in the console's request logs.
|
|
34
|
+
*/
|
|
35
|
+
readonly requestId: string | null;
|
|
36
|
+
constructor(message: string, fields?: ErrorFields);
|
|
37
|
+
/**
|
|
38
|
+
* Whether this means memory is unavailable - unreachable, too slow, too busy or failing - rather
|
|
39
|
+
* than that the request or the key is wrong. A `failOpen` client rides out an outage; a mistake
|
|
40
|
+
* still throws.
|
|
41
|
+
*/
|
|
42
|
+
get outage(): boolean;
|
|
43
|
+
}
|
|
44
|
+
/** 401: no key, or one the service did not issue. */
|
|
45
|
+
declare class AuthenticationError extends AlexeinError {
|
|
46
|
+
}
|
|
47
|
+
/** 403: the key reads, and the call writes. */
|
|
48
|
+
declare class PermissionDeniedError extends AlexeinError {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 404: nothing was ever added for this app user, or memory holds nothing by the ref or id given.
|
|
52
|
+
* Search answers an empty result instead.
|
|
53
|
+
*/
|
|
54
|
+
declare class NotFoundError extends AlexeinError {
|
|
55
|
+
}
|
|
56
|
+
/** 400, 413, 422 and any other 4xx: the request itself is wrong. Retrying will not help. */
|
|
57
|
+
declare class InvalidRequestError extends AlexeinError {
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 429, after retries: too many requests in flight, or reads too fast. Retried for you, after
|
|
61
|
+
* `Retry-After` seconds (when at most 60) or with backoff.
|
|
62
|
+
*/
|
|
63
|
+
declare class RateLimitError extends AlexeinError {
|
|
64
|
+
}
|
|
65
|
+
/** 5xx, after retries (503 is retried; the rest are not): the service is busy or failing. */
|
|
66
|
+
declare class ServiceUnavailableError extends AlexeinError {
|
|
67
|
+
}
|
|
68
|
+
/** The service could not be reached, after retries. */
|
|
69
|
+
declare class APIConnectionError extends AlexeinError {
|
|
70
|
+
get outage(): boolean;
|
|
71
|
+
}
|
|
72
|
+
/** The service did not answer in time, after retries. */
|
|
73
|
+
declare class APITimeoutError extends APIConnectionError {
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { APIConnectionError, APITimeoutError, AlexeinError, AuthenticationError, type FieldError, InvalidRequestError, NotFoundError, PermissionDeniedError, RateLimitError, ServiceUnavailableError, VERSION };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export { A as AddOptions, a as AddResult, b as AddedItem, c as Adding, d as AppUser, e as Author, C as Correction, D as DEFAULT_BASE_URL, f as DEFAULT_RETRIES, g as DEFAULT_TIMEOUT_MS, h as Deleted, E as Erased, i as Excerpt, j as ExportPage, k as ExportRecord, F as Fact, l as FactsPage, m as Filters, n as FollowUp, o as ForgetOptions, p as Forgotten, G as GrepOptions, H as History, I as Item, q as ItemDefaults, r as ItemStatus, s as ItemsOptions, t as ItemsPage, J as Json, K as Known, L as LatestOptions, M as Me, u as Memories, v as Memory, w as MemoryEntry, x as MemoryOptions, O as OpenItem, y as OpenItems, z as OpenItemsOptions, B as Opened, N as Origin, P as PageOptions, S as SearchOptions, Q as SearchResult, R as Source, T as Sources, U as Statuses, V as StoredItem, W as Summary, X as User, Y as UsersPage, Z as Value, _ as VersionEntry, $ as Versions } from './client-YKZ4fkK-.js';
|
|
2
|
+
|
|
3
|
+
declare const VERSION = "0.3.0";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What can go wrong, one class per thing a caller would handle differently: the same classes as
|
|
7
|
+
* the Python client's, so what is true of an error there is true here.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** One field a 422 named, and what it takes. */
|
|
11
|
+
interface FieldError {
|
|
12
|
+
/** Where in the body: `query`, `items[0].text`; empty for the body itself. */
|
|
13
|
+
field: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
interface ErrorFields {
|
|
17
|
+
status?: number | null;
|
|
18
|
+
detail?: string;
|
|
19
|
+
errors?: FieldError[];
|
|
20
|
+
requestId?: string | null;
|
|
21
|
+
cause?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** Every error this client throws. */
|
|
24
|
+
declare class AlexeinError extends Error {
|
|
25
|
+
/** The HTTP status, or null when no response came back. */
|
|
26
|
+
readonly status: number | null;
|
|
27
|
+
/** The API's own explanation; for a transport failure, what went wrong. */
|
|
28
|
+
readonly detail: string;
|
|
29
|
+
/** On a 422: each field the body got wrong. Empty otherwise. */
|
|
30
|
+
readonly errors: FieldError[];
|
|
31
|
+
/**
|
|
32
|
+
* The request's id: the `X-Request-Id` this client sent, which the API logs and answers with.
|
|
33
|
+
* Quote it when you ask for help, or find the request in the console's request logs.
|
|
34
|
+
*/
|
|
35
|
+
readonly requestId: string | null;
|
|
36
|
+
constructor(message: string, fields?: ErrorFields);
|
|
37
|
+
/**
|
|
38
|
+
* Whether this means memory is unavailable - unreachable, too slow, too busy or failing - rather
|
|
39
|
+
* than that the request or the key is wrong. A `failOpen` client rides out an outage; a mistake
|
|
40
|
+
* still throws.
|
|
41
|
+
*/
|
|
42
|
+
get outage(): boolean;
|
|
43
|
+
}
|
|
44
|
+
/** 401: no key, or one the service did not issue. */
|
|
45
|
+
declare class AuthenticationError extends AlexeinError {
|
|
46
|
+
}
|
|
47
|
+
/** 403: the key reads, and the call writes. */
|
|
48
|
+
declare class PermissionDeniedError extends AlexeinError {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 404: nothing was ever added for this app user, or memory holds nothing by the ref or id given.
|
|
52
|
+
* Search answers an empty result instead.
|
|
53
|
+
*/
|
|
54
|
+
declare class NotFoundError extends AlexeinError {
|
|
55
|
+
}
|
|
56
|
+
/** 400, 413, 422 and any other 4xx: the request itself is wrong. Retrying will not help. */
|
|
57
|
+
declare class InvalidRequestError extends AlexeinError {
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 429, after retries: too many requests in flight, or reads too fast. Retried for you, after
|
|
61
|
+
* `Retry-After` seconds (when at most 60) or with backoff.
|
|
62
|
+
*/
|
|
63
|
+
declare class RateLimitError extends AlexeinError {
|
|
64
|
+
}
|
|
65
|
+
/** 5xx, after retries (503 is retried; the rest are not): the service is busy or failing. */
|
|
66
|
+
declare class ServiceUnavailableError extends AlexeinError {
|
|
67
|
+
}
|
|
68
|
+
/** The service could not be reached, after retries. */
|
|
69
|
+
declare class APIConnectionError extends AlexeinError {
|
|
70
|
+
get outage(): boolean;
|
|
71
|
+
}
|
|
72
|
+
/** The service did not answer in time, after retries. */
|
|
73
|
+
declare class APITimeoutError extends APIConnectionError {
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { APIConnectionError, APITimeoutError, AlexeinError, AuthenticationError, type FieldError, InvalidRequestError, NotFoundError, PermissionDeniedError, RateLimitError, ServiceUnavailableError, VERSION };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
APIConnectionError,
|
|
3
|
+
APITimeoutError,
|
|
4
|
+
AlexeinError,
|
|
5
|
+
AuthenticationError,
|
|
6
|
+
DEFAULT_BASE_URL,
|
|
7
|
+
DEFAULT_RETRIES,
|
|
8
|
+
DEFAULT_TIMEOUT_MS,
|
|
9
|
+
InvalidRequestError,
|
|
10
|
+
Memory,
|
|
11
|
+
NotFoundError,
|
|
12
|
+
PermissionDeniedError,
|
|
13
|
+
RateLimitError,
|
|
14
|
+
SearchResult,
|
|
15
|
+
ServiceUnavailableError,
|
|
16
|
+
User,
|
|
17
|
+
VERSION
|
|
18
|
+
} from "./chunk-UNVZ22EN.js";
|
|
19
|
+
export {
|
|
20
|
+
APIConnectionError,
|
|
21
|
+
APITimeoutError,
|
|
22
|
+
AlexeinError,
|
|
23
|
+
AuthenticationError,
|
|
24
|
+
DEFAULT_BASE_URL,
|
|
25
|
+
DEFAULT_RETRIES,
|
|
26
|
+
DEFAULT_TIMEOUT_MS,
|
|
27
|
+
InvalidRequestError,
|
|
28
|
+
Memory,
|
|
29
|
+
NotFoundError,
|
|
30
|
+
PermissionDeniedError,
|
|
31
|
+
RateLimitError,
|
|
32
|
+
SearchResult,
|
|
33
|
+
ServiceUnavailableError,
|
|
34
|
+
User,
|
|
35
|
+
VERSION
|
|
36
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkTLAHP2PBcjs = require('./chunk-TLAHP2PB.cjs');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunk7KPDU3YVcjs = require('./chunk-7KPDU3YV.cjs');
|
|
19
|
+
|
|
20
|
+
// src/langgraph/index.ts
|
|
21
|
+
var _messages = require('@langchain/core/messages');
|
|
22
|
+
var _tools = require('@langchain/core/tools');
|
|
23
|
+
var _langgraph = require('@langchain/langgraph');
|
|
24
|
+
var _zod = require('zod');
|
|
25
|
+
var MemoryAnnotation = _langgraph.Annotation.Root({
|
|
26
|
+
..._langgraph.MessagesAnnotation.spec,
|
|
27
|
+
memory: _langgraph.Annotation.call(void 0, { reducer: (_, found) => found, default: () => "" })
|
|
28
|
+
});
|
|
29
|
+
var MemoryState = new (0, _langgraph.StateSchema)({
|
|
30
|
+
messages: _langgraph.MessagesValue,
|
|
31
|
+
memory: _zod.z.string().default("")
|
|
32
|
+
});
|
|
33
|
+
var MemoryContext = _zod.z.object({ user_id: _zod.z.string().optional() });
|
|
34
|
+
function userIdOf(config) {
|
|
35
|
+
const context = _optionalChain([config, 'optionalAccess', _2 => _2.context]);
|
|
36
|
+
const found = _nullishCoalesce(_optionalChain([context, 'optionalAccess', _3 => _3.user_id]), () => ( _optionalChain([config, 'optionalAccess', _4 => _4.configurable, 'optionalAccess', _5 => _5.user_id])));
|
|
37
|
+
if (found === void 0 || found === null || found === "") {
|
|
38
|
+
throw new Error(
|
|
39
|
+
'Alexein needs to know whose memory this is: run the graph with { context: { user_id: "..." } }, or { configurable: { user_id: "..." } }'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return String(found);
|
|
43
|
+
}
|
|
44
|
+
function threadOf(config) {
|
|
45
|
+
const thread = _optionalChain([config, 'optionalAccess', _6 => _6.configurable, 'optionalAccess', _7 => _7.thread_id]);
|
|
46
|
+
return thread === void 0 || thread === null ? void 0 : String(thread);
|
|
47
|
+
}
|
|
48
|
+
function lastHuman(messages) {
|
|
49
|
+
return messages.findLast((m) => _messages.HumanMessage.isInstance(m));
|
|
50
|
+
}
|
|
51
|
+
function lastReply(messages) {
|
|
52
|
+
return messages.findLast((m) => _messages.AIMessage.isInstance(m) && !_optionalChain([m, 'access', _8 => _8.tool_calls, 'optionalAccess', _9 => _9.length]));
|
|
53
|
+
}
|
|
54
|
+
var AlexeinMemory = (_class = class {
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
#client;
|
|
59
|
+
/** `client` defaults to one made on first use: fail-open unless strict, a 10 s timeout. */
|
|
60
|
+
constructor(client, options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
61
|
+
const given = _chunkTLAHP2PBcjs.isClient.call(void 0, client) ? client : void 0;
|
|
62
|
+
const settings = _chunkTLAHP2PBcjs.isClient.call(void 0, client) ? options : { ...client, ...options };
|
|
63
|
+
this.fast = _nullishCoalesce(settings.fast, () => ( false));
|
|
64
|
+
this.maxChars = _nullishCoalesce(settings.maxChars, () => ( 4e3));
|
|
65
|
+
this.strict = _nullishCoalesce(settings.strict, () => ( false));
|
|
66
|
+
this.#client = new (0, _chunkTLAHP2PBcjs.LazyClient)(given, "langgraph", this.strict, settings.timeout);
|
|
67
|
+
}
|
|
68
|
+
get client() {
|
|
69
|
+
return this.#client.client;
|
|
70
|
+
}
|
|
71
|
+
user(config) {
|
|
72
|
+
return this.client.user(userIdOf(config));
|
|
73
|
+
}
|
|
74
|
+
/** A node: what memory holds for the latest human message, into `state.memory`. */
|
|
75
|
+
__init() {this.recall = exports.recall = async (state, config) => {
|
|
76
|
+
const asked = _optionalChain([lastHuman, 'call', _16 => _16(state.messages), 'optionalAccess', _17 => _17.text, 'access', _18 => _18.trim, 'call', _19 => _19()]);
|
|
77
|
+
const user = this.user(config);
|
|
78
|
+
if (!asked) return { memory: "" };
|
|
79
|
+
const found = await _chunkTLAHP2PBcjs.searchFor.call(void 0, user, asked, this.fast);
|
|
80
|
+
return { memory: _nullishCoalesce(_optionalChain([found, 'optionalAccess', _20 => _20.context, 'call', _21 => _21(this.maxChars)]), () => ( "")) };
|
|
81
|
+
}}
|
|
82
|
+
/**
|
|
83
|
+
* A node: save the turn - the latest human message and the last reply that is not a tool call -
|
|
84
|
+
* in the thread's session. Each message keeps its LangGraph id as its item id (else a stable
|
|
85
|
+
* hash), so running a turn again edits what was saved rather than adding a copy. Tool calls and
|
|
86
|
+
* tool results are not saved. Needs a key that writes.
|
|
87
|
+
*/
|
|
88
|
+
__init2() {this.remember = exports.remember = async (state, config) => {
|
|
89
|
+
const user = this.user(config);
|
|
90
|
+
const thread = threadOf(config);
|
|
91
|
+
const said = [
|
|
92
|
+
await item(lastHuman(state.messages), "user", thread),
|
|
93
|
+
await item(lastReply(state.messages), "assistant", thread)
|
|
94
|
+
].filter((i) => i !== void 0);
|
|
95
|
+
if (said.length) await user.add(said, { session: thread });
|
|
96
|
+
return {};
|
|
97
|
+
}}
|
|
98
|
+
/** What `recall` found, as a block for your system prompt; empty when it found nothing. */
|
|
99
|
+
__init3() {this.prompt = (state) => _chunkTLAHP2PBcjs.promptBlock.call(void 0, _nullishCoalesce(state.memory, () => ( "")))}
|
|
100
|
+
/**
|
|
101
|
+
* Tools the model calls when it decides to: `memory_search` and `memory_open`, and with
|
|
102
|
+
* `write`, `memory_add`. The user comes from the run, which a model never sees.
|
|
103
|
+
*/
|
|
104
|
+
tools({ write = false } = {}) {
|
|
105
|
+
const read = [this.searchTool(), this.openTool()];
|
|
106
|
+
return write ? [...read, this.addTool()] : read;
|
|
107
|
+
}
|
|
108
|
+
searchTool() {
|
|
109
|
+
return _tools.tool.call(void 0,
|
|
110
|
+
async ({ query }, config) => {
|
|
111
|
+
const found = await _chunkTLAHP2PBcjs.searchFor.call(void 0, this.user(config), query, this.fast);
|
|
112
|
+
return _chunkTLAHP2PBcjs.searchAnswer.call(void 0, found, this.maxChars);
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "memory_search",
|
|
116
|
+
description: "Search what you remember about this user: what they said, did and decided in earlier conversations. Ask in plain language. Ends with the refs of what it found, to read whole with memory_open.",
|
|
117
|
+
schema: _zod.z.object({ query: _zod.z.string().describe("What to look for") })
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
openTool() {
|
|
122
|
+
return _tools.tool.call(void 0,
|
|
123
|
+
async ({ ref }, config) => {
|
|
124
|
+
const user = this.user(config);
|
|
125
|
+
try {
|
|
126
|
+
return _chunkTLAHP2PBcjs.openAnswer.call(void 0, await user.open(ref));
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error instanceof _chunk7KPDU3YVcjs.NotFoundError) return _chunkTLAHP2PBcjs.notFoundAnswer.call(void 0, error);
|
|
129
|
+
return _chunkTLAHP2PBcjs.outageAnswer.call(void 0, error, this.strict);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "memory_open",
|
|
134
|
+
description: "Read one remembered memory whole, by a ref memory_search gave.",
|
|
135
|
+
schema: _zod.z.object({ ref: _zod.z.string().describe("A ref memory_search gave") })
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
addTool() {
|
|
140
|
+
return _tools.tool.call(void 0,
|
|
141
|
+
async ({ text }, config) => {
|
|
142
|
+
const saved = await this.user(config).add(text, {
|
|
143
|
+
kind: "note",
|
|
144
|
+
session: threadOf(config)
|
|
145
|
+
});
|
|
146
|
+
return saved.failed ? _chunkTLAHP2PBcjs.UNAVAILABLE : _chunkTLAHP2PBcjs.SAVED;
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "memory_add",
|
|
150
|
+
description: "Remember something about this user for later conversations: a preference, a fact about them, a decision. Write it as one plain sentence. Never save passwords, keys or secrets.",
|
|
151
|
+
schema: _zod.z.object({ text: _zod.z.string().describe("One plain sentence") })
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}, _class);
|
|
156
|
+
async function item(message, role, thread) {
|
|
157
|
+
const text = _optionalChain([message, 'optionalAccess', _22 => _22.text]);
|
|
158
|
+
if (!_optionalChain([text, 'optionalAccess', _23 => _23.trim, 'call', _24 => _24()])) return void 0;
|
|
159
|
+
const id = await _asyncNullishCoalesce(await _asyncOptionalChain([message, 'optionalAccess', async _25 => _25.id]), async () => ( await _chunkTLAHP2PBcjs.stableId.call(void 0, thread, role, text)));
|
|
160
|
+
return { id, role, text };
|
|
161
|
+
}
|
|
162
|
+
var fallback;
|
|
163
|
+
function defaultMemory() {
|
|
164
|
+
fallback ??= new AlexeinMemory();
|
|
165
|
+
return fallback;
|
|
166
|
+
}
|
|
167
|
+
var recall = (state, config) => defaultMemory().recall(state, config);
|
|
168
|
+
var remember = (state, config) => defaultMemory().remember(state, config);
|
|
169
|
+
var memoryPrompt = (state) => defaultMemory().prompt(state);
|
|
170
|
+
var memoryTools = (options = {}) => defaultMemory().tools(options);
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
exports.AlexeinMemory = AlexeinMemory; exports.MemoryAnnotation = MemoryAnnotation; exports.MemoryContext = MemoryContext; exports.MemoryState = MemoryState; exports.NOTHING_FOUND = _chunkTLAHP2PBcjs.NOTHING_FOUND; exports.NOTHING_YET = _chunkTLAHP2PBcjs.NOTHING_YET; exports.UNAVAILABLE = _chunkTLAHP2PBcjs.UNAVAILABLE; exports.defaultMemory = defaultMemory; exports.memoryPrompt = memoryPrompt; exports.memoryTools = memoryTools; exports.recall = recall; exports.remember = remember; exports.userIdOf = userIdOf;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as _langchain_core_messages from '@langchain/core/messages';
|
|
2
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
4
|
+
import { StateSchema } from '@langchain/langgraph';
|
|
5
|
+
import { StructuredToolInterface } from '@langchain/core/tools';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { v as Memory } from './client-YKZ4fkK-.cjs';
|
|
8
|
+
import { I as IntegrationOptions } from './shared-Btg8LbKC.cjs';
|
|
9
|
+
export { N as NOTHING_FOUND, a as NOTHING_YET, U as UNAVAILABLE } from './shared-Btg8LbKC.cjs';
|
|
10
|
+
|
|
11
|
+
/** A graph's state with room for what `recall` found: `messages` and `memory`. */
|
|
12
|
+
declare const MemoryAnnotation: _langchain_langgraph.AnnotationRoot<{
|
|
13
|
+
memory: _langchain_langgraph.BaseChannel<string, string | _langchain_langgraph.OverwriteValue<string>, unknown>;
|
|
14
|
+
messages: _langchain_langgraph.BaseChannel<BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[], _langchain_langgraph.OverwriteValue<BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[]> | _langchain_langgraph.Messages, unknown>;
|
|
15
|
+
}>;
|
|
16
|
+
/** The same state as a `StateSchema`, for graphs written that way. */
|
|
17
|
+
declare const MemoryState: StateSchema<{
|
|
18
|
+
messages: _langchain_langgraph.ReducedValue<BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[], _langchain_langgraph.Messages>;
|
|
19
|
+
memory: z.ZodDefault<z.ZodString>;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Whose memory a run reads, as a context schema. Optional, so that a run without it reaches the
|
|
23
|
+
* check that says how to give one instead of failing the schema's.
|
|
24
|
+
*/
|
|
25
|
+
declare const MemoryContext: z.ZodObject<{
|
|
26
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
/** What a node or tool is handed about its run: its context and its thread. */
|
|
29
|
+
interface RunConfig {
|
|
30
|
+
context?: unknown;
|
|
31
|
+
configurable?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** A state with messages, and `memory` once `recall` has run. */
|
|
34
|
+
interface MemoryStateValue {
|
|
35
|
+
messages: BaseMessage[];
|
|
36
|
+
memory?: string;
|
|
37
|
+
}
|
|
38
|
+
/** The app user this run is for: `context.user_id`, else `configurable.user_id`. */
|
|
39
|
+
declare function userIdOf(config: RunConfig | undefined): string;
|
|
40
|
+
/** Memory for a LangGraph.js graph: nodes, a prompt block and tools, over one client. */
|
|
41
|
+
declare class AlexeinMemory {
|
|
42
|
+
#private;
|
|
43
|
+
readonly fast: boolean;
|
|
44
|
+
readonly maxChars: number;
|
|
45
|
+
readonly strict: boolean;
|
|
46
|
+
/** `client` defaults to one made on first use: fail-open unless strict, a 10 s timeout. */
|
|
47
|
+
constructor(client?: Memory | IntegrationOptions, options?: IntegrationOptions);
|
|
48
|
+
get client(): Memory;
|
|
49
|
+
private user;
|
|
50
|
+
/** A node: what memory holds for the latest human message, into `state.memory`. */
|
|
51
|
+
readonly recall: (state: MemoryStateValue, config?: RunConfig) => Promise<{
|
|
52
|
+
memory: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* A node: save the turn - the latest human message and the last reply that is not a tool call -
|
|
56
|
+
* in the thread's session. Each message keeps its LangGraph id as its item id (else a stable
|
|
57
|
+
* hash), so running a turn again edits what was saved rather than adding a copy. Tool calls and
|
|
58
|
+
* tool results are not saved. Needs a key that writes.
|
|
59
|
+
*/
|
|
60
|
+
readonly remember: (state: MemoryStateValue, config?: RunConfig) => Promise<Record<string, never>>;
|
|
61
|
+
/** What `recall` found, as a block for your system prompt; empty when it found nothing. */
|
|
62
|
+
readonly prompt: (state: {
|
|
63
|
+
memory?: string;
|
|
64
|
+
}) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Tools the model calls when it decides to: `memory_search` and `memory_open`, and with
|
|
67
|
+
* `write`, `memory_add`. The user comes from the run, which a model never sees.
|
|
68
|
+
*/
|
|
69
|
+
tools({ write }?: {
|
|
70
|
+
write?: boolean;
|
|
71
|
+
}): StructuredToolInterface[];
|
|
72
|
+
private searchTool;
|
|
73
|
+
private openTool;
|
|
74
|
+
private addTool;
|
|
75
|
+
}
|
|
76
|
+
/** The `AlexeinMemory` the module-level functions use: made on first use, from the environment. */
|
|
77
|
+
declare function defaultMemory(): AlexeinMemory;
|
|
78
|
+
/** `recall` of the default `AlexeinMemory`. */
|
|
79
|
+
declare const recall: (state: MemoryStateValue, config?: RunConfig) => Promise<{
|
|
80
|
+
memory: string;
|
|
81
|
+
}>;
|
|
82
|
+
/** `remember` of the default `AlexeinMemory`. */
|
|
83
|
+
declare const remember: (state: MemoryStateValue, config?: RunConfig) => Promise<Record<string, never>>;
|
|
84
|
+
/** `prompt` of the default `AlexeinMemory`. */
|
|
85
|
+
declare const memoryPrompt: (state: {
|
|
86
|
+
memory?: string;
|
|
87
|
+
}) => string;
|
|
88
|
+
/** `tools` of the default `AlexeinMemory`. */
|
|
89
|
+
declare const memoryTools: (options?: {
|
|
90
|
+
write?: boolean;
|
|
91
|
+
}) => StructuredToolInterface[];
|
|
92
|
+
|
|
93
|
+
export { AlexeinMemory, IntegrationOptions as AlexeinMemoryOptions, MemoryAnnotation, MemoryContext, MemoryState, type MemoryStateValue, type RunConfig, defaultMemory, memoryPrompt, memoryTools, recall, remember, userIdOf };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as _langchain_core_messages from '@langchain/core/messages';
|
|
2
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
4
|
+
import { StateSchema } from '@langchain/langgraph';
|
|
5
|
+
import { StructuredToolInterface } from '@langchain/core/tools';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { v as Memory } from './client-YKZ4fkK-.js';
|
|
8
|
+
import { I as IntegrationOptions } from './shared-Btg8LbKC.js';
|
|
9
|
+
export { N as NOTHING_FOUND, a as NOTHING_YET, U as UNAVAILABLE } from './shared-Btg8LbKC.js';
|
|
10
|
+
|
|
11
|
+
/** A graph's state with room for what `recall` found: `messages` and `memory`. */
|
|
12
|
+
declare const MemoryAnnotation: _langchain_langgraph.AnnotationRoot<{
|
|
13
|
+
memory: _langchain_langgraph.BaseChannel<string, string | _langchain_langgraph.OverwriteValue<string>, unknown>;
|
|
14
|
+
messages: _langchain_langgraph.BaseChannel<BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[], _langchain_langgraph.OverwriteValue<BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[]> | _langchain_langgraph.Messages, unknown>;
|
|
15
|
+
}>;
|
|
16
|
+
/** The same state as a `StateSchema`, for graphs written that way. */
|
|
17
|
+
declare const MemoryState: StateSchema<{
|
|
18
|
+
messages: _langchain_langgraph.ReducedValue<BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[], _langchain_langgraph.Messages>;
|
|
19
|
+
memory: z.ZodDefault<z.ZodString>;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Whose memory a run reads, as a context schema. Optional, so that a run without it reaches the
|
|
23
|
+
* check that says how to give one instead of failing the schema's.
|
|
24
|
+
*/
|
|
25
|
+
declare const MemoryContext: z.ZodObject<{
|
|
26
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
/** What a node or tool is handed about its run: its context and its thread. */
|
|
29
|
+
interface RunConfig {
|
|
30
|
+
context?: unknown;
|
|
31
|
+
configurable?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** A state with messages, and `memory` once `recall` has run. */
|
|
34
|
+
interface MemoryStateValue {
|
|
35
|
+
messages: BaseMessage[];
|
|
36
|
+
memory?: string;
|
|
37
|
+
}
|
|
38
|
+
/** The app user this run is for: `context.user_id`, else `configurable.user_id`. */
|
|
39
|
+
declare function userIdOf(config: RunConfig | undefined): string;
|
|
40
|
+
/** Memory for a LangGraph.js graph: nodes, a prompt block and tools, over one client. */
|
|
41
|
+
declare class AlexeinMemory {
|
|
42
|
+
#private;
|
|
43
|
+
readonly fast: boolean;
|
|
44
|
+
readonly maxChars: number;
|
|
45
|
+
readonly strict: boolean;
|
|
46
|
+
/** `client` defaults to one made on first use: fail-open unless strict, a 10 s timeout. */
|
|
47
|
+
constructor(client?: Memory | IntegrationOptions, options?: IntegrationOptions);
|
|
48
|
+
get client(): Memory;
|
|
49
|
+
private user;
|
|
50
|
+
/** A node: what memory holds for the latest human message, into `state.memory`. */
|
|
51
|
+
readonly recall: (state: MemoryStateValue, config?: RunConfig) => Promise<{
|
|
52
|
+
memory: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* A node: save the turn - the latest human message and the last reply that is not a tool call -
|
|
56
|
+
* in the thread's session. Each message keeps its LangGraph id as its item id (else a stable
|
|
57
|
+
* hash), so running a turn again edits what was saved rather than adding a copy. Tool calls and
|
|
58
|
+
* tool results are not saved. Needs a key that writes.
|
|
59
|
+
*/
|
|
60
|
+
readonly remember: (state: MemoryStateValue, config?: RunConfig) => Promise<Record<string, never>>;
|
|
61
|
+
/** What `recall` found, as a block for your system prompt; empty when it found nothing. */
|
|
62
|
+
readonly prompt: (state: {
|
|
63
|
+
memory?: string;
|
|
64
|
+
}) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Tools the model calls when it decides to: `memory_search` and `memory_open`, and with
|
|
67
|
+
* `write`, `memory_add`. The user comes from the run, which a model never sees.
|
|
68
|
+
*/
|
|
69
|
+
tools({ write }?: {
|
|
70
|
+
write?: boolean;
|
|
71
|
+
}): StructuredToolInterface[];
|
|
72
|
+
private searchTool;
|
|
73
|
+
private openTool;
|
|
74
|
+
private addTool;
|
|
75
|
+
}
|
|
76
|
+
/** The `AlexeinMemory` the module-level functions use: made on first use, from the environment. */
|
|
77
|
+
declare function defaultMemory(): AlexeinMemory;
|
|
78
|
+
/** `recall` of the default `AlexeinMemory`. */
|
|
79
|
+
declare const recall: (state: MemoryStateValue, config?: RunConfig) => Promise<{
|
|
80
|
+
memory: string;
|
|
81
|
+
}>;
|
|
82
|
+
/** `remember` of the default `AlexeinMemory`. */
|
|
83
|
+
declare const remember: (state: MemoryStateValue, config?: RunConfig) => Promise<Record<string, never>>;
|
|
84
|
+
/** `prompt` of the default `AlexeinMemory`. */
|
|
85
|
+
declare const memoryPrompt: (state: {
|
|
86
|
+
memory?: string;
|
|
87
|
+
}) => string;
|
|
88
|
+
/** `tools` of the default `AlexeinMemory`. */
|
|
89
|
+
declare const memoryTools: (options?: {
|
|
90
|
+
write?: boolean;
|
|
91
|
+
}) => StructuredToolInterface[];
|
|
92
|
+
|
|
93
|
+
export { AlexeinMemory, IntegrationOptions as AlexeinMemoryOptions, MemoryAnnotation, MemoryContext, MemoryState, type MemoryStateValue, type RunConfig, defaultMemory, memoryPrompt, memoryTools, recall, remember, userIdOf };
|