@xache/langchain 0.6.0 → 0.7.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/dist/index.d.mts +114 -1
- package/dist/index.d.ts +114 -1
- package/dist/index.js +261 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +251 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +7 -0
- package/src/probe.ts +122 -0
package/dist/index.d.mts
CHANGED
|
@@ -682,4 +682,117 @@ declare class XacheGraphRetriever extends BaseRetriever {
|
|
|
682
682
|
_getRelevantDocuments(query: string, _runManager?: CallbackManagerForRetrieverRun): Promise<Document[]>;
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
-
|
|
685
|
+
/**
|
|
686
|
+
* Xache Memory Probe for LangChain.js
|
|
687
|
+
* Zero-knowledge semantic memory search using cognitive fingerprints
|
|
688
|
+
*/
|
|
689
|
+
|
|
690
|
+
interface ProbeToolConfig {
|
|
691
|
+
/** Wallet address for authentication */
|
|
692
|
+
walletAddress: string;
|
|
693
|
+
/** Private key for signing (optional if signer or walletProvider is provided) */
|
|
694
|
+
privateKey?: string;
|
|
695
|
+
/** External signer (alternative to privateKey) */
|
|
696
|
+
signer?: XacheSigner;
|
|
697
|
+
/** Wallet provider for lazy signer resolution */
|
|
698
|
+
walletProvider?: XacheWalletProvider;
|
|
699
|
+
/** Encryption key for use with external signers */
|
|
700
|
+
encryptionKey?: string;
|
|
701
|
+
/** API URL (defaults to https://api.xache.xyz) */
|
|
702
|
+
apiUrl?: string;
|
|
703
|
+
/** Chain: 'base' or 'solana' */
|
|
704
|
+
chain?: 'base' | 'solana';
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Create a tool for probing memory using cognitive fingerprints.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* import { createMemoryProbeTool } from '@xache/langchain';
|
|
712
|
+
*
|
|
713
|
+
* const probeTool = createMemoryProbeTool({
|
|
714
|
+
* walletAddress: '0x...',
|
|
715
|
+
* privateKey: '0x...',
|
|
716
|
+
* });
|
|
717
|
+
*
|
|
718
|
+
* const tools = [probeTool, ...];
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
declare function createMemoryProbeTool(config: ProbeToolConfig): DynamicStructuredTool;
|
|
722
|
+
/**
|
|
723
|
+
* Class-based memory probe tool (alternative API)
|
|
724
|
+
*/
|
|
725
|
+
declare class XacheMemoryProbeTool {
|
|
726
|
+
private tool;
|
|
727
|
+
constructor(config: ProbeToolConfig);
|
|
728
|
+
asTool(): DynamicStructuredTool;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Xache Ephemeral Context for LangChain.js
|
|
733
|
+
* Create, manage, and promote short-lived working memory sessions
|
|
734
|
+
*/
|
|
735
|
+
|
|
736
|
+
interface EphemeralToolConfig {
|
|
737
|
+
/** Wallet address for authentication */
|
|
738
|
+
walletAddress: string;
|
|
739
|
+
/** Private key for signing (optional if signer or walletProvider is provided) */
|
|
740
|
+
privateKey?: string;
|
|
741
|
+
/** External signer (alternative to privateKey) */
|
|
742
|
+
signer?: XacheSigner;
|
|
743
|
+
/** Wallet provider for lazy signer resolution */
|
|
744
|
+
walletProvider?: XacheWalletProvider;
|
|
745
|
+
/** Encryption key for use with external signers */
|
|
746
|
+
encryptionKey?: string;
|
|
747
|
+
/** API URL (defaults to https://api.xache.xyz) */
|
|
748
|
+
apiUrl?: string;
|
|
749
|
+
/** Chain: 'base' or 'solana' */
|
|
750
|
+
chain?: 'base' | 'solana';
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Create a tool for creating an ephemeral working memory session.
|
|
754
|
+
*/
|
|
755
|
+
declare function createEphemeralCreateSessionTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
756
|
+
/**
|
|
757
|
+
* Create a tool for writing data to an ephemeral slot.
|
|
758
|
+
*/
|
|
759
|
+
declare function createEphemeralWriteSlotTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
760
|
+
/**
|
|
761
|
+
* Create a tool for reading data from an ephemeral slot.
|
|
762
|
+
*/
|
|
763
|
+
declare function createEphemeralReadSlotTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
764
|
+
/**
|
|
765
|
+
* Create a tool for promoting an ephemeral session to persistent memory.
|
|
766
|
+
*/
|
|
767
|
+
declare function createEphemeralPromoteTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
768
|
+
/**
|
|
769
|
+
* Create a tool for getting ephemeral session status and details.
|
|
770
|
+
*/
|
|
771
|
+
declare function createEphemeralStatusTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
772
|
+
declare class XacheEphemeralCreateSessionTool {
|
|
773
|
+
private tool;
|
|
774
|
+
constructor(config: EphemeralToolConfig);
|
|
775
|
+
asTool(): DynamicStructuredTool;
|
|
776
|
+
}
|
|
777
|
+
declare class XacheEphemeralWriteSlotTool {
|
|
778
|
+
private tool;
|
|
779
|
+
constructor(config: EphemeralToolConfig);
|
|
780
|
+
asTool(): DynamicStructuredTool;
|
|
781
|
+
}
|
|
782
|
+
declare class XacheEphemeralReadSlotTool {
|
|
783
|
+
private tool;
|
|
784
|
+
constructor(config: EphemeralToolConfig);
|
|
785
|
+
asTool(): DynamicStructuredTool;
|
|
786
|
+
}
|
|
787
|
+
declare class XacheEphemeralPromoteTool {
|
|
788
|
+
private tool;
|
|
789
|
+
constructor(config: EphemeralToolConfig);
|
|
790
|
+
asTool(): DynamicStructuredTool;
|
|
791
|
+
}
|
|
792
|
+
declare class XacheEphemeralStatusTool {
|
|
793
|
+
private tool;
|
|
794
|
+
constructor(config: EphemeralToolConfig);
|
|
795
|
+
asTool(): DynamicStructuredTool;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
export { type CollectiveToolConfig, type EphemeralToolConfig, type ExtractedMemory, type ExtractionResult, type GraphToolConfig, type ProbeToolConfig, type ReputationResult, type ReputationToolConfig, XacheChatMessageHistory, type XacheChatMessageHistoryConfig, XacheCollectiveContributeTool, XacheCollectiveQueryTool, XacheConversationBufferMemory, XacheEphemeralCreateSessionTool, XacheEphemeralPromoteTool, XacheEphemeralReadSlotTool, XacheEphemeralStatusTool, XacheEphemeralWriteSlotTool, XacheExtractor, type XacheExtractorConfig, XacheGraphAskTool, XacheGraphEntityHistoryTool, XacheGraphExtractTool, XacheGraphLoadTool, XacheGraphMergeEntitiesTool, XacheGraphQueryTool, XacheGraphRetriever, type XacheGraphRetrieverConfig, XacheMemory, type XacheMemoryConfig, XacheMemoryProbeTool, XacheReputationChecker, XacheReputationTool, XacheRetriever, type XacheRetrieverConfig, createCollectiveContributeTool, createCollectiveQueryTool, createEphemeralCreateSessionTool, createEphemeralPromoteTool, createEphemeralReadSlotTool, createEphemeralStatusTool, createEphemeralWriteSlotTool, createGraphAddEntityTool, createGraphAddRelationshipTool, createGraphAskTool, createGraphEntityHistoryTool, createGraphExtractTool, createGraphLoadTool, createGraphMergeEntitiesTool, createGraphQueryTool, createMemoryProbeTool, createReputationTool };
|
package/dist/index.d.ts
CHANGED
|
@@ -682,4 +682,117 @@ declare class XacheGraphRetriever extends BaseRetriever {
|
|
|
682
682
|
_getRelevantDocuments(query: string, _runManager?: CallbackManagerForRetrieverRun): Promise<Document[]>;
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
-
|
|
685
|
+
/**
|
|
686
|
+
* Xache Memory Probe for LangChain.js
|
|
687
|
+
* Zero-knowledge semantic memory search using cognitive fingerprints
|
|
688
|
+
*/
|
|
689
|
+
|
|
690
|
+
interface ProbeToolConfig {
|
|
691
|
+
/** Wallet address for authentication */
|
|
692
|
+
walletAddress: string;
|
|
693
|
+
/** Private key for signing (optional if signer or walletProvider is provided) */
|
|
694
|
+
privateKey?: string;
|
|
695
|
+
/** External signer (alternative to privateKey) */
|
|
696
|
+
signer?: XacheSigner;
|
|
697
|
+
/** Wallet provider for lazy signer resolution */
|
|
698
|
+
walletProvider?: XacheWalletProvider;
|
|
699
|
+
/** Encryption key for use with external signers */
|
|
700
|
+
encryptionKey?: string;
|
|
701
|
+
/** API URL (defaults to https://api.xache.xyz) */
|
|
702
|
+
apiUrl?: string;
|
|
703
|
+
/** Chain: 'base' or 'solana' */
|
|
704
|
+
chain?: 'base' | 'solana';
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Create a tool for probing memory using cognitive fingerprints.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* import { createMemoryProbeTool } from '@xache/langchain';
|
|
712
|
+
*
|
|
713
|
+
* const probeTool = createMemoryProbeTool({
|
|
714
|
+
* walletAddress: '0x...',
|
|
715
|
+
* privateKey: '0x...',
|
|
716
|
+
* });
|
|
717
|
+
*
|
|
718
|
+
* const tools = [probeTool, ...];
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
declare function createMemoryProbeTool(config: ProbeToolConfig): DynamicStructuredTool;
|
|
722
|
+
/**
|
|
723
|
+
* Class-based memory probe tool (alternative API)
|
|
724
|
+
*/
|
|
725
|
+
declare class XacheMemoryProbeTool {
|
|
726
|
+
private tool;
|
|
727
|
+
constructor(config: ProbeToolConfig);
|
|
728
|
+
asTool(): DynamicStructuredTool;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Xache Ephemeral Context for LangChain.js
|
|
733
|
+
* Create, manage, and promote short-lived working memory sessions
|
|
734
|
+
*/
|
|
735
|
+
|
|
736
|
+
interface EphemeralToolConfig {
|
|
737
|
+
/** Wallet address for authentication */
|
|
738
|
+
walletAddress: string;
|
|
739
|
+
/** Private key for signing (optional if signer or walletProvider is provided) */
|
|
740
|
+
privateKey?: string;
|
|
741
|
+
/** External signer (alternative to privateKey) */
|
|
742
|
+
signer?: XacheSigner;
|
|
743
|
+
/** Wallet provider for lazy signer resolution */
|
|
744
|
+
walletProvider?: XacheWalletProvider;
|
|
745
|
+
/** Encryption key for use with external signers */
|
|
746
|
+
encryptionKey?: string;
|
|
747
|
+
/** API URL (defaults to https://api.xache.xyz) */
|
|
748
|
+
apiUrl?: string;
|
|
749
|
+
/** Chain: 'base' or 'solana' */
|
|
750
|
+
chain?: 'base' | 'solana';
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Create a tool for creating an ephemeral working memory session.
|
|
754
|
+
*/
|
|
755
|
+
declare function createEphemeralCreateSessionTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
756
|
+
/**
|
|
757
|
+
* Create a tool for writing data to an ephemeral slot.
|
|
758
|
+
*/
|
|
759
|
+
declare function createEphemeralWriteSlotTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
760
|
+
/**
|
|
761
|
+
* Create a tool for reading data from an ephemeral slot.
|
|
762
|
+
*/
|
|
763
|
+
declare function createEphemeralReadSlotTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
764
|
+
/**
|
|
765
|
+
* Create a tool for promoting an ephemeral session to persistent memory.
|
|
766
|
+
*/
|
|
767
|
+
declare function createEphemeralPromoteTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
768
|
+
/**
|
|
769
|
+
* Create a tool for getting ephemeral session status and details.
|
|
770
|
+
*/
|
|
771
|
+
declare function createEphemeralStatusTool(config: EphemeralToolConfig): DynamicStructuredTool;
|
|
772
|
+
declare class XacheEphemeralCreateSessionTool {
|
|
773
|
+
private tool;
|
|
774
|
+
constructor(config: EphemeralToolConfig);
|
|
775
|
+
asTool(): DynamicStructuredTool;
|
|
776
|
+
}
|
|
777
|
+
declare class XacheEphemeralWriteSlotTool {
|
|
778
|
+
private tool;
|
|
779
|
+
constructor(config: EphemeralToolConfig);
|
|
780
|
+
asTool(): DynamicStructuredTool;
|
|
781
|
+
}
|
|
782
|
+
declare class XacheEphemeralReadSlotTool {
|
|
783
|
+
private tool;
|
|
784
|
+
constructor(config: EphemeralToolConfig);
|
|
785
|
+
asTool(): DynamicStructuredTool;
|
|
786
|
+
}
|
|
787
|
+
declare class XacheEphemeralPromoteTool {
|
|
788
|
+
private tool;
|
|
789
|
+
constructor(config: EphemeralToolConfig);
|
|
790
|
+
asTool(): DynamicStructuredTool;
|
|
791
|
+
}
|
|
792
|
+
declare class XacheEphemeralStatusTool {
|
|
793
|
+
private tool;
|
|
794
|
+
constructor(config: EphemeralToolConfig);
|
|
795
|
+
asTool(): DynamicStructuredTool;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
export { type CollectiveToolConfig, type EphemeralToolConfig, type ExtractedMemory, type ExtractionResult, type GraphToolConfig, type ProbeToolConfig, type ReputationResult, type ReputationToolConfig, XacheChatMessageHistory, type XacheChatMessageHistoryConfig, XacheCollectiveContributeTool, XacheCollectiveQueryTool, XacheConversationBufferMemory, XacheEphemeralCreateSessionTool, XacheEphemeralPromoteTool, XacheEphemeralReadSlotTool, XacheEphemeralStatusTool, XacheEphemeralWriteSlotTool, XacheExtractor, type XacheExtractorConfig, XacheGraphAskTool, XacheGraphEntityHistoryTool, XacheGraphExtractTool, XacheGraphLoadTool, XacheGraphMergeEntitiesTool, XacheGraphQueryTool, XacheGraphRetriever, type XacheGraphRetrieverConfig, XacheMemory, type XacheMemoryConfig, XacheMemoryProbeTool, XacheReputationChecker, XacheReputationTool, XacheRetriever, type XacheRetrieverConfig, createCollectiveContributeTool, createCollectiveQueryTool, createEphemeralCreateSessionTool, createEphemeralPromoteTool, createEphemeralReadSlotTool, createEphemeralStatusTool, createEphemeralWriteSlotTool, createGraphAddEntityTool, createGraphAddRelationshipTool, createGraphAskTool, createGraphEntityHistoryTool, createGraphExtractTool, createGraphLoadTool, createGraphMergeEntitiesTool, createGraphQueryTool, createMemoryProbeTool, createReputationTool };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,11 @@ __export(index_exports, {
|
|
|
24
24
|
XacheCollectiveContributeTool: () => XacheCollectiveContributeTool,
|
|
25
25
|
XacheCollectiveQueryTool: () => XacheCollectiveQueryTool,
|
|
26
26
|
XacheConversationBufferMemory: () => XacheConversationBufferMemory,
|
|
27
|
+
XacheEphemeralCreateSessionTool: () => XacheEphemeralCreateSessionTool,
|
|
28
|
+
XacheEphemeralPromoteTool: () => XacheEphemeralPromoteTool,
|
|
29
|
+
XacheEphemeralReadSlotTool: () => XacheEphemeralReadSlotTool,
|
|
30
|
+
XacheEphemeralStatusTool: () => XacheEphemeralStatusTool,
|
|
31
|
+
XacheEphemeralWriteSlotTool: () => XacheEphemeralWriteSlotTool,
|
|
27
32
|
XacheExtractor: () => XacheExtractor,
|
|
28
33
|
XacheGraphAskTool: () => XacheGraphAskTool,
|
|
29
34
|
XacheGraphEntityHistoryTool: () => XacheGraphEntityHistoryTool,
|
|
@@ -33,11 +38,17 @@ __export(index_exports, {
|
|
|
33
38
|
XacheGraphQueryTool: () => XacheGraphQueryTool,
|
|
34
39
|
XacheGraphRetriever: () => XacheGraphRetriever,
|
|
35
40
|
XacheMemory: () => XacheMemory,
|
|
41
|
+
XacheMemoryProbeTool: () => XacheMemoryProbeTool,
|
|
36
42
|
XacheReputationChecker: () => XacheReputationChecker,
|
|
37
43
|
XacheReputationTool: () => XacheReputationTool,
|
|
38
44
|
XacheRetriever: () => XacheRetriever,
|
|
39
45
|
createCollectiveContributeTool: () => createCollectiveContributeTool,
|
|
40
46
|
createCollectiveQueryTool: () => createCollectiveQueryTool,
|
|
47
|
+
createEphemeralCreateSessionTool: () => createEphemeralCreateSessionTool,
|
|
48
|
+
createEphemeralPromoteTool: () => createEphemeralPromoteTool,
|
|
49
|
+
createEphemeralReadSlotTool: () => createEphemeralReadSlotTool,
|
|
50
|
+
createEphemeralStatusTool: () => createEphemeralStatusTool,
|
|
51
|
+
createEphemeralWriteSlotTool: () => createEphemeralWriteSlotTool,
|
|
41
52
|
createGraphAddEntityTool: () => createGraphAddEntityTool,
|
|
42
53
|
createGraphAddRelationshipTool: () => createGraphAddRelationshipTool,
|
|
43
54
|
createGraphAskTool: () => createGraphAskTool,
|
|
@@ -46,6 +57,7 @@ __export(index_exports, {
|
|
|
46
57
|
createGraphLoadTool: () => createGraphLoadTool,
|
|
47
58
|
createGraphMergeEntitiesTool: () => createGraphMergeEntitiesTool,
|
|
48
59
|
createGraphQueryTool: () => createGraphQueryTool,
|
|
60
|
+
createMemoryProbeTool: () => createMemoryProbeTool,
|
|
49
61
|
createReputationTool: () => createReputationTool
|
|
50
62
|
});
|
|
51
63
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -990,12 +1002,254 @@ var XacheGraphRetriever = class extends import_retrievers2.BaseRetriever {
|
|
|
990
1002
|
});
|
|
991
1003
|
}
|
|
992
1004
|
};
|
|
1005
|
+
|
|
1006
|
+
// src/probe.ts
|
|
1007
|
+
var import_tools4 = require("@langchain/core/tools");
|
|
1008
|
+
var import_zod4 = require("zod");
|
|
1009
|
+
var import_sdk7 = require("@xache/sdk");
|
|
1010
|
+
function createClient4(config) {
|
|
1011
|
+
const chainPrefix = config.chain === "solana" ? "sol" : "evm";
|
|
1012
|
+
const did = `did:agent:${chainPrefix}:${config.walletAddress.toLowerCase()}`;
|
|
1013
|
+
return new import_sdk7.XacheClient({
|
|
1014
|
+
apiUrl: config.apiUrl || "https://api.xache.xyz",
|
|
1015
|
+
did,
|
|
1016
|
+
privateKey: config.privateKey,
|
|
1017
|
+
signer: config.signer,
|
|
1018
|
+
walletProvider: config.walletProvider,
|
|
1019
|
+
encryptionKey: config.encryptionKey
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
var COGNITIVE_CATEGORIES = [
|
|
1023
|
+
"preference",
|
|
1024
|
+
"fact",
|
|
1025
|
+
"event",
|
|
1026
|
+
"procedure",
|
|
1027
|
+
"relationship",
|
|
1028
|
+
"observation",
|
|
1029
|
+
"decision",
|
|
1030
|
+
"goal",
|
|
1031
|
+
"constraint",
|
|
1032
|
+
"reference",
|
|
1033
|
+
"summary",
|
|
1034
|
+
"handoff",
|
|
1035
|
+
"pattern",
|
|
1036
|
+
"feedback",
|
|
1037
|
+
"unknown"
|
|
1038
|
+
];
|
|
1039
|
+
function createMemoryProbeTool(config) {
|
|
1040
|
+
const client = createClient4(config);
|
|
1041
|
+
return new import_tools4.DynamicStructuredTool({
|
|
1042
|
+
name: "xache_memory_probe",
|
|
1043
|
+
description: "Search your memories by topic using zero-knowledge semantic matching. Use this when you want to check what you already know about a topic without knowing exact storage keys. Returns matching memories with decrypted data.",
|
|
1044
|
+
schema: import_zod4.z.object({
|
|
1045
|
+
query: import_zod4.z.string().describe("What to search for in your memories"),
|
|
1046
|
+
category: import_zod4.z.enum(COGNITIVE_CATEGORIES).optional().describe("Filter by cognitive category"),
|
|
1047
|
+
limit: import_zod4.z.number().optional().default(10).describe("Maximum number of results (1-50)")
|
|
1048
|
+
}),
|
|
1049
|
+
func: async ({ query, category, limit }) => {
|
|
1050
|
+
const result = await client.memory.probe({
|
|
1051
|
+
query,
|
|
1052
|
+
category,
|
|
1053
|
+
limit: limit || 10
|
|
1054
|
+
});
|
|
1055
|
+
const matches = result.matches || [];
|
|
1056
|
+
if (matches.length === 0) {
|
|
1057
|
+
return "No matching memories found for this query.";
|
|
1058
|
+
}
|
|
1059
|
+
let output = `Found ${matches.length} matching memories (total: ${result.total}):
|
|
1060
|
+
`;
|
|
1061
|
+
matches.forEach((match, i) => {
|
|
1062
|
+
const data = typeof match.data === "string" ? match.data.slice(0, 300) : JSON.stringify(match.data).slice(0, 300);
|
|
1063
|
+
output += `
|
|
1064
|
+
${i + 1}. [${match.category}] ${data}`;
|
|
1065
|
+
output += ` (key: ${match.storageKey})`;
|
|
1066
|
+
});
|
|
1067
|
+
return output;
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
var XacheMemoryProbeTool = class {
|
|
1072
|
+
constructor(config) {
|
|
1073
|
+
this.tool = createMemoryProbeTool(config);
|
|
1074
|
+
}
|
|
1075
|
+
asTool() {
|
|
1076
|
+
return this.tool;
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
// src/ephemeral.ts
|
|
1081
|
+
var import_tools5 = require("@langchain/core/tools");
|
|
1082
|
+
var import_zod5 = require("zod");
|
|
1083
|
+
var import_sdk8 = require("@xache/sdk");
|
|
1084
|
+
function createClient5(config) {
|
|
1085
|
+
const chainPrefix = config.chain === "solana" ? "sol" : "evm";
|
|
1086
|
+
const did = `did:agent:${chainPrefix}:${config.walletAddress.toLowerCase()}`;
|
|
1087
|
+
return new import_sdk8.XacheClient({
|
|
1088
|
+
apiUrl: config.apiUrl || "https://api.xache.xyz",
|
|
1089
|
+
did,
|
|
1090
|
+
privateKey: config.privateKey,
|
|
1091
|
+
signer: config.signer,
|
|
1092
|
+
walletProvider: config.walletProvider,
|
|
1093
|
+
encryptionKey: config.encryptionKey
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
function createEphemeralCreateSessionTool(config) {
|
|
1097
|
+
const client = createClient5(config);
|
|
1098
|
+
return new import_tools5.DynamicStructuredTool({
|
|
1099
|
+
name: "xache_ephemeral_create_session",
|
|
1100
|
+
description: "Create a new ephemeral working memory session. Returns a session key for storing temporary data in slots.",
|
|
1101
|
+
schema: import_zod5.z.object({
|
|
1102
|
+
ttlSeconds: import_zod5.z.number().optional().describe("Session time-to-live in seconds (default: 3600)"),
|
|
1103
|
+
maxWindows: import_zod5.z.number().optional().describe("Maximum renewal windows (default: 5)")
|
|
1104
|
+
}),
|
|
1105
|
+
func: async ({ ttlSeconds, maxWindows }) => {
|
|
1106
|
+
const session = await client.ephemeral.createSession({
|
|
1107
|
+
ttlSeconds,
|
|
1108
|
+
maxWindows
|
|
1109
|
+
});
|
|
1110
|
+
return [
|
|
1111
|
+
`Created ephemeral session.`,
|
|
1112
|
+
`Session Key: ${session.sessionKey}`,
|
|
1113
|
+
`Status: ${session.status}`,
|
|
1114
|
+
`TTL: ${session.ttlSeconds}s`,
|
|
1115
|
+
`Expires: ${session.expiresAt}`
|
|
1116
|
+
].join("\n");
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
function createEphemeralWriteSlotTool(config) {
|
|
1121
|
+
const client = createClient5(config);
|
|
1122
|
+
return new import_tools5.DynamicStructuredTool({
|
|
1123
|
+
name: "xache_ephemeral_write_slot",
|
|
1124
|
+
description: "Write data to an ephemeral session slot. Slots: conversation, facts, tasks, cache, scratch, handoff.",
|
|
1125
|
+
schema: import_zod5.z.object({
|
|
1126
|
+
sessionKey: import_zod5.z.string().describe("The ephemeral session key"),
|
|
1127
|
+
slot: import_zod5.z.enum(["conversation", "facts", "tasks", "cache", "scratch", "handoff"]).describe("Slot name"),
|
|
1128
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).describe("Data to write to the slot")
|
|
1129
|
+
}),
|
|
1130
|
+
func: async ({ sessionKey, slot, data }) => {
|
|
1131
|
+
await client.ephemeral.writeSlot(sessionKey, slot, data);
|
|
1132
|
+
return `Wrote data to slot "${slot}" in session ${sessionKey.substring(0, 12)}...`;
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
function createEphemeralReadSlotTool(config) {
|
|
1137
|
+
const client = createClient5(config);
|
|
1138
|
+
return new import_tools5.DynamicStructuredTool({
|
|
1139
|
+
name: "xache_ephemeral_read_slot",
|
|
1140
|
+
description: "Read data from an ephemeral session slot. Slots: conversation, facts, tasks, cache, scratch, handoff.",
|
|
1141
|
+
schema: import_zod5.z.object({
|
|
1142
|
+
sessionKey: import_zod5.z.string().describe("The ephemeral session key"),
|
|
1143
|
+
slot: import_zod5.z.enum(["conversation", "facts", "tasks", "cache", "scratch", "handoff"]).describe("Slot name")
|
|
1144
|
+
}),
|
|
1145
|
+
func: async ({ sessionKey, slot }) => {
|
|
1146
|
+
const data = await client.ephemeral.readSlot(sessionKey, slot);
|
|
1147
|
+
return JSON.stringify(data, null, 2);
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
function createEphemeralPromoteTool(config) {
|
|
1152
|
+
const client = createClient5(config);
|
|
1153
|
+
return new import_tools5.DynamicStructuredTool({
|
|
1154
|
+
name: "xache_ephemeral_promote",
|
|
1155
|
+
description: "Promote an ephemeral session to persistent memory. Extracts valuable data from slots and stores as permanent memories.",
|
|
1156
|
+
schema: import_zod5.z.object({
|
|
1157
|
+
sessionKey: import_zod5.z.string().describe("The ephemeral session key to promote")
|
|
1158
|
+
}),
|
|
1159
|
+
func: async ({ sessionKey }) => {
|
|
1160
|
+
const result = await client.ephemeral.promoteSession(sessionKey);
|
|
1161
|
+
let output = `Promoted session ${sessionKey.substring(0, 12)}...
|
|
1162
|
+
`;
|
|
1163
|
+
output += `Memories created: ${result.memoriesCreated}
|
|
1164
|
+
`;
|
|
1165
|
+
if (result.memoryIds.length > 0) {
|
|
1166
|
+
output += `Memory IDs: ${result.memoryIds.join(", ")}
|
|
1167
|
+
`;
|
|
1168
|
+
}
|
|
1169
|
+
if (result.receiptId) {
|
|
1170
|
+
output += `Receipt: ${result.receiptId}`;
|
|
1171
|
+
}
|
|
1172
|
+
return output;
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
function createEphemeralStatusTool(config) {
|
|
1177
|
+
const client = createClient5(config);
|
|
1178
|
+
return new import_tools5.DynamicStructuredTool({
|
|
1179
|
+
name: "xache_ephemeral_status",
|
|
1180
|
+
description: "Get the status and details of an ephemeral session. Shows active slots, size, TTL, and window information.",
|
|
1181
|
+
schema: import_zod5.z.object({
|
|
1182
|
+
sessionKey: import_zod5.z.string().describe("The ephemeral session key")
|
|
1183
|
+
}),
|
|
1184
|
+
func: async ({ sessionKey }) => {
|
|
1185
|
+
const session = await client.ephemeral.getSession(sessionKey);
|
|
1186
|
+
if (!session) {
|
|
1187
|
+
return `Session ${sessionKey.substring(0, 12)}... not found.`;
|
|
1188
|
+
}
|
|
1189
|
+
return [
|
|
1190
|
+
`Session: ${session.sessionKey.substring(0, 12)}...`,
|
|
1191
|
+
`Status: ${session.status}`,
|
|
1192
|
+
`Window: ${session.window}/${session.maxWindows}`,
|
|
1193
|
+
`TTL: ${session.ttlSeconds}s`,
|
|
1194
|
+
`Expires: ${session.expiresAt}`,
|
|
1195
|
+
`Active Slots: ${session.activeSlots.length > 0 ? session.activeSlots.join(", ") : "none"}`,
|
|
1196
|
+
`Total Size: ${session.totalSize} bytes`,
|
|
1197
|
+
`Cumulative Cost: $${session.cumulativeCost.toFixed(4)}`
|
|
1198
|
+
].join("\n");
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
var XacheEphemeralCreateSessionTool = class {
|
|
1203
|
+
constructor(config) {
|
|
1204
|
+
this.tool = createEphemeralCreateSessionTool(config);
|
|
1205
|
+
}
|
|
1206
|
+
asTool() {
|
|
1207
|
+
return this.tool;
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
var XacheEphemeralWriteSlotTool = class {
|
|
1211
|
+
constructor(config) {
|
|
1212
|
+
this.tool = createEphemeralWriteSlotTool(config);
|
|
1213
|
+
}
|
|
1214
|
+
asTool() {
|
|
1215
|
+
return this.tool;
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
var XacheEphemeralReadSlotTool = class {
|
|
1219
|
+
constructor(config) {
|
|
1220
|
+
this.tool = createEphemeralReadSlotTool(config);
|
|
1221
|
+
}
|
|
1222
|
+
asTool() {
|
|
1223
|
+
return this.tool;
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
var XacheEphemeralPromoteTool = class {
|
|
1227
|
+
constructor(config) {
|
|
1228
|
+
this.tool = createEphemeralPromoteTool(config);
|
|
1229
|
+
}
|
|
1230
|
+
asTool() {
|
|
1231
|
+
return this.tool;
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
var XacheEphemeralStatusTool = class {
|
|
1235
|
+
constructor(config) {
|
|
1236
|
+
this.tool = createEphemeralStatusTool(config);
|
|
1237
|
+
}
|
|
1238
|
+
asTool() {
|
|
1239
|
+
return this.tool;
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
993
1242
|
// Annotate the CommonJS export names for ESM import in node:
|
|
994
1243
|
0 && (module.exports = {
|
|
995
1244
|
XacheChatMessageHistory,
|
|
996
1245
|
XacheCollectiveContributeTool,
|
|
997
1246
|
XacheCollectiveQueryTool,
|
|
998
1247
|
XacheConversationBufferMemory,
|
|
1248
|
+
XacheEphemeralCreateSessionTool,
|
|
1249
|
+
XacheEphemeralPromoteTool,
|
|
1250
|
+
XacheEphemeralReadSlotTool,
|
|
1251
|
+
XacheEphemeralStatusTool,
|
|
1252
|
+
XacheEphemeralWriteSlotTool,
|
|
999
1253
|
XacheExtractor,
|
|
1000
1254
|
XacheGraphAskTool,
|
|
1001
1255
|
XacheGraphEntityHistoryTool,
|
|
@@ -1005,11 +1259,17 @@ var XacheGraphRetriever = class extends import_retrievers2.BaseRetriever {
|
|
|
1005
1259
|
XacheGraphQueryTool,
|
|
1006
1260
|
XacheGraphRetriever,
|
|
1007
1261
|
XacheMemory,
|
|
1262
|
+
XacheMemoryProbeTool,
|
|
1008
1263
|
XacheReputationChecker,
|
|
1009
1264
|
XacheReputationTool,
|
|
1010
1265
|
XacheRetriever,
|
|
1011
1266
|
createCollectiveContributeTool,
|
|
1012
1267
|
createCollectiveQueryTool,
|
|
1268
|
+
createEphemeralCreateSessionTool,
|
|
1269
|
+
createEphemeralPromoteTool,
|
|
1270
|
+
createEphemeralReadSlotTool,
|
|
1271
|
+
createEphemeralStatusTool,
|
|
1272
|
+
createEphemeralWriteSlotTool,
|
|
1013
1273
|
createGraphAddEntityTool,
|
|
1014
1274
|
createGraphAddRelationshipTool,
|
|
1015
1275
|
createGraphAskTool,
|
|
@@ -1018,6 +1278,7 @@ var XacheGraphRetriever = class extends import_retrievers2.BaseRetriever {
|
|
|
1018
1278
|
createGraphLoadTool,
|
|
1019
1279
|
createGraphMergeEntitiesTool,
|
|
1020
1280
|
createGraphQueryTool,
|
|
1281
|
+
createMemoryProbeTool,
|
|
1021
1282
|
createReputationTool
|
|
1022
1283
|
});
|
|
1023
1284
|
//# sourceMappingURL=index.js.map
|