@forbocai/core 0.5.2 → 0.5.6
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/ans104-GLQVFKBA.mjs +224 -0
- package/dist/chunk-7P6ASYW6.mjs +9 -0
- package/dist/index.d.mts +29 -70
- package/dist/index.d.ts +29 -70
- package/dist/index.js +306 -85
- package/dist/index.mjs +76 -89
- package/package.json +3 -2
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
2
|
+
|
|
3
|
+
// src/ans104.ts
|
|
4
|
+
import base64url from "base64url";
|
|
5
|
+
import { Buffer } from "buffer";
|
|
6
|
+
import { constants, createHash, createSign } from "crypto";
|
|
7
|
+
import { jwkTopem } from "arweave/node/lib/crypto/pem";
|
|
8
|
+
var SIGNATURE_TYPE_ARWEAVE = 1;
|
|
9
|
+
var SIGNATURE_LENGTH = 512;
|
|
10
|
+
var OWNER_LENGTH = 512;
|
|
11
|
+
var MAX_TAG_BYTES = 4096;
|
|
12
|
+
var stringToBuffer = (value) => Buffer.from(value);
|
|
13
|
+
var concatBuffers = (buffers) => Buffer.concat(buffers);
|
|
14
|
+
var longToNByteArray = (bytes, long) => {
|
|
15
|
+
const byteArray = new Uint8Array(bytes);
|
|
16
|
+
if (long < 0) throw new Error("Array is unsigned, cannot represent -ve numbers");
|
|
17
|
+
if (long > 2 ** (bytes * 8) - 1) throw new Error(`Number ${long} is too large for an array of ${bytes} bytes`);
|
|
18
|
+
for (let index = 0; index < byteArray.length; index++) {
|
|
19
|
+
const byte = long & 255;
|
|
20
|
+
byteArray[index] = byte;
|
|
21
|
+
long = (long - byte) / 256;
|
|
22
|
+
}
|
|
23
|
+
return byteArray;
|
|
24
|
+
};
|
|
25
|
+
var longTo8ByteArray = (long) => longToNByteArray(8, long);
|
|
26
|
+
var shortTo2ByteArray = (short) => longToNByteArray(2, short);
|
|
27
|
+
var AVSCTap = class {
|
|
28
|
+
constructor(buf = Buffer.alloc(MAX_TAG_BYTES), pos = 0) {
|
|
29
|
+
this.buf = buf;
|
|
30
|
+
this.pos = pos;
|
|
31
|
+
}
|
|
32
|
+
writeTags(tags) {
|
|
33
|
+
if (!Array.isArray(tags)) {
|
|
34
|
+
throw new Error("input must be array");
|
|
35
|
+
}
|
|
36
|
+
const n = tags.length;
|
|
37
|
+
if (n) {
|
|
38
|
+
this.writeLong(n);
|
|
39
|
+
for (let i = 0; i < n; i++) {
|
|
40
|
+
const tag = tags[i];
|
|
41
|
+
if (typeof tag?.name !== "string" || typeof tag?.value !== "string") {
|
|
42
|
+
throw new Error(`Invalid tag format for ${tag}, expected {name:string, value: string}`);
|
|
43
|
+
}
|
|
44
|
+
this.writeString(tag.name);
|
|
45
|
+
this.writeString(tag.value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
this.writeLong(0);
|
|
49
|
+
}
|
|
50
|
+
toBuffer() {
|
|
51
|
+
const buffer = Buffer.alloc(this.pos);
|
|
52
|
+
if (this.pos > this.buf.length) throw new Error(`Too many tag bytes (${this.pos} > ${this.buf.length})`);
|
|
53
|
+
this.buf.copy(buffer, 0, 0, this.pos);
|
|
54
|
+
return buffer;
|
|
55
|
+
}
|
|
56
|
+
writeLong(n) {
|
|
57
|
+
const buf = this.buf;
|
|
58
|
+
let f, m;
|
|
59
|
+
if (n >= -1073741824 && n < 1073741824) {
|
|
60
|
+
m = n >= 0 ? n << 1 : ~n << 1 | 1;
|
|
61
|
+
do {
|
|
62
|
+
buf[this.pos] = m & 127;
|
|
63
|
+
m >>= 7;
|
|
64
|
+
} while (m && (buf[this.pos++] |= 128));
|
|
65
|
+
} else {
|
|
66
|
+
f = n >= 0 ? n * 2 : -n * 2 - 1;
|
|
67
|
+
do {
|
|
68
|
+
buf[this.pos] = f & 127;
|
|
69
|
+
f /= 128;
|
|
70
|
+
} while (f >= 1 && (buf[this.pos++] |= 128));
|
|
71
|
+
}
|
|
72
|
+
this.pos++;
|
|
73
|
+
this.buf = buf;
|
|
74
|
+
}
|
|
75
|
+
writeString(s) {
|
|
76
|
+
const len = Buffer.byteLength(s);
|
|
77
|
+
const buf = this.buf;
|
|
78
|
+
this.writeLong(len);
|
|
79
|
+
let pos = this.pos;
|
|
80
|
+
this.pos += len;
|
|
81
|
+
if (this.pos > buf.length) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (len > 64) {
|
|
85
|
+
this.buf.write(s, this.pos - len, len, "utf8");
|
|
86
|
+
} else {
|
|
87
|
+
let i, l, c1, c2;
|
|
88
|
+
for (i = 0, l = len; i < l; i++) {
|
|
89
|
+
c1 = s.charCodeAt(i);
|
|
90
|
+
if (c1 < 128) {
|
|
91
|
+
buf[pos++] = c1;
|
|
92
|
+
} else if (c1 < 2048) {
|
|
93
|
+
buf[pos++] = c1 >> 6 | 192;
|
|
94
|
+
buf[pos++] = c1 & 63 | 128;
|
|
95
|
+
} else if ((c1 & 64512) === 55296 && ((c2 = s.charCodeAt(i + 1)) & 64512) === 56320) {
|
|
96
|
+
c1 = 65536 + ((c1 & 1023) << 10) + (c2 & 1023);
|
|
97
|
+
i++;
|
|
98
|
+
buf[pos++] = c1 >> 18 | 240;
|
|
99
|
+
buf[pos++] = c1 >> 12 & 63 | 128;
|
|
100
|
+
buf[pos++] = c1 >> 6 & 63 | 128;
|
|
101
|
+
buf[pos++] = c1 & 63 | 128;
|
|
102
|
+
} else {
|
|
103
|
+
buf[pos++] = c1 >> 12 | 224;
|
|
104
|
+
buf[pos++] = c1 >> 6 & 63 | 128;
|
|
105
|
+
buf[pos++] = c1 & 63 | 128;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.buf = buf;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var serializeTags = (tags) => {
|
|
113
|
+
if (tags?.length === 0) {
|
|
114
|
+
return Buffer.allocUnsafe(0);
|
|
115
|
+
}
|
|
116
|
+
const tap = new AVSCTap();
|
|
117
|
+
tap.writeTags(tags);
|
|
118
|
+
return tap.toBuffer();
|
|
119
|
+
};
|
|
120
|
+
var hash = (data, algorithm) => {
|
|
121
|
+
const algo = algorithm === "SHA-256" ? "sha256" : "sha384";
|
|
122
|
+
return createHash(algo).update(data).digest();
|
|
123
|
+
};
|
|
124
|
+
var deepHash = async (data) => {
|
|
125
|
+
if (Array.isArray(data)) {
|
|
126
|
+
const tag2 = concatBuffers([stringToBuffer("list"), stringToBuffer(data.length.toString())]);
|
|
127
|
+
return deepHashChunks(data, hash(tag2, "SHA-384"));
|
|
128
|
+
}
|
|
129
|
+
const _data = data;
|
|
130
|
+
const tag = concatBuffers([stringToBuffer("blob"), stringToBuffer(_data.byteLength.toString())]);
|
|
131
|
+
const taggedHash = concatBuffers([hash(tag, "SHA-384"), hash(_data, "SHA-384")]);
|
|
132
|
+
return hash(taggedHash, "SHA-384");
|
|
133
|
+
};
|
|
134
|
+
var deepHashChunks = async (chunks, acc) => {
|
|
135
|
+
if (chunks.length < 1) {
|
|
136
|
+
return acc;
|
|
137
|
+
}
|
|
138
|
+
const hashPair = concatBuffers([acc, await deepHash(chunks[0])]);
|
|
139
|
+
const newAcc = hash(hashPair, "SHA-384");
|
|
140
|
+
return deepHashChunks(chunks.slice(1), newAcc);
|
|
141
|
+
};
|
|
142
|
+
var getSignatureData = async (signatureType, rawOwner, rawTarget, rawAnchor, rawTags, rawData) => {
|
|
143
|
+
return deepHash([
|
|
144
|
+
stringToBuffer("dataitem"),
|
|
145
|
+
stringToBuffer("1"),
|
|
146
|
+
stringToBuffer(signatureType.toString()),
|
|
147
|
+
rawOwner,
|
|
148
|
+
rawTarget,
|
|
149
|
+
rawAnchor,
|
|
150
|
+
rawTags,
|
|
151
|
+
rawData
|
|
152
|
+
]);
|
|
153
|
+
};
|
|
154
|
+
var signData = async (pemKey, message) => {
|
|
155
|
+
return createSign("sha256").update(message).sign({
|
|
156
|
+
key: pemKey,
|
|
157
|
+
padding: constants.RSA_PKCS1_PSS_PADDING
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
var getOwner = (jwk) => {
|
|
161
|
+
return base64url.toBuffer(jwk.n);
|
|
162
|
+
};
|
|
163
|
+
var getPem = (jwk) => {
|
|
164
|
+
const pem = jwkTopem(jwk);
|
|
165
|
+
return typeof pem === "string" ? pem : pem.toString();
|
|
166
|
+
};
|
|
167
|
+
var createArweaveDataItem = async (data, jwk, opts) => {
|
|
168
|
+
const rawOwner = getOwner(jwk);
|
|
169
|
+
if (rawOwner.byteLength !== OWNER_LENGTH) {
|
|
170
|
+
throw new Error(`Owner must be ${OWNER_LENGTH} bytes, but was ${rawOwner.byteLength}`);
|
|
171
|
+
}
|
|
172
|
+
const rawTarget = opts?.target ? base64url.toBuffer(opts.target) : Buffer.alloc(0);
|
|
173
|
+
const rawAnchor = opts?.anchor ? Buffer.from(opts.anchor) : Buffer.alloc(0);
|
|
174
|
+
const rawTags = (opts?.tags?.length ?? 0) > 0 ? serializeTags(opts?.tags) : Buffer.alloc(0);
|
|
175
|
+
const rawData = typeof data === "string" ? Buffer.from(data) : Buffer.from(data);
|
|
176
|
+
const targetLength = 1 + (rawTarget?.byteLength ?? 0);
|
|
177
|
+
const anchorLength = 1 + (rawAnchor?.byteLength ?? 0);
|
|
178
|
+
const tagsLength = 16 + (rawTags ? rawTags.byteLength : 0);
|
|
179
|
+
const dataLength = rawData.byteLength;
|
|
180
|
+
const length = 2 + SIGNATURE_LENGTH + OWNER_LENGTH + targetLength + anchorLength + tagsLength + dataLength;
|
|
181
|
+
const bytes = Buffer.alloc(length);
|
|
182
|
+
bytes.set(shortTo2ByteArray(SIGNATURE_TYPE_ARWEAVE), 0);
|
|
183
|
+
bytes.set(new Uint8Array(SIGNATURE_LENGTH).fill(0), 2);
|
|
184
|
+
bytes.set(rawOwner, 2 + SIGNATURE_LENGTH);
|
|
185
|
+
const position = 2 + SIGNATURE_LENGTH + OWNER_LENGTH;
|
|
186
|
+
bytes[position] = rawTarget.length > 0 ? 1 : 0;
|
|
187
|
+
if (rawTarget.length > 0) {
|
|
188
|
+
if (rawTarget.byteLength !== 32) throw new Error("Target must be 32 bytes");
|
|
189
|
+
bytes.set(rawTarget, position + 1);
|
|
190
|
+
}
|
|
191
|
+
const anchorStart = position + targetLength;
|
|
192
|
+
let tagsStart = anchorStart + 1;
|
|
193
|
+
bytes[anchorStart] = rawAnchor.length > 0 ? 1 : 0;
|
|
194
|
+
if (rawAnchor.length > 0) {
|
|
195
|
+
tagsStart += rawAnchor.byteLength;
|
|
196
|
+
if (rawAnchor.byteLength !== 32) throw new Error("Anchor must be 32 bytes");
|
|
197
|
+
bytes.set(rawAnchor, anchorStart + 1);
|
|
198
|
+
}
|
|
199
|
+
bytes.set(longTo8ByteArray(opts?.tags?.length ?? 0), tagsStart);
|
|
200
|
+
bytes.set(longTo8ByteArray(rawTags?.byteLength ?? 0), tagsStart + 8);
|
|
201
|
+
if (rawTags.length > 0) {
|
|
202
|
+
bytes.set(rawTags, tagsStart + 16);
|
|
203
|
+
}
|
|
204
|
+
const dataStart = tagsStart + tagsLength;
|
|
205
|
+
bytes.set(rawData, dataStart);
|
|
206
|
+
const signatureData = await getSignatureData(
|
|
207
|
+
SIGNATURE_TYPE_ARWEAVE,
|
|
208
|
+
rawOwner,
|
|
209
|
+
rawTarget,
|
|
210
|
+
rawAnchor,
|
|
211
|
+
rawTags,
|
|
212
|
+
rawData
|
|
213
|
+
);
|
|
214
|
+
const signature = await signData(getPem(jwk), signatureData);
|
|
215
|
+
bytes.set(signature, 2);
|
|
216
|
+
const id = hash(signature, "SHA-256");
|
|
217
|
+
return {
|
|
218
|
+
id: base64url.encode(id),
|
|
219
|
+
raw: bytes
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
export {
|
|
223
|
+
createArweaveDataItem
|
|
224
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -30,17 +30,24 @@ interface CompletionOptions {
|
|
|
30
30
|
stop?: string[];
|
|
31
31
|
jsonSchema?: object;
|
|
32
32
|
}
|
|
33
|
-
type Mood = string;
|
|
34
33
|
interface AgentState {
|
|
35
34
|
[key: string]: unknown;
|
|
36
35
|
}
|
|
36
|
+
/** Interface for Memory module operations used by the Agent. */
|
|
37
|
+
interface IMemory {
|
|
38
|
+
store(text: string, type?: string, importance?: number): Promise<MemoryItem>;
|
|
39
|
+
recall(query: string, limit?: number, threshold?: number): Promise<MemoryItem[]>;
|
|
40
|
+
list(limit?: number, offset?: number): Promise<MemoryItem[]>;
|
|
41
|
+
clear(): Promise<void>;
|
|
42
|
+
export(): Promise<MemoryItem[]>;
|
|
43
|
+
import(memories: MemoryItem[]): Promise<void>;
|
|
44
|
+
}
|
|
37
45
|
interface AgentConfig {
|
|
38
46
|
id: string;
|
|
39
47
|
cortex: ICortex;
|
|
40
|
-
memory:
|
|
48
|
+
memory: IMemory | null;
|
|
41
49
|
persona: string;
|
|
42
50
|
initialState?: Partial<AgentState>;
|
|
43
|
-
memoryConfig?: MemoryConfig;
|
|
44
51
|
apiUrl?: string;
|
|
45
52
|
}
|
|
46
53
|
interface AgentResponse {
|
|
@@ -48,37 +55,14 @@ interface AgentResponse {
|
|
|
48
55
|
action?: AgentAction;
|
|
49
56
|
thought?: string;
|
|
50
57
|
}
|
|
51
|
-
type MemoryType = string;
|
|
52
|
-
interface MemoryConfig {
|
|
53
|
-
/** Decay strategy: 'none' | 'temporal' */
|
|
54
|
-
decay?: 'none' | 'temporal';
|
|
55
|
-
/** Max memories to keep in active context during retrieval */
|
|
56
|
-
maxContextWindow?: number;
|
|
57
|
-
}
|
|
58
58
|
interface MemoryItem {
|
|
59
59
|
id: string;
|
|
60
60
|
text: string;
|
|
61
61
|
embedding?: number[];
|
|
62
62
|
timestamp: number;
|
|
63
|
-
type:
|
|
63
|
+
type: string;
|
|
64
64
|
importance: number;
|
|
65
65
|
}
|
|
66
|
-
interface Observation {
|
|
67
|
-
type: 'event' | 'state' | 'request';
|
|
68
|
-
timestamp: number;
|
|
69
|
-
agentId?: string;
|
|
70
|
-
gameId?: string;
|
|
71
|
-
content: string;
|
|
72
|
-
data?: Record<string, unknown>;
|
|
73
|
-
context?: Record<string, unknown>;
|
|
74
|
-
}
|
|
75
|
-
interface Directive {
|
|
76
|
-
type: 'system-prompt' | 'action-constraints' | 'behavior-rules' | 'thought';
|
|
77
|
-
content: string;
|
|
78
|
-
constraints?: Record<string, unknown>;
|
|
79
|
-
priority?: 'high' | 'normal' | 'low';
|
|
80
|
-
expiresAt?: number;
|
|
81
|
-
}
|
|
82
66
|
interface AgentAction {
|
|
83
67
|
type: string;
|
|
84
68
|
target?: string;
|
|
@@ -217,14 +201,6 @@ declare const createInitialState: (partial?: Partial<AgentState>) => AgentState;
|
|
|
217
201
|
* @returns A new AgentState object with the updates applied.
|
|
218
202
|
*/
|
|
219
203
|
declare const updateAgentState: (currentState: AgentState, updates: Partial<AgentState>) => AgentState;
|
|
220
|
-
/**
|
|
221
|
-
* Pure function to process input and generate response
|
|
222
|
-
* @param currentState - The current state of the agent.
|
|
223
|
-
* @param input - The input string to process.
|
|
224
|
-
* @param context - Optional context data.
|
|
225
|
-
* @returns The agent's response including dialogue and action.
|
|
226
|
-
*/
|
|
227
|
-
declare const processAgentInput: (currentState: AgentState, input: string, context?: Record<string, unknown>) => AgentResponse;
|
|
228
204
|
/**
|
|
229
205
|
* Pure function to export agent to Soul
|
|
230
206
|
* @param agentId - The ID of the agent.
|
|
@@ -249,7 +225,7 @@ declare const createAgent: (config: AgentConfig) => IAgent;
|
|
|
249
225
|
* @param memory - Optional memory instance.
|
|
250
226
|
* @returns An instantiated IAgent.
|
|
251
227
|
*/
|
|
252
|
-
declare const fromSoul: (soul: Soul, cortex: ICortex, memory?:
|
|
228
|
+
declare const fromSoul: (soul: Soul, cortex: ICortex, memory?: IMemory | null) => Promise<IAgent>;
|
|
253
229
|
|
|
254
230
|
/**
|
|
255
231
|
* Bridge configuration
|
|
@@ -309,22 +285,22 @@ declare const validateAction: (action: AgentAction, rules: readonly ValidationRu
|
|
|
309
285
|
* Soul export configuration
|
|
310
286
|
*/
|
|
311
287
|
interface SoulExportConfig {
|
|
312
|
-
/** API URL for remote upload/pinning */
|
|
313
|
-
apiUrl?: string;
|
|
314
288
|
/** Include memories in export */
|
|
315
289
|
includeMemories?: boolean;
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
|
|
290
|
+
/** Arweave wallet JWK (object or JSON string) for direct uploads */
|
|
291
|
+
walletJwk?: Record<string, unknown> | string;
|
|
292
|
+
/** Deprecated: use walletJwk */
|
|
293
|
+
privateKey?: Record<string, unknown> | string;
|
|
294
|
+
/** Bundler URL for ANS-104 data item uploads */
|
|
295
|
+
bundlerUrl?: string;
|
|
296
|
+
/** Gateway URL for read access (default: https://arweave.net) */
|
|
297
|
+
gatewayUrl?: string;
|
|
322
298
|
}
|
|
323
299
|
/**
|
|
324
300
|
* Soul export result
|
|
325
301
|
*/
|
|
326
302
|
interface SoulExportResult {
|
|
327
|
-
/** Arweave
|
|
303
|
+
/** Arweave data item ID (TXID) */
|
|
328
304
|
txId: string;
|
|
329
305
|
/** Gateway URL to access the soul. */
|
|
330
306
|
url: string;
|
|
@@ -335,9 +311,7 @@ interface SoulExportResult {
|
|
|
335
311
|
* Soul import configuration
|
|
336
312
|
*/
|
|
337
313
|
interface SoulImportConfig {
|
|
338
|
-
/**
|
|
339
|
-
apiUrl?: string;
|
|
340
|
-
/** Gateway URL for Arweave (defaults to https://gateway.irys.xyz) */
|
|
314
|
+
/** Gateway URL for Arweave (defaults to https://arweave.net) */
|
|
341
315
|
gatewayUrl?: string;
|
|
342
316
|
}
|
|
343
317
|
/**
|
|
@@ -369,13 +343,13 @@ declare const serializeSoul: (soul: Soul) => string;
|
|
|
369
343
|
*/
|
|
370
344
|
declare const deserializeSoul: (json: string) => Soul;
|
|
371
345
|
/**
|
|
372
|
-
* Pure function to upload Soul to Arweave
|
|
346
|
+
* Pure function to upload Soul to Arweave using ANS-104 data items
|
|
373
347
|
*/
|
|
374
348
|
declare const uploadToArweave: (soul: Soul, config: SoulExportConfig) => Promise<SoulExportResult>;
|
|
375
349
|
/**
|
|
376
|
-
* Export agent Soul to Arweave (
|
|
350
|
+
* Export agent Soul to Arweave (direct ANS-104 or API)
|
|
377
351
|
*/
|
|
378
|
-
declare const exportSoul: (
|
|
352
|
+
declare const exportSoul: (_agentId: string, soul: Soul, config?: SoulExportConfig) => Promise<SoulExportResult>;
|
|
379
353
|
/**
|
|
380
354
|
* Import Soul from Arweave by TXID
|
|
381
355
|
*/
|
|
@@ -397,7 +371,7 @@ declare const getSoulList: (limit?: number, apiUrl?: string) => Promise<SoulList
|
|
|
397
371
|
/**
|
|
398
372
|
* Factory function to create Soul instance
|
|
399
373
|
*/
|
|
400
|
-
declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]
|
|
374
|
+
declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]) => ISoul;
|
|
401
375
|
/**
|
|
402
376
|
* Pure function to validate a Soul object
|
|
403
377
|
*/
|
|
@@ -406,9 +380,6 @@ declare const validateSoul: (soul: Soul) => {
|
|
|
406
380
|
errors: string[];
|
|
407
381
|
};
|
|
408
382
|
|
|
409
|
-
/**
|
|
410
|
-
* Ghost test configuration
|
|
411
|
-
*/
|
|
412
383
|
/**
|
|
413
384
|
* Ghost test configuration
|
|
414
385
|
*/
|
|
@@ -424,9 +395,6 @@ interface GhostConfig {
|
|
|
424
395
|
/** Custom test parameters */
|
|
425
396
|
params?: Record<string, unknown>;
|
|
426
397
|
}
|
|
427
|
-
/**
|
|
428
|
-
* Ghost session status
|
|
429
|
-
*/
|
|
430
398
|
/**
|
|
431
399
|
* Ghost session status
|
|
432
400
|
*/
|
|
@@ -444,9 +412,6 @@ interface GhostStatus {
|
|
|
444
412
|
/** Number of errors encountered. */
|
|
445
413
|
errors: number;
|
|
446
414
|
}
|
|
447
|
-
/**
|
|
448
|
-
* Individual test result
|
|
449
|
-
*/
|
|
450
415
|
/**
|
|
451
416
|
* Individual test result
|
|
452
417
|
*/
|
|
@@ -462,9 +427,6 @@ interface GhostTestResult {
|
|
|
462
427
|
/** URL or path to a screenshot if captured. */
|
|
463
428
|
screenshot?: string;
|
|
464
429
|
}
|
|
465
|
-
/**
|
|
466
|
-
* Complete session results
|
|
467
|
-
*/
|
|
468
430
|
/**
|
|
469
431
|
* Complete session results
|
|
470
432
|
*/
|
|
@@ -488,9 +450,6 @@ interface GhostResults {
|
|
|
488
450
|
/** Additional metrics collected during the session. */
|
|
489
451
|
metrics: Record<string, number>;
|
|
490
452
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Interface for Ghost operations
|
|
493
|
-
*/
|
|
494
453
|
/**
|
|
495
454
|
* Interface for Ghost operations
|
|
496
455
|
*/
|
|
@@ -595,7 +554,7 @@ declare const createGhost: (config: GhostConfig) => IGhost;
|
|
|
595
554
|
* Creates a remote Cortex instance that proxies inference to the ForbocAI API.
|
|
596
555
|
* This is environment-agnostic as it only uses the standard fetch API.
|
|
597
556
|
*/
|
|
598
|
-
declare const createRemoteCortex: (apiUrl: string) => ICortex;
|
|
557
|
+
declare const createRemoteCortex: (apiUrl: string, cortexId?: string) => ICortex;
|
|
599
558
|
|
|
600
559
|
interface RPGAgentState extends AgentState {
|
|
601
560
|
inventory: string[];
|
|
@@ -646,6 +605,6 @@ declare namespace index {
|
|
|
646
605
|
export { type index_RPGAgentState as RPGAgentState, index_RPG_MEMORY_TYPES as RPG_MEMORY_TYPES, index_RPG_MOODS as RPG_MOODS, index_attackRule as attackRule, index_createRPGState as createRPGState, index_interactRule as interactRule, index_movementRule as movementRule, index_puzzleRules as puzzleRules, index_resourceRule as resourceRule, index_rpgRules as rpgRules, index_socialRules as socialRules, index_spatialRules as spatialRules, index_speakRule as speakRule };
|
|
647
606
|
}
|
|
648
607
|
|
|
649
|
-
declare const SDK_VERSION = "0.5.
|
|
608
|
+
declare const SDK_VERSION = "0.5.6";
|
|
650
609
|
|
|
651
|
-
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type
|
|
610
|
+
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, type PromptConstraints, type RecalledMemory, SDK_VERSION, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type ValidationContext, type ValidationResult, type ValidationRule, type VerdictRequest, type VerdictResponse, createAgent, createBridge, createGhost, createInitialState, createRemoteCortex, createSoul, createSoulInstance, deserializeSoul, exportSoul, exportToSoul, fromSoul, getGhostHistory, getGhostResults, getGhostStatus, getSoulList, importSoulFromArweave, index as presets, serializeSoul, startGhostSession, stopGhostSession, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|
package/dist/index.d.ts
CHANGED
|
@@ -30,17 +30,24 @@ interface CompletionOptions {
|
|
|
30
30
|
stop?: string[];
|
|
31
31
|
jsonSchema?: object;
|
|
32
32
|
}
|
|
33
|
-
type Mood = string;
|
|
34
33
|
interface AgentState {
|
|
35
34
|
[key: string]: unknown;
|
|
36
35
|
}
|
|
36
|
+
/** Interface for Memory module operations used by the Agent. */
|
|
37
|
+
interface IMemory {
|
|
38
|
+
store(text: string, type?: string, importance?: number): Promise<MemoryItem>;
|
|
39
|
+
recall(query: string, limit?: number, threshold?: number): Promise<MemoryItem[]>;
|
|
40
|
+
list(limit?: number, offset?: number): Promise<MemoryItem[]>;
|
|
41
|
+
clear(): Promise<void>;
|
|
42
|
+
export(): Promise<MemoryItem[]>;
|
|
43
|
+
import(memories: MemoryItem[]): Promise<void>;
|
|
44
|
+
}
|
|
37
45
|
interface AgentConfig {
|
|
38
46
|
id: string;
|
|
39
47
|
cortex: ICortex;
|
|
40
|
-
memory:
|
|
48
|
+
memory: IMemory | null;
|
|
41
49
|
persona: string;
|
|
42
50
|
initialState?: Partial<AgentState>;
|
|
43
|
-
memoryConfig?: MemoryConfig;
|
|
44
51
|
apiUrl?: string;
|
|
45
52
|
}
|
|
46
53
|
interface AgentResponse {
|
|
@@ -48,37 +55,14 @@ interface AgentResponse {
|
|
|
48
55
|
action?: AgentAction;
|
|
49
56
|
thought?: string;
|
|
50
57
|
}
|
|
51
|
-
type MemoryType = string;
|
|
52
|
-
interface MemoryConfig {
|
|
53
|
-
/** Decay strategy: 'none' | 'temporal' */
|
|
54
|
-
decay?: 'none' | 'temporal';
|
|
55
|
-
/** Max memories to keep in active context during retrieval */
|
|
56
|
-
maxContextWindow?: number;
|
|
57
|
-
}
|
|
58
58
|
interface MemoryItem {
|
|
59
59
|
id: string;
|
|
60
60
|
text: string;
|
|
61
61
|
embedding?: number[];
|
|
62
62
|
timestamp: number;
|
|
63
|
-
type:
|
|
63
|
+
type: string;
|
|
64
64
|
importance: number;
|
|
65
65
|
}
|
|
66
|
-
interface Observation {
|
|
67
|
-
type: 'event' | 'state' | 'request';
|
|
68
|
-
timestamp: number;
|
|
69
|
-
agentId?: string;
|
|
70
|
-
gameId?: string;
|
|
71
|
-
content: string;
|
|
72
|
-
data?: Record<string, unknown>;
|
|
73
|
-
context?: Record<string, unknown>;
|
|
74
|
-
}
|
|
75
|
-
interface Directive {
|
|
76
|
-
type: 'system-prompt' | 'action-constraints' | 'behavior-rules' | 'thought';
|
|
77
|
-
content: string;
|
|
78
|
-
constraints?: Record<string, unknown>;
|
|
79
|
-
priority?: 'high' | 'normal' | 'low';
|
|
80
|
-
expiresAt?: number;
|
|
81
|
-
}
|
|
82
66
|
interface AgentAction {
|
|
83
67
|
type: string;
|
|
84
68
|
target?: string;
|
|
@@ -217,14 +201,6 @@ declare const createInitialState: (partial?: Partial<AgentState>) => AgentState;
|
|
|
217
201
|
* @returns A new AgentState object with the updates applied.
|
|
218
202
|
*/
|
|
219
203
|
declare const updateAgentState: (currentState: AgentState, updates: Partial<AgentState>) => AgentState;
|
|
220
|
-
/**
|
|
221
|
-
* Pure function to process input and generate response
|
|
222
|
-
* @param currentState - The current state of the agent.
|
|
223
|
-
* @param input - The input string to process.
|
|
224
|
-
* @param context - Optional context data.
|
|
225
|
-
* @returns The agent's response including dialogue and action.
|
|
226
|
-
*/
|
|
227
|
-
declare const processAgentInput: (currentState: AgentState, input: string, context?: Record<string, unknown>) => AgentResponse;
|
|
228
204
|
/**
|
|
229
205
|
* Pure function to export agent to Soul
|
|
230
206
|
* @param agentId - The ID of the agent.
|
|
@@ -249,7 +225,7 @@ declare const createAgent: (config: AgentConfig) => IAgent;
|
|
|
249
225
|
* @param memory - Optional memory instance.
|
|
250
226
|
* @returns An instantiated IAgent.
|
|
251
227
|
*/
|
|
252
|
-
declare const fromSoul: (soul: Soul, cortex: ICortex, memory?:
|
|
228
|
+
declare const fromSoul: (soul: Soul, cortex: ICortex, memory?: IMemory | null) => Promise<IAgent>;
|
|
253
229
|
|
|
254
230
|
/**
|
|
255
231
|
* Bridge configuration
|
|
@@ -309,22 +285,22 @@ declare const validateAction: (action: AgentAction, rules: readonly ValidationRu
|
|
|
309
285
|
* Soul export configuration
|
|
310
286
|
*/
|
|
311
287
|
interface SoulExportConfig {
|
|
312
|
-
/** API URL for remote upload/pinning */
|
|
313
|
-
apiUrl?: string;
|
|
314
288
|
/** Include memories in export */
|
|
315
289
|
includeMemories?: boolean;
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
|
|
290
|
+
/** Arweave wallet JWK (object or JSON string) for direct uploads */
|
|
291
|
+
walletJwk?: Record<string, unknown> | string;
|
|
292
|
+
/** Deprecated: use walletJwk */
|
|
293
|
+
privateKey?: Record<string, unknown> | string;
|
|
294
|
+
/** Bundler URL for ANS-104 data item uploads */
|
|
295
|
+
bundlerUrl?: string;
|
|
296
|
+
/** Gateway URL for read access (default: https://arweave.net) */
|
|
297
|
+
gatewayUrl?: string;
|
|
322
298
|
}
|
|
323
299
|
/**
|
|
324
300
|
* Soul export result
|
|
325
301
|
*/
|
|
326
302
|
interface SoulExportResult {
|
|
327
|
-
/** Arweave
|
|
303
|
+
/** Arweave data item ID (TXID) */
|
|
328
304
|
txId: string;
|
|
329
305
|
/** Gateway URL to access the soul. */
|
|
330
306
|
url: string;
|
|
@@ -335,9 +311,7 @@ interface SoulExportResult {
|
|
|
335
311
|
* Soul import configuration
|
|
336
312
|
*/
|
|
337
313
|
interface SoulImportConfig {
|
|
338
|
-
/**
|
|
339
|
-
apiUrl?: string;
|
|
340
|
-
/** Gateway URL for Arweave (defaults to https://gateway.irys.xyz) */
|
|
314
|
+
/** Gateway URL for Arweave (defaults to https://arweave.net) */
|
|
341
315
|
gatewayUrl?: string;
|
|
342
316
|
}
|
|
343
317
|
/**
|
|
@@ -369,13 +343,13 @@ declare const serializeSoul: (soul: Soul) => string;
|
|
|
369
343
|
*/
|
|
370
344
|
declare const deserializeSoul: (json: string) => Soul;
|
|
371
345
|
/**
|
|
372
|
-
* Pure function to upload Soul to Arweave
|
|
346
|
+
* Pure function to upload Soul to Arweave using ANS-104 data items
|
|
373
347
|
*/
|
|
374
348
|
declare const uploadToArweave: (soul: Soul, config: SoulExportConfig) => Promise<SoulExportResult>;
|
|
375
349
|
/**
|
|
376
|
-
* Export agent Soul to Arweave (
|
|
350
|
+
* Export agent Soul to Arweave (direct ANS-104 or API)
|
|
377
351
|
*/
|
|
378
|
-
declare const exportSoul: (
|
|
352
|
+
declare const exportSoul: (_agentId: string, soul: Soul, config?: SoulExportConfig) => Promise<SoulExportResult>;
|
|
379
353
|
/**
|
|
380
354
|
* Import Soul from Arweave by TXID
|
|
381
355
|
*/
|
|
@@ -397,7 +371,7 @@ declare const getSoulList: (limit?: number, apiUrl?: string) => Promise<SoulList
|
|
|
397
371
|
/**
|
|
398
372
|
* Factory function to create Soul instance
|
|
399
373
|
*/
|
|
400
|
-
declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]
|
|
374
|
+
declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]) => ISoul;
|
|
401
375
|
/**
|
|
402
376
|
* Pure function to validate a Soul object
|
|
403
377
|
*/
|
|
@@ -406,9 +380,6 @@ declare const validateSoul: (soul: Soul) => {
|
|
|
406
380
|
errors: string[];
|
|
407
381
|
};
|
|
408
382
|
|
|
409
|
-
/**
|
|
410
|
-
* Ghost test configuration
|
|
411
|
-
*/
|
|
412
383
|
/**
|
|
413
384
|
* Ghost test configuration
|
|
414
385
|
*/
|
|
@@ -424,9 +395,6 @@ interface GhostConfig {
|
|
|
424
395
|
/** Custom test parameters */
|
|
425
396
|
params?: Record<string, unknown>;
|
|
426
397
|
}
|
|
427
|
-
/**
|
|
428
|
-
* Ghost session status
|
|
429
|
-
*/
|
|
430
398
|
/**
|
|
431
399
|
* Ghost session status
|
|
432
400
|
*/
|
|
@@ -444,9 +412,6 @@ interface GhostStatus {
|
|
|
444
412
|
/** Number of errors encountered. */
|
|
445
413
|
errors: number;
|
|
446
414
|
}
|
|
447
|
-
/**
|
|
448
|
-
* Individual test result
|
|
449
|
-
*/
|
|
450
415
|
/**
|
|
451
416
|
* Individual test result
|
|
452
417
|
*/
|
|
@@ -462,9 +427,6 @@ interface GhostTestResult {
|
|
|
462
427
|
/** URL or path to a screenshot if captured. */
|
|
463
428
|
screenshot?: string;
|
|
464
429
|
}
|
|
465
|
-
/**
|
|
466
|
-
* Complete session results
|
|
467
|
-
*/
|
|
468
430
|
/**
|
|
469
431
|
* Complete session results
|
|
470
432
|
*/
|
|
@@ -488,9 +450,6 @@ interface GhostResults {
|
|
|
488
450
|
/** Additional metrics collected during the session. */
|
|
489
451
|
metrics: Record<string, number>;
|
|
490
452
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Interface for Ghost operations
|
|
493
|
-
*/
|
|
494
453
|
/**
|
|
495
454
|
* Interface for Ghost operations
|
|
496
455
|
*/
|
|
@@ -595,7 +554,7 @@ declare const createGhost: (config: GhostConfig) => IGhost;
|
|
|
595
554
|
* Creates a remote Cortex instance that proxies inference to the ForbocAI API.
|
|
596
555
|
* This is environment-agnostic as it only uses the standard fetch API.
|
|
597
556
|
*/
|
|
598
|
-
declare const createRemoteCortex: (apiUrl: string) => ICortex;
|
|
557
|
+
declare const createRemoteCortex: (apiUrl: string, cortexId?: string) => ICortex;
|
|
599
558
|
|
|
600
559
|
interface RPGAgentState extends AgentState {
|
|
601
560
|
inventory: string[];
|
|
@@ -646,6 +605,6 @@ declare namespace index {
|
|
|
646
605
|
export { type index_RPGAgentState as RPGAgentState, index_RPG_MEMORY_TYPES as RPG_MEMORY_TYPES, index_RPG_MOODS as RPG_MOODS, index_attackRule as attackRule, index_createRPGState as createRPGState, index_interactRule as interactRule, index_movementRule as movementRule, index_puzzleRules as puzzleRules, index_resourceRule as resourceRule, index_rpgRules as rpgRules, index_socialRules as socialRules, index_spatialRules as spatialRules, index_speakRule as speakRule };
|
|
647
606
|
}
|
|
648
607
|
|
|
649
|
-
declare const SDK_VERSION = "0.5.
|
|
608
|
+
declare const SDK_VERSION = "0.5.6";
|
|
650
609
|
|
|
651
|
-
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type
|
|
610
|
+
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type DirectiveRequest, type DirectiveResponse, type GhostConfig, type GhostHistoryEntry, type GhostResults, type GhostStatus, type GhostTestResult, type IAgent, type IBridge, type ICortex, type IGhost, type IMemory, type ISoul, type MemoryItem, type MemoryRecallInstruction, type MemoryStoreInstruction, type PromptConstraints, type RecalledMemory, SDK_VERSION, type Soul, type SoulExportConfig, type SoulExportResult, type SoulImportConfig, type SoulListEntry, type ValidationContext, type ValidationResult, type ValidationRule, type VerdictRequest, type VerdictResponse, createAgent, createBridge, createGhost, createInitialState, createRemoteCortex, createSoul, createSoulInstance, deserializeSoul, exportSoul, exportToSoul, fromSoul, getGhostHistory, getGhostResults, getGhostStatus, getSoulList, importSoulFromArweave, index as presets, serializeSoul, startGhostSession, stopGhostSession, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|