MCPcopy Create free account
hub / github.com/astercloud/aster / main

Function main

client-sdks/client-js/examples/memory-usage.ts:7–208  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { MemoryResource } from "@aster/client-js";
6
7async function main() {
8 // 创建 Memory 资源
9 const memory = new MemoryResource({
10 baseUrl: "http://localhost:8080",
11 apiKey: process.env.ASTER_API_KEY,
12 });
13
14 console.log("=".repeat(60));
15 console.log("AsterClient 三层记忆系统演示");
16 console.log("=".repeat(60));
17
18 // ========================================================================
19 // 1. Working Memory 演示
20 // ========================================================================
21 console.log("\n📝 1. Working Memory(工作记忆)");
22 console.log("-".repeat(60));
23
24 // 设置 Thread 作用域的记忆(会话级别)
25 await memory.working.set(
26 "user_preference",
27 {
28 theme: "dark",
29 language: "zh-CN",
30 notifications: true,
31 },
32 {
33 scope: "thread",
34 ttl: 3600, // 1小时后过期
35 },
36 );
37 console.log("✅ 设置 Thread 作用域记忆: user_preference");
38
39 // 设置 Resource 作用域的记忆(全局)
40 await memory.working.set(
41 "app_config",
42 {
43 version: "1.0.0",
44 features: ["chat", "workflow", "memory"],
45 },
46 {
47 scope: "resource", // 全局作用域
48 ttl: 0, // 永不过期
49 },
50 );
51 console.log("✅ 设置 Resource 作用域记忆: app_config");
52
53 // 带 JSON Schema 验证的记忆
54 await memory.working.set(
55 "validated_data",
56 {
57 count: 42,
58 name: "test",
59 },
60 {
61 schema: {
62 type: "object",
63 properties: {
64 count: { type: "number" },

Callers 1

memory-usage.tsFile · 0.70

Calls 12

getProvenanceMethod · 0.95
getLineageMethod · 0.95
consolidateMethod · 0.95
getStatsMethod · 0.95
logMethod · 0.80
searchMethod · 0.80
setMethod · 0.45
getMethod · 0.45
listMethod · 0.45
deleteMethod · 0.45
deleteBatchMethod · 0.45

Tested by

no test coverage detected