@supermemory/eve 0.1.0 → 0.1.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/dist/index.d.ts +1 -1
- package/dist/lib/capture-conversation.js +2 -1
- package/dist/lib/client.d.ts +2 -1
- package/dist/lib/client.js +13 -2
- package/dist/lib/dependencies.d.ts +1 -1
- package/dist/lib/documents.js +2 -1
- package/dist/lib/extract-source.js +2 -1
- package/dist/lib/forget-matching.js +2 -1
- package/dist/lib/forget-memory.d.ts +1 -1
- package/dist/lib/forget-memory.js +3 -2
- package/dist/lib/remember.js +3 -2
- package/dist/lib/search-context.js +2 -1
- package/dist/options.d.ts +3 -2
- package/dist/options.js +5 -1
- package/dist/provider.js +6 -5
- package/dist/tools/forget.d.ts +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { SupermemoryOptions } from "./options.js";
|
|
1
|
+
export type { SupermemoryApiKey, SupermemoryOptions } from "./options.js";
|
|
2
2
|
export { supermemory as default, supermemory } from "./provider.js";
|
|
@@ -37,7 +37,8 @@ export async function captureCompletedTurn(context, dependencies, capture) {
|
|
|
37
37
|
const entityContext = entityContextForTurn(turn, capture.entityContext);
|
|
38
38
|
const sourceId = `conv_${context.session.id}`;
|
|
39
39
|
try {
|
|
40
|
-
await
|
|
40
|
+
const client = await dependencies.getClient();
|
|
41
|
+
await addDocument(client, {
|
|
41
42
|
containerTag: dependencies.containerTags.context,
|
|
42
43
|
content,
|
|
43
44
|
customId: sourceId,
|
package/dist/lib/client.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import Supermemory from "supermemory";
|
|
2
|
-
|
|
2
|
+
import type { SupermemoryApiKey } from "../options.js";
|
|
3
|
+
export declare function createSupermemoryClientFactory(apiKey: SupermemoryApiKey): () => Promise<Supermemory>;
|
package/dist/lib/client.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import Supermemory from "supermemory";
|
|
2
|
-
export function
|
|
3
|
-
|
|
2
|
+
export function createSupermemoryClientFactory(apiKey) {
|
|
3
|
+
if (typeof apiKey === "string") {
|
|
4
|
+
const client = new Supermemory({ apiKey });
|
|
5
|
+
return async () => client;
|
|
6
|
+
}
|
|
7
|
+
const resolveApiKey = apiKey;
|
|
8
|
+
return async () => {
|
|
9
|
+
const resolvedApiKey = await resolveApiKey();
|
|
10
|
+
if (!resolvedApiKey) {
|
|
11
|
+
throw new Error("The Supermemory API key resolver returned an empty value.");
|
|
12
|
+
}
|
|
13
|
+
return new Supermemory({ apiKey: resolvedApiKey });
|
|
14
|
+
};
|
|
4
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type Supermemory from "supermemory";
|
|
2
2
|
import type { ContainerTags } from "./container-tags.js";
|
|
3
3
|
export interface SupermemoryDependencies {
|
|
4
|
-
readonly
|
|
4
|
+
readonly getClient: () => Promise<Supermemory>;
|
|
5
5
|
readonly containerTags: ContainerTags;
|
|
6
6
|
}
|
package/dist/lib/documents.js
CHANGED
|
@@ -31,7 +31,8 @@ export async function readStoredDocument(documentId, offset, container, ctx, dep
|
|
|
31
31
|
const containerTag = container === "agent_extraction"
|
|
32
32
|
? dependencies.containerTags.extraction
|
|
33
33
|
: dependencies.containerTags.context;
|
|
34
|
-
const
|
|
34
|
+
const client = await dependencies.getClient();
|
|
35
|
+
const document = await accessibleDocument(client, documentId, containerTag, ctx.abortSignal);
|
|
35
36
|
const details = {
|
|
36
37
|
id: document.id,
|
|
37
38
|
customId: document.customId,
|
|
@@ -31,7 +31,8 @@ async function sandboxAttachment(inputPath, ctx) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
export async function extractSource(input, ctx, dependencies) {
|
|
34
|
-
const
|
|
34
|
+
const client = await dependencies.getClient();
|
|
35
|
+
const { containerTags } = dependencies;
|
|
35
36
|
const metadata = extractionMetadata(input, ctx);
|
|
36
37
|
if (input.kind === "file") {
|
|
37
38
|
const { file, filepath } = await sandboxAttachment(input.value, ctx);
|
|
@@ -28,7 +28,8 @@ export async function forgetMatchingMemories(input, ctx, dependencies) {
|
|
|
28
28
|
if (!input.dryRun && !input.ids?.length) {
|
|
29
29
|
throw new Error("Finalizing requires the exact candidate IDs returned by a dry-run preview.");
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
const client = await dependencies.getClient();
|
|
32
|
+
return forgetMatchingResponseSchema.parse(await client.post("/v4/memories/forget-matching", {
|
|
32
33
|
body: {
|
|
33
34
|
...(query ? { query } : {}),
|
|
34
35
|
containerTag: dependencies.containerTags.context,
|
|
@@ -4,4 +4,4 @@ export type ForgetMemoryInput = {
|
|
|
4
4
|
memoryId: string;
|
|
5
5
|
reason?: string;
|
|
6
6
|
};
|
|
7
|
-
export declare function forgetMemory(input: ForgetMemoryInput, ctx: ToolContext, dependencies: SupermemoryDependencies):
|
|
7
|
+
export declare function forgetMemory(input: ForgetMemoryInput, ctx: ToolContext, dependencies: SupermemoryDependencies): Promise<import("supermemory/resources/memories.mjs").MemoryForgetResponse>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export function forgetMemory(input, ctx, dependencies) {
|
|
2
|
-
|
|
1
|
+
export async function forgetMemory(input, ctx, dependencies) {
|
|
2
|
+
const client = await dependencies.getClient();
|
|
3
|
+
return client.memories.forget({
|
|
3
4
|
containerTag: dependencies.containerTags.context,
|
|
4
5
|
id: input.memoryId,
|
|
5
6
|
...(input.reason ? { reason: input.reason } : {}),
|
package/dist/lib/remember.js
CHANGED
|
@@ -5,14 +5,15 @@ export async function rememberContext(input, ctx, dependencies) {
|
|
|
5
5
|
const conversationId = `conv_${ctx.session.id}`;
|
|
6
6
|
const requestedSourceDocumentId = input.sourceDocumentId?.trim();
|
|
7
7
|
let sourceDocumentId;
|
|
8
|
+
const client = await dependencies.getClient();
|
|
8
9
|
if (requestedSourceDocumentId) {
|
|
9
|
-
const source = await accessibleDocument(
|
|
10
|
+
const source = await accessibleDocument(client, requestedSourceDocumentId, dependencies.containerTags.extraction, ctx.abortSignal);
|
|
10
11
|
if (source.status !== "done") {
|
|
11
12
|
throw new Error("The source document is still processing. Read it again before remembering its contents.");
|
|
12
13
|
}
|
|
13
14
|
sourceDocumentId = source.id;
|
|
14
15
|
}
|
|
15
|
-
const result = await addDocument(
|
|
16
|
+
const result = await addDocument(client, {
|
|
16
17
|
containerTag: dependencies.containerTags.context,
|
|
17
18
|
content: input.memory,
|
|
18
19
|
customId: sourceId,
|
|
@@ -13,7 +13,8 @@ export async function searchStoredContext(input, options, dependencies) {
|
|
|
13
13
|
if (input.customId) {
|
|
14
14
|
filters.push({ key: "source_id", value: input.customId });
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
const client = await dependencies.getClient();
|
|
17
|
+
return client.search({
|
|
17
18
|
q: input.query,
|
|
18
19
|
containerTag: dependencies.containerTags.context,
|
|
19
20
|
searchMode: SEARCH_MODE_BY_SCOPE[input.scope],
|
package/dist/options.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export type SupermemoryApiKey = string | (() => string | Promise<string>);
|
|
1
2
|
export type SupermemoryMetadataValue = string | number | boolean | readonly string[];
|
|
2
3
|
export interface SupermemoryOptions {
|
|
3
|
-
readonly apiKey:
|
|
4
|
+
readonly apiKey: SupermemoryApiKey;
|
|
4
5
|
readonly containerTagPrefix?: string;
|
|
5
6
|
readonly autoSearch?: {
|
|
6
7
|
readonly enabled?: boolean;
|
|
@@ -17,7 +18,7 @@ export interface SupermemoryOptions {
|
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
export interface SupermemoryConfig {
|
|
20
|
-
readonly apiKey:
|
|
21
|
+
readonly apiKey: SupermemoryApiKey;
|
|
21
22
|
readonly containerTagPrefix: string;
|
|
22
23
|
readonly autoSearch: {
|
|
23
24
|
readonly enabled: boolean;
|
package/dist/options.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
const metadataValue = z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]);
|
|
3
|
+
const apiKey = z.union([
|
|
4
|
+
z.string().min(1),
|
|
5
|
+
z.custom((value) => typeof value === "function"),
|
|
6
|
+
]);
|
|
3
7
|
function isTimeZone(value) {
|
|
4
8
|
try {
|
|
5
9
|
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
@@ -10,7 +14,7 @@ function isTimeZone(value) {
|
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
const optionsSchema = z.object({
|
|
13
|
-
apiKey
|
|
17
|
+
apiKey,
|
|
14
18
|
containerTagPrefix: z
|
|
15
19
|
.string()
|
|
16
20
|
.min(1)
|
package/dist/provider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineMemoryProvider, } from "eve/memory";
|
|
2
2
|
import { EMPTY_AUTO_SEARCH_CONTEXT, loadAutoSearchContext } from "./lib/auto-search.js";
|
|
3
3
|
import { captureCompletedTurn } from "./lib/capture-conversation.js";
|
|
4
|
-
import {
|
|
4
|
+
import { createSupermemoryClientFactory } from "./lib/client.js";
|
|
5
5
|
import { resolveContainerTags } from "./lib/container-tags.js";
|
|
6
6
|
import { loadProfileContext } from "./lib/profile-context.js";
|
|
7
7
|
import { resolveOptions } from "./options.js";
|
|
@@ -13,18 +13,19 @@ function errorMessage(error) {
|
|
|
13
13
|
}
|
|
14
14
|
export function supermemory(options) {
|
|
15
15
|
const config = resolveOptions(options);
|
|
16
|
-
const
|
|
16
|
+
const getClient = createSupermemoryClientFactory(config.apiKey);
|
|
17
17
|
const dependencies = (scopeKey) => ({
|
|
18
|
-
|
|
18
|
+
getClient,
|
|
19
19
|
containerTags: resolveContainerTags(scopeKey, config.containerTagPrefix),
|
|
20
20
|
});
|
|
21
21
|
const recall = async (context) => {
|
|
22
22
|
const messages = [];
|
|
23
23
|
try {
|
|
24
|
+
const memory = dependencies(context.memory.scope.key);
|
|
24
25
|
const content = await loadProfileContext({
|
|
25
26
|
abortSignal: context.abortSignal,
|
|
26
|
-
client,
|
|
27
|
-
containerTag:
|
|
27
|
+
client: await memory.getClient(),
|
|
28
|
+
containerTag: memory.containerTags.context,
|
|
28
29
|
timeZone: config.profileContext.timeZone,
|
|
29
30
|
});
|
|
30
31
|
messages.push({ content, id: PROFILE_CONTEXT_ID });
|
package/dist/tools/forget.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export declare function createForgetTool(dependencies: SupermemoryDependencies):
|
|
|
6
6
|
execute(input: {
|
|
7
7
|
memoryId: string;
|
|
8
8
|
reason?: string | undefined;
|
|
9
|
-
}, ctx: import("eve/tools").ToolContext):
|
|
9
|
+
}, ctx: import("eve/tools").ToolContext): Promise<import("supermemory/resources/memories.mjs").MemoryForgetResponse>;
|
|
10
10
|
};
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -240,7 +240,7 @@ export declare function createSupermemoryTools(dependencies: SupermemoryDependen
|
|
|
240
240
|
execute(input: {
|
|
241
241
|
memoryId: string;
|
|
242
242
|
reason?: string | undefined;
|
|
243
|
-
}, ctx: import("eve/tools").ToolContext):
|
|
243
|
+
}, ctx: import("eve/tools").ToolContext): Promise<import("supermemory/resources/memories.mjs").MemoryForgetResponse>;
|
|
244
244
|
};
|
|
245
245
|
forget_matching: import("eve/tools").ToolDefinition<{
|
|
246
246
|
query?: string | undefined;
|