@alexein/sdk 0.0.0-stage → 0.3.1
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 +41 -0
- package/LICENSE +21 -0
- package/README.md +238 -2
- package/dist/chunk-3LJEU4WL.js +101 -0
- package/dist/chunk-BIGISYZR.cjs +920 -0
- package/dist/chunk-DADXKQLZ.js +920 -0
- package/dist/chunk-PSATR3NL.cjs +101 -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
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return 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; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkBIGISYZRcjs = require('./chunk-BIGISYZR.cjs');
|
|
6
|
+
|
|
7
|
+
// src/integrations/shared.ts
|
|
8
|
+
var UNAVAILABLE = "Memory is unavailable right now; carry on without it.";
|
|
9
|
+
var NOTHING_FOUND = "Nothing remembered about that.";
|
|
10
|
+
var NOTHING_YET = "Nothing has been remembered for this user yet.";
|
|
11
|
+
var SAVED = "Saved.";
|
|
12
|
+
var HEADING = "What you remember about this user from earlier conversations. Use it where it helps; the conversation itself takes precedence where they differ.";
|
|
13
|
+
var MAX_QUERY = 2e3;
|
|
14
|
+
var TIMEOUT = 1e4;
|
|
15
|
+
var LazyClient = class {
|
|
16
|
+
constructor(given, integration, strict, timeout = TIMEOUT) {
|
|
17
|
+
this.integration = integration;
|
|
18
|
+
this.strict = strict;
|
|
19
|
+
this.timeout = timeout;
|
|
20
|
+
this.#client = given;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
#client;
|
|
26
|
+
get client() {
|
|
27
|
+
this.#client ??= new (0, _chunkBIGISYZRcjs.Memory)({
|
|
28
|
+
failOpen: !this.strict,
|
|
29
|
+
integration: this.integration,
|
|
30
|
+
timeout: this.timeout
|
|
31
|
+
});
|
|
32
|
+
return this.#client;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
function isClient(given) {
|
|
36
|
+
return typeof _optionalChain([given, 'optionalAccess', _ => _.user]) === "function";
|
|
37
|
+
}
|
|
38
|
+
async function searchFor(user, query, fast) {
|
|
39
|
+
try {
|
|
40
|
+
return await user.search(query.slice(-MAX_QUERY), { fast });
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error instanceof _chunkBIGISYZRcjs.NotFoundError) return void 0;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function searchAnswer(found, maxChars) {
|
|
47
|
+
if (_optionalChain([found, 'optionalAccess', _2 => _2.failed])) return UNAVAILABLE;
|
|
48
|
+
const said = _nullishCoalesce(_optionalChain([found, 'optionalAccess', _3 => _3.context, 'call', _4 => _4(maxChars)]), () => ( ""));
|
|
49
|
+
if (!found || !said) return NOTHING_FOUND;
|
|
50
|
+
const refs = [...new Set(found.refs)];
|
|
51
|
+
if (!refs.length) return said;
|
|
52
|
+
return `${said}
|
|
53
|
+
|
|
54
|
+
To read one whole, memory_open:
|
|
55
|
+
${refs.map((r) => `- ${r}`).join("\n")}`;
|
|
56
|
+
}
|
|
57
|
+
function described(memory) {
|
|
58
|
+
return memory.type === "excerpt" && memory.date ? `${memory.date.slice(0, 10)}: ${memory.text}` : memory.text;
|
|
59
|
+
}
|
|
60
|
+
function openAnswer(opened) {
|
|
61
|
+
if (!opened.sources.length) return described(opened.memory);
|
|
62
|
+
const from = opened.sources.map((s) => `- ${described(s)}`).join("\n");
|
|
63
|
+
return `${described(opened.memory)}
|
|
64
|
+
|
|
65
|
+
Learned from:
|
|
66
|
+
${from}`;
|
|
67
|
+
}
|
|
68
|
+
function notFoundAnswer(error) {
|
|
69
|
+
return /\bref\b/.test(error.detail) ? "Memory holds nothing by that ref." : NOTHING_YET;
|
|
70
|
+
}
|
|
71
|
+
function outageAnswer(error, strict) {
|
|
72
|
+
if (strict || !(error instanceof _chunkBIGISYZRcjs.AlexeinError) || !error.outage) throw error;
|
|
73
|
+
console.warn(`Alexein is unavailable: ${error.message}`);
|
|
74
|
+
return UNAVAILABLE;
|
|
75
|
+
}
|
|
76
|
+
function promptBlock(found) {
|
|
77
|
+
return found ? `${HEADING}
|
|
78
|
+
|
|
79
|
+
${found}` : "";
|
|
80
|
+
}
|
|
81
|
+
async function stableId(...parts) {
|
|
82
|
+
const bytes = new TextEncoder().encode(parts.map((p) => _nullishCoalesce(p, () => ( ""))).join("|"));
|
|
83
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
|
|
84
|
+
return Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 24);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
exports.UNAVAILABLE = UNAVAILABLE; exports.NOTHING_FOUND = NOTHING_FOUND; exports.NOTHING_YET = NOTHING_YET; exports.SAVED = SAVED; exports.LazyClient = LazyClient; exports.isClient = isClient; exports.searchFor = searchFor; exports.searchAnswer = searchAnswer; exports.openAnswer = openAnswer; exports.notFoundAnswer = notFoundAnswer; exports.outageAnswer = outageAnswer; exports.promptBlock = promptBlock; exports.stableId = stableId;
|