@engramx/client 0.1.0 → 0.2.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/LICENSE +190 -21
- package/README.md +19 -22
- package/dist/EngramClient.d.ts +125 -4
- package/dist/EngramClient.js +449 -41
- package/dist/EngramClient.js.map +1 -1
- package/dist/actionReceipt.d.ts +41 -0
- package/dist/actionReceipt.js +67 -0
- package/dist/actionReceipt.js.map +1 -0
- package/dist/certifiedAudit.d.ts +26 -0
- package/dist/certifiedAudit.js +57 -0
- package/dist/certifiedAudit.js.map +1 -0
- package/dist/claude-setup.js +22 -3
- package/dist/claude-setup.js.map +1 -1
- package/dist/cli.js +19 -60
- package/dist/cli.js.map +1 -1
- package/dist/encryption.d.ts +15 -0
- package/dist/encryption.js +92 -5
- package/dist/encryption.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +146 -47
- package/dist/migrate.js.map +1 -1
- package/dist/offline.js +15 -1
- package/dist/offline.js.map +1 -1
- package/dist/openclaw-setup.js +33 -9
- package/dist/openclaw-setup.js.map +1 -1
- package/dist/path-utils.d.ts +10 -0
- package/dist/path-utils.js +28 -0
- package/dist/path-utils.js.map +1 -1
- package/dist/types.d.ts +35 -1
- package/package.json +3 -3
- package/dist/agent-skill.d.ts +0 -150
- package/dist/agent-skill.js +0 -152
- package/dist/agent-skill.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025-2026 Vaughn Hew
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -22,25 +22,24 @@ import { EngramClient } from '@engramx/client';
|
|
|
22
22
|
const engram = new EngramClient({
|
|
23
23
|
canisterId: 'xxxxx-xxxxx-xxxxx-xxxxx-xxx',
|
|
24
24
|
sessionKeyPath: '~/.engramx/session.key',
|
|
25
|
+
clientLabel: 'my-agent', // identifies this host in the engram's cross-model reuse set
|
|
25
26
|
});
|
|
26
27
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// At the START of a session: load everything the agent remembers, ready to inject as a
|
|
29
|
+
// system prompt. This is the "read me back" that continuity depends on — prefer it over a
|
|
30
|
+
// manual readMemoryBatch: it runs on the update path, so the read is recorded on-chain and
|
|
31
|
+
// counts toward reuse. (Query reads can't — the IC discards query-path state changes.)
|
|
32
|
+
const systemPrompt = await engram.sessionSystemPrompt();
|
|
33
|
+
// ...or get the structured files instead of a formatted string:
|
|
34
|
+
const ctx = await engram.startSession();
|
|
35
|
+
console.log(`loaded ${ctx.includedFiles}/${ctx.totalFiles} files`);
|
|
30
36
|
|
|
31
|
-
//
|
|
37
|
+
// AS THE AGENT WORKS: append (append-only; the canister concatenates the delta)
|
|
32
38
|
const version = await engram.appendMemory('memory/daily.md', '## Notes\nSomething happened.');
|
|
33
39
|
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
// Read session transcript
|
|
38
|
-
const messages = await engram.readSession('session-key', 0, 50);
|
|
39
|
-
|
|
40
|
-
// Append to session
|
|
41
|
-
await engram.appendSession('session-key', [
|
|
42
|
-
{ role: { User: null }, content: 'Hello', timestamp: BigInt(Date.now() * 1_000_000) },
|
|
43
|
-
]);
|
|
40
|
+
// Point reads: one file, or several at once
|
|
41
|
+
const file = await engram.readMemory('MEMORY.md');
|
|
42
|
+
const files = await engram.readMemoryBatch(['MEMORY.md', 'memory/daily.md']);
|
|
44
43
|
|
|
45
44
|
// Check balance
|
|
46
45
|
const balance = await engram.walletBalance();
|
|
@@ -51,16 +50,14 @@ const balance = await engram.walletBalance();
|
|
|
51
50
|
Register your machine as an operator:
|
|
52
51
|
|
|
53
52
|
```bash
|
|
54
|
-
#
|
|
55
|
-
pnpm dlx @engramx/client pair <invite-code> --engram <canister-id> --openclaw
|
|
53
|
+
# Pair this host — register as operator and install the OpenClaw plugin
|
|
54
|
+
pnpm dlx @engramx/client pair <invite-code> --engram <canister-id> --target openclaw
|
|
56
55
|
|
|
57
|
-
# Replacement host — restore
|
|
58
|
-
pnpm dlx @engramx/client
|
|
56
|
+
# Replacement host — after pairing, restore memory from the engram
|
|
57
|
+
pnpm dlx @engramx/client migrate --engram <canister-id> --recover
|
|
59
58
|
```
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Migration (default) pushes local memory files to the engram. Recovery (`--recover`) restores database backups; memory files sync automatically on next OpenClaw startup.
|
|
60
|
+
`pair` generates `~/.engramx/session.key`, registers the operator, and installs the OpenClaw plugin. `migrate` then moves memory, saving a local checkpoint first — run `npx @engramx/client rollback` to undo. Its default direction pushes local memory files to the engram; `--recover` instead restores database backups, and memory files sync automatically on next OpenClaw startup.
|
|
64
61
|
|
|
65
62
|
## Guardian API
|
|
66
63
|
|
|
@@ -101,7 +98,7 @@ const data = await engram.pullBackupChunk(backupId, 0);
|
|
|
101
98
|
|
|
102
99
|
## OpenClaw Integration
|
|
103
100
|
|
|
104
|
-
The `--openclaw`
|
|
101
|
+
The `--target openclaw` option on `pair` handles plugin installation and `openclaw.json` configuration automatically. For manual setup or customization, see [integrations/openclaw/README.md](../../integrations/openclaw/README.md).
|
|
105
102
|
|
|
106
103
|
## Roadmap
|
|
107
104
|
|
package/dist/EngramClient.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type CertifiedAuditHead, type VerifiedAuditHead } from './certifiedAudit';
|
|
1
2
|
import { Principal } from '@icp-sdk/core/principal';
|
|
2
3
|
import { Ic402Client, type SessionHandle } from '@ic402/client';
|
|
3
|
-
import type { RawMemoryFile, MemoryFile, MemoryFileInfo, MemoryVersion, OperatorRecord, AuditEntry, EngramStatus, GuardianRecord, WorldIdProof, BackupMetadata, BackupType, StorageStats, PaymentRequirement, PaymentSignature, PaymentResult, SessionIntent, SessionConfig, SessionState, Voucher, SpendingPolicy, ContentEntry, ContentDelivery, AgentCard, ApprovalRequest, EndpointType, EndpointStatus, X402Endpoint, PurchaseRecord, RevenueSummary } from './types';
|
|
4
|
+
import type { RawMemoryFile, MemoryFile, MemoryFileInfo, SessionContext, MemoryVersion, OperatorRecord, AuditEntry, EngramStatus, GuardianRecord, WorldIdProof, BackupMetadata, BackupType, StorageStats, PaymentRequirement, PaymentSignature, PaymentResult, SessionIntent, SessionConfig, SessionState, Voucher, SpendingPolicy, ContentEntry, ContentDelivery, AgentCard, ApprovalRequest, EndpointType, EndpointStatus, X402Endpoint, PurchaseRecord, RevenueSummary } from './types';
|
|
4
5
|
export interface EngramClientConfig {
|
|
5
6
|
/** The engram canister ID */
|
|
6
7
|
canisterId: string;
|
|
@@ -20,7 +21,13 @@ export interface EngramClientConfig {
|
|
|
20
21
|
* Enable for new/migrated engrams; the canister must support vetKD. Reads of
|
|
21
22
|
* legacy plaintext keep working regardless. */
|
|
22
23
|
encryptMemory?: boolean;
|
|
24
|
+
/** Label identifying this host in the engram's distinct-reader set (drives cross-model reuse
|
|
25
|
+
* metrics). Sent by `startSession()`. Default: 'sdk'. Use your product name, e.g. 'openclaw'. */
|
|
26
|
+
clientLabel?: string;
|
|
23
27
|
}
|
|
28
|
+
export declare const idlFactory: ({ IDL }: {
|
|
29
|
+
IDL: any;
|
|
30
|
+
}) => any;
|
|
24
31
|
export declare class EngramClient {
|
|
25
32
|
private agent;
|
|
26
33
|
private actor;
|
|
@@ -30,16 +37,68 @@ export declare class EngramClient {
|
|
|
30
37
|
private canisterId;
|
|
31
38
|
private encryption;
|
|
32
39
|
private encryptionModeSynced;
|
|
40
|
+
private clientLabel;
|
|
33
41
|
private unwrap;
|
|
34
42
|
constructor(config: EngramClientConfig);
|
|
35
43
|
readMemory(path: string): Promise<MemoryFile>;
|
|
44
|
+
/**
|
|
45
|
+
* Append `content` to a memory file (append-only; the canister concatenates the delta).
|
|
46
|
+
*
|
|
47
|
+
* @returns the new on-chain version. **Special case:** if an `offlineQueue` is configured and the
|
|
48
|
+
* network call fails with a transport error, the encoded delta is queued for a later
|
|
49
|
+
* `syncOfflineQueue()` and this returns `0n` — a "deferred, not yet committed" sentinel, NOT a real
|
|
50
|
+
* version. Callers that surface a version to users should treat `0n` as "queued". Deterministic
|
|
51
|
+
* errors (validation, permission, writes-paused, non-framed base in encrypted mode) always throw.
|
|
52
|
+
*/
|
|
36
53
|
appendMemory(path: string, content: string): Promise<bigint>;
|
|
37
54
|
listMemoryFiles(): Promise<MemoryFileInfo[]>;
|
|
38
55
|
readMemoryBatch(paths: string[]): Promise<[string, MemoryFile | Error][]>;
|
|
56
|
+
/**
|
|
57
|
+
* Load the engram's memory for injection at the START of an agent session — the automatic
|
|
58
|
+
* "read me back" that continuity depends on.
|
|
59
|
+
*
|
|
60
|
+
* Prefer this over a manual `readMemoryBatch` at session start: it runs on the canister's UPDATE
|
|
61
|
+
* path, so it registers the read on-chain and counts toward the engram's cross-model reuse metric
|
|
62
|
+
* (the north star). A query read cannot — the IC discards query-path state changes — so a session
|
|
63
|
+
* bootstrapped with queries is invisible to reuse accounting. Call this once per session; write with
|
|
64
|
+
* `appendMemory` as the agent works.
|
|
65
|
+
*
|
|
66
|
+
* Files come back newest-modified first and decrypted; `truncated` is true when the byte cap was hit
|
|
67
|
+
* and older files were omitted (page them with `readMemoryBatch`). Reserved `config/` and `secrets/`
|
|
68
|
+
* paths are excluded. Pass `clientLabel` in the constructor to identify this host in the reuse set.
|
|
69
|
+
*
|
|
70
|
+
* This is an update call, so it can fail transiently (rate limit) or deterministically (permission).
|
|
71
|
+
* By default it throws; pass `{ onError: 'empty' }` to degrade to an empty context instead — useful
|
|
72
|
+
* when a missing memory read should not abort the agent's session bootstrap.
|
|
73
|
+
*/
|
|
74
|
+
startSession(opts?: {
|
|
75
|
+
onError?: 'throw' | 'empty';
|
|
76
|
+
}): Promise<SessionContext>;
|
|
77
|
+
private loadSessionContext;
|
|
78
|
+
/**
|
|
79
|
+
* Format a {@link SessionContext} into a single system-prompt string ready to prepend to an agent's
|
|
80
|
+
* messages. Convenience over `startSession` for the common "inject everything I remember" case — call
|
|
81
|
+
* `startSession()` yourself if you need the structured files instead. Accepts the same `onError`
|
|
82
|
+
* option as `startSession`.
|
|
83
|
+
*
|
|
84
|
+
* SECURITY: memory content is written by operators (AI hosts) and is UNTRUSTED input, not host
|
|
85
|
+
* instructions. Each file is wrapped in a delimited `<engram-memory>` block and the header tells the
|
|
86
|
+
* model to treat the blocks as data — so appended memory cannot masquerade as system-level directives
|
|
87
|
+
* (prompt-injection boundary). Do not strip the fences when embedding this in your own prompt.
|
|
88
|
+
*/
|
|
89
|
+
sessionSystemPrompt(opts?: {
|
|
90
|
+
onError?: 'throw' | 'empty';
|
|
91
|
+
}): Promise<string>;
|
|
39
92
|
getMemoryHistory(path: string): Promise<MemoryVersion[]>;
|
|
40
93
|
walletBalance(): Promise<bigint>;
|
|
41
94
|
readAuditLog(fromIndex?: number, limit?: number): Promise<AuditEntry[]>;
|
|
42
95
|
auditLogSize(): Promise<bigint>;
|
|
96
|
+
/** The chained audit-log head plus the IC certificate over it (raw, unverified). Use
|
|
97
|
+
* getVerifiedAuditHead() to verify it against the IC root key. */
|
|
98
|
+
getCertifiedAuditHead(): Promise<CertifiedAuditHead>;
|
|
99
|
+
/** Fetch the certified audit head and VERIFY it against the IC root key — returns the certified
|
|
100
|
+
* head bytes and whether the replica's claim agrees, WITHOUT trusting this replica. */
|
|
101
|
+
getVerifiedAuditHead(): Promise<VerifiedAuditHead>;
|
|
43
102
|
status(): Promise<EngramStatus>;
|
|
44
103
|
listGuardians(): Promise<GuardianRecord[]>;
|
|
45
104
|
rotateOperatorKey(newPublicKeyHash: string): Promise<void>;
|
|
@@ -47,19 +106,51 @@ export declare class EngramClient {
|
|
|
47
106
|
getPaymentRequirements(amount: bigint): Promise<PaymentRequirement[]>;
|
|
48
107
|
requestSession(): Promise<SessionIntent>;
|
|
49
108
|
openSession(config: SessionConfig, sig: PaymentSignature, rationale?: string, approvalId?: string): Promise<SessionState | {
|
|
50
|
-
approvalPending:
|
|
109
|
+
approvalPending: {
|
|
110
|
+
requestId: string;
|
|
111
|
+
reason: string;
|
|
112
|
+
};
|
|
51
113
|
}>;
|
|
52
114
|
sessionReadMemory(voucher: Voucher, path: string): Promise<RawMemoryFile>;
|
|
53
115
|
sessionAppendMemory(voucher: Voucher, path: string, content: Uint8Array): Promise<bigint>;
|
|
54
116
|
endSession(sessionId: string): Promise<PaymentResult>;
|
|
55
117
|
forceCloseSession(sessionId: string): Promise<PaymentResult>;
|
|
118
|
+
private ownerAuthFor;
|
|
119
|
+
/**
|
|
120
|
+
* Withdraw a token balance to the owner's own principal (owner-only, destination-locked).
|
|
121
|
+
* Pass `{ receipt: true }` to attach an exportable owner-signed authorization (D1).
|
|
122
|
+
*/
|
|
123
|
+
ownerWithdraw(token: string, amount: bigint, options?: {
|
|
124
|
+
receipt?: boolean;
|
|
125
|
+
nonce?: bigint;
|
|
126
|
+
}): Promise<{
|
|
127
|
+
Ok: bigint;
|
|
128
|
+
} | {
|
|
129
|
+
Err: string;
|
|
130
|
+
}>;
|
|
56
131
|
uploadContent(id: string, mimeType: string, data: Uint8Array): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* E8: upload content larger than the ~2 MB single-shot ingress limit by streaming it through the
|
|
134
|
+
* canister's chunked path (uploadContentInit + uploadContentChunk). Chunk size is 1.5 MB — the
|
|
135
|
+
* ContentStore MAX_CHUNK_SIZE, enforced as a hard cap and safely under ICP's 2 MB ingress limit once
|
|
136
|
+
* Candid framing is added.
|
|
137
|
+
*
|
|
138
|
+
* There is NO finalize step: content is complete and readable once every chunk is written (the store
|
|
139
|
+
* reassembles on read). Chunks are write-once server-side (CTR keystream-reuse guard), so a mid-upload
|
|
140
|
+
* failure leaves a stuck, un-overwritable entry; on any error this helper best-effort deletes the
|
|
141
|
+
* partial entry so the caller can retry from scratch (set cleanupOnError=false to keep it for a manual
|
|
142
|
+
* resume). Payloads at or under one chunk delegate to single-shot uploadContent.
|
|
143
|
+
*/
|
|
144
|
+
uploadContentChunked(id: string, mimeType: string, data: Uint8Array, cleanupOnError?: boolean): Promise<void>;
|
|
57
145
|
listContent(): Promise<ContentEntry[]>;
|
|
58
146
|
getContent(contentId: string, paymentSig?: PaymentSignature, rationale?: string, approvalId?: string): Promise<{
|
|
59
147
|
paymentRequired?: PaymentRequirement[];
|
|
60
148
|
delivery?: ContentDelivery;
|
|
61
149
|
error?: string;
|
|
62
|
-
approvalPending?:
|
|
150
|
+
approvalPending?: {
|
|
151
|
+
requestId: string;
|
|
152
|
+
reason: string;
|
|
153
|
+
};
|
|
63
154
|
}>;
|
|
64
155
|
deleteContent(id: string): Promise<void>;
|
|
65
156
|
createEndpoint(name: string, description: string, endpointType: EndpointType, contentId: string | null, suggestedPrice: bigint): Promise<X402Endpoint>;
|
|
@@ -79,6 +170,15 @@ export declare class EngramClient {
|
|
|
79
170
|
getBackupMetadata(backupId: string): Promise<BackupMetadata>;
|
|
80
171
|
deleteBackup(backupId: string): Promise<void>;
|
|
81
172
|
latestBackupMatchesHash(dbType: string, sha256: string): Promise<BackupMetadata | null>;
|
|
173
|
+
/** Encrypt a backup payload IFF this engram is in Private mode — the SAME toggle that governs
|
|
174
|
+
* memory files governs backups (encrypt files ⇒ encrypt backups). Produces a whole-blob
|
|
175
|
+
* envelope (MAGIC|ciphertext); a passthrough (returns the input) in Connected mode. Compute the
|
|
176
|
+
* dedup/integrity SHA-256 over the PLAINTEXT, then encrypt its result for upload. */
|
|
177
|
+
encryptBackupPayload(data: Uint8Array): Promise<Uint8Array>;
|
|
178
|
+
/** Reverse of encryptBackupPayload: decrypt a pulled backup blob when it carries the ENC magic.
|
|
179
|
+
* Content-driven (not flag-driven), so a plaintext / legacy backup passes through unchanged
|
|
180
|
+
* regardless of the current mode. Returns the original DB bytes, ready to write to disk. */
|
|
181
|
+
decryptBackupPayload(bytes: Uint8Array): Promise<Uint8Array>;
|
|
82
182
|
storageStats(): Promise<StorageStats>;
|
|
83
183
|
/** Warm the vetKeys memory-encryption key cache (one vetKD derivation). Optional —
|
|
84
184
|
* read/append derive lazily on first use. */
|
|
@@ -103,12 +203,27 @@ export declare class EngramClient {
|
|
|
103
203
|
total: number;
|
|
104
204
|
failed: string[];
|
|
105
205
|
}>;
|
|
206
|
+
/** Owner-only: DECRYPT all existing memory files back to plaintext-at-rest — the reverse of
|
|
207
|
+
* migrateMemoryToEncrypted(). Reads each file, and if it is encrypted (framed segments or a
|
|
208
|
+
* legacy whole-file envelope), recovers the plaintext BYTES and rewrites it via writeMemory;
|
|
209
|
+
* already-plaintext files are skipped. Idempotent + resumable. Run this BEFORE turning
|
|
210
|
+
* encryption off so the hosted surface can serve the files. Decryption derives the key on
|
|
211
|
+
* demand, so it works regardless of the canister flag for a read-authorized owner. */
|
|
212
|
+
migrateMemoryToPlaintext(): Promise<{
|
|
213
|
+
migrated: number;
|
|
214
|
+
total: number;
|
|
215
|
+
failed: string[];
|
|
216
|
+
}>;
|
|
106
217
|
syncOfflineQueue(): Promise<{
|
|
107
218
|
synced: number;
|
|
108
219
|
failed: number;
|
|
109
220
|
}>;
|
|
110
221
|
registerOperator(inviteCode: string): Promise<OperatorRecord>;
|
|
111
222
|
getProtectedPaths(): Promise<string[]>;
|
|
223
|
+
/** The caller's OWN payment approval requests (not owner-only listApprovalRequests). Poll this after an
|
|
224
|
+
* over-limit payment returns approvalPending: when the owner raises the spending limit, the request
|
|
225
|
+
* flips to `Approved` and the operation can be retried. Operator-safe (returns only your own requests). */
|
|
226
|
+
getMyApprovalRequests(): Promise<ApprovalRequest[]>;
|
|
112
227
|
/**
|
|
113
228
|
* Create a pre-configured Ic402Client for auto-payment operations.
|
|
114
229
|
* The client handles 402 → ICRC-2 approve → retry automatically.
|
|
@@ -166,7 +281,7 @@ export declare class EngramClient {
|
|
|
166
281
|
Callback: null;
|
|
167
282
|
} | {
|
|
168
283
|
Both: null;
|
|
169
|
-
}, timeout: bigint, verifierCanisterId?: string, verificationKey?: Uint8Array): Promise<string>;
|
|
284
|
+
}, timeout: bigint, verifierCanisterId?: string, verificationKey?: Uint8Array, bindResult?: boolean): Promise<string>;
|
|
170
285
|
listServices(): Promise<unknown[]>;
|
|
171
286
|
/** Owner/operator view — includes disabled service drafts (others get enabled-only). */
|
|
172
287
|
listAllServices(): Promise<unknown[]>;
|
|
@@ -196,6 +311,12 @@ export declare class EngramClient {
|
|
|
196
311
|
disputeJob(jobId: string, reason: string): Promise<void>;
|
|
197
312
|
getJobStatus(jobId: string): Promise<unknown | null>;
|
|
198
313
|
getJob(jobId: string): Promise<unknown | null>;
|
|
314
|
+
/**
|
|
315
|
+
* E1: enumerate a service's job summaries. Owner OR the service's own operator only — any other
|
|
316
|
+
* caller gets []. Summaries omit params/result/proof blobs (use getJob(jobId) for a full payload).
|
|
317
|
+
* Pass a statusFilter like `{ Pending: null }` to filter, or omit for all statuses.
|
|
318
|
+
*/
|
|
319
|
+
listJobs(serviceId: string, statusFilter?: unknown): Promise<unknown[]>;
|
|
199
320
|
getJobResult(jobId: string): Promise<Uint8Array | null>;
|
|
200
321
|
pollJobResult(jobId: string, maxAttempts?: number, intervalMs?: number): Promise<unknown>;
|
|
201
322
|
keccak256(data: number[]): Promise<number[]>;
|