@forbocai/core 0.5.4 → 0.5.7
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 +96 -70
- package/dist/index.d.ts +96 -70
- package/dist/index.js +383 -89
- package/dist/index.mjs +149 -93
- 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,55 +30,40 @@ 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;
|
|
52
|
+
apiKey?: string;
|
|
45
53
|
}
|
|
46
54
|
interface AgentResponse {
|
|
47
55
|
dialogue: string;
|
|
48
56
|
action?: AgentAction;
|
|
49
57
|
thought?: string;
|
|
50
58
|
}
|
|
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
59
|
interface MemoryItem {
|
|
59
60
|
id: string;
|
|
60
61
|
text: string;
|
|
61
62
|
embedding?: number[];
|
|
62
63
|
timestamp: number;
|
|
63
|
-
type:
|
|
64
|
+
type: string;
|
|
64
65
|
importance: number;
|
|
65
66
|
}
|
|
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
67
|
interface AgentAction {
|
|
83
68
|
type: string;
|
|
84
69
|
target?: string;
|
|
@@ -116,6 +101,20 @@ interface RecalledMemory {
|
|
|
116
101
|
importance: number;
|
|
117
102
|
similarity?: number;
|
|
118
103
|
}
|
|
104
|
+
/** Speak Request (Simple Dialogue) */
|
|
105
|
+
interface SpeakRequest {
|
|
106
|
+
speakMessage: string;
|
|
107
|
+
speakContext?: Record<string, unknown>;
|
|
108
|
+
speakAgentState: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
/** Speak Response (Simple Dialogue) */
|
|
111
|
+
interface SpeakResponse {
|
|
112
|
+
speakReply: string;
|
|
113
|
+
speakHistory: Array<{
|
|
114
|
+
role: string;
|
|
115
|
+
content: string;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
119
118
|
/** Step 5: API → SDK. API returns full SLM prompt + constraints. */
|
|
120
119
|
interface ContextResponse {
|
|
121
120
|
prompt: string;
|
|
@@ -187,6 +186,17 @@ interface IAgent {
|
|
|
187
186
|
* @returns A promise that resolves to the agent's response.
|
|
188
187
|
*/
|
|
189
188
|
process(input: string, context?: Record<string, unknown>): Promise<AgentResponse>;
|
|
189
|
+
/**
|
|
190
|
+
* Generates a conversational response (bypassing the multi-round ruleset evaluation).
|
|
191
|
+
* @param message - The input message.
|
|
192
|
+
* @param context - Optional context overrides.
|
|
193
|
+
* @returns A promise resolving to the agent's textual reply.
|
|
194
|
+
*/
|
|
195
|
+
speak(message: string, context?: Record<string, unknown>): Promise<string>;
|
|
196
|
+
/**
|
|
197
|
+
* Alias for `speak()`.
|
|
198
|
+
*/
|
|
199
|
+
reply(message: string, context?: Record<string, unknown>): Promise<string>;
|
|
190
200
|
/**
|
|
191
201
|
* Retrieves the current state of the agent.
|
|
192
202
|
* @returns The current AgentState.
|
|
@@ -217,14 +227,6 @@ declare const createInitialState: (partial?: Partial<AgentState>) => AgentState;
|
|
|
217
227
|
* @returns A new AgentState object with the updates applied.
|
|
218
228
|
*/
|
|
219
229
|
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
230
|
/**
|
|
229
231
|
* Pure function to export agent to Soul
|
|
230
232
|
* @param agentId - The ID of the agent.
|
|
@@ -249,7 +251,7 @@ declare const createAgent: (config: AgentConfig) => IAgent;
|
|
|
249
251
|
* @param memory - Optional memory instance.
|
|
250
252
|
* @returns An instantiated IAgent.
|
|
251
253
|
*/
|
|
252
|
-
declare const fromSoul: (soul: Soul, cortex: ICortex, memory?:
|
|
254
|
+
declare const fromSoul: (soul: Soul, cortex: ICortex, memory?: IMemory | null) => Promise<IAgent>;
|
|
253
255
|
|
|
254
256
|
/**
|
|
255
257
|
* Bridge configuration
|
|
@@ -309,22 +311,22 @@ declare const validateAction: (action: AgentAction, rules: readonly ValidationRu
|
|
|
309
311
|
* Soul export configuration
|
|
310
312
|
*/
|
|
311
313
|
interface SoulExportConfig {
|
|
312
|
-
/** API URL for remote upload/pinning */
|
|
313
|
-
apiUrl?: string;
|
|
314
314
|
/** Include memories in export */
|
|
315
315
|
includeMemories?: boolean;
|
|
316
|
-
/**
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
|
|
316
|
+
/** Arweave wallet JWK (object or JSON string) for direct uploads */
|
|
317
|
+
walletJwk?: Record<string, unknown> | string;
|
|
318
|
+
/** Deprecated: use walletJwk */
|
|
319
|
+
privateKey?: Record<string, unknown> | string;
|
|
320
|
+
/** Bundler URL for ANS-104 data item uploads */
|
|
321
|
+
bundlerUrl?: string;
|
|
322
|
+
/** Gateway URL for read access (default: https://arweave.net) */
|
|
323
|
+
gatewayUrl?: string;
|
|
322
324
|
}
|
|
323
325
|
/**
|
|
324
326
|
* Soul export result
|
|
325
327
|
*/
|
|
326
328
|
interface SoulExportResult {
|
|
327
|
-
/** Arweave
|
|
329
|
+
/** Arweave data item ID (TXID) */
|
|
328
330
|
txId: string;
|
|
329
331
|
/** Gateway URL to access the soul. */
|
|
330
332
|
url: string;
|
|
@@ -335,9 +337,7 @@ interface SoulExportResult {
|
|
|
335
337
|
* Soul import configuration
|
|
336
338
|
*/
|
|
337
339
|
interface SoulImportConfig {
|
|
338
|
-
/**
|
|
339
|
-
apiUrl?: string;
|
|
340
|
-
/** Gateway URL for Arweave (defaults to https://gateway.irys.xyz) */
|
|
340
|
+
/** Gateway URL for Arweave (defaults to https://arweave.net) */
|
|
341
341
|
gatewayUrl?: string;
|
|
342
342
|
}
|
|
343
343
|
/**
|
|
@@ -369,13 +369,13 @@ declare const serializeSoul: (soul: Soul) => string;
|
|
|
369
369
|
*/
|
|
370
370
|
declare const deserializeSoul: (json: string) => Soul;
|
|
371
371
|
/**
|
|
372
|
-
* Pure function to upload Soul to Arweave
|
|
372
|
+
* Pure function to upload Soul to Arweave using ANS-104 data items
|
|
373
373
|
*/
|
|
374
374
|
declare const uploadToArweave: (soul: Soul, config: SoulExportConfig) => Promise<SoulExportResult>;
|
|
375
375
|
/**
|
|
376
|
-
* Export agent Soul to Arweave (
|
|
376
|
+
* Export agent Soul to Arweave (direct ANS-104 or API)
|
|
377
377
|
*/
|
|
378
|
-
declare const exportSoul: (
|
|
378
|
+
declare const exportSoul: (_agentId: string, soul: Soul, config?: SoulExportConfig) => Promise<SoulExportResult>;
|
|
379
379
|
/**
|
|
380
380
|
* Import Soul from Arweave by TXID
|
|
381
381
|
*/
|
|
@@ -397,7 +397,7 @@ declare const getSoulList: (limit?: number, apiUrl?: string) => Promise<SoulList
|
|
|
397
397
|
/**
|
|
398
398
|
* Factory function to create Soul instance
|
|
399
399
|
*/
|
|
400
|
-
declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]
|
|
400
|
+
declare const createSoulInstance: (id: string, name: string, persona: string, state: AgentState, memories?: MemoryItem[]) => ISoul;
|
|
401
401
|
/**
|
|
402
402
|
* Pure function to validate a Soul object
|
|
403
403
|
*/
|
|
@@ -406,9 +406,6 @@ declare const validateSoul: (soul: Soul) => {
|
|
|
406
406
|
errors: string[];
|
|
407
407
|
};
|
|
408
408
|
|
|
409
|
-
/**
|
|
410
|
-
* Ghost test configuration
|
|
411
|
-
*/
|
|
412
409
|
/**
|
|
413
410
|
* Ghost test configuration
|
|
414
411
|
*/
|
|
@@ -424,9 +421,6 @@ interface GhostConfig {
|
|
|
424
421
|
/** Custom test parameters */
|
|
425
422
|
params?: Record<string, unknown>;
|
|
426
423
|
}
|
|
427
|
-
/**
|
|
428
|
-
* Ghost session status
|
|
429
|
-
*/
|
|
430
424
|
/**
|
|
431
425
|
* Ghost session status
|
|
432
426
|
*/
|
|
@@ -444,9 +438,6 @@ interface GhostStatus {
|
|
|
444
438
|
/** Number of errors encountered. */
|
|
445
439
|
errors: number;
|
|
446
440
|
}
|
|
447
|
-
/**
|
|
448
|
-
* Individual test result
|
|
449
|
-
*/
|
|
450
441
|
/**
|
|
451
442
|
* Individual test result
|
|
452
443
|
*/
|
|
@@ -462,9 +453,6 @@ interface GhostTestResult {
|
|
|
462
453
|
/** URL or path to a screenshot if captured. */
|
|
463
454
|
screenshot?: string;
|
|
464
455
|
}
|
|
465
|
-
/**
|
|
466
|
-
* Complete session results
|
|
467
|
-
*/
|
|
468
456
|
/**
|
|
469
457
|
* Complete session results
|
|
470
458
|
*/
|
|
@@ -488,9 +476,6 @@ interface GhostResults {
|
|
|
488
476
|
/** Additional metrics collected during the session. */
|
|
489
477
|
metrics: Record<string, number>;
|
|
490
478
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Interface for Ghost operations
|
|
493
|
-
*/
|
|
494
479
|
/**
|
|
495
480
|
* Interface for Ghost operations
|
|
496
481
|
*/
|
|
@@ -595,7 +580,48 @@ declare const createGhost: (config: GhostConfig) => IGhost;
|
|
|
595
580
|
* Creates a remote Cortex instance that proxies inference to the ForbocAI API.
|
|
596
581
|
* This is environment-agnostic as it only uses the standard fetch API.
|
|
597
582
|
*/
|
|
598
|
-
declare const createRemoteCortex: (apiUrl: string) => ICortex;
|
|
583
|
+
declare const createRemoteCortex: (apiUrl: string, cortexId?: string, apiKey?: string) => ICortex;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Consume an async token stream, calling `onChunk` for each token.
|
|
587
|
+
* Useful for rendering typewriter effects in UI.
|
|
588
|
+
*/
|
|
589
|
+
declare function streamToCallback(stream: AsyncGenerator<string, void, unknown>, onChunk: (chunk: string) => void): Promise<void>;
|
|
590
|
+
/**
|
|
591
|
+
* Consume an async token stream and return the full accumulated string.
|
|
592
|
+
*/
|
|
593
|
+
declare function streamToString(stream: AsyncGenerator<string, void, unknown>): Promise<string>;
|
|
594
|
+
/**
|
|
595
|
+
* Stream tokens from a cortex directly to a callback.
|
|
596
|
+
* Convenience wrapper combining cortex.completeStream + streamToCallback.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* // Typewriter effect in a React component:
|
|
600
|
+
* await streamFromCortex(cortex, prompt, (token) => {
|
|
601
|
+
* setDisplayText(prev => prev + token);
|
|
602
|
+
* });
|
|
603
|
+
*/
|
|
604
|
+
declare function streamFromCortex(cortex: ICortex, prompt: string, onChunk: (chunk: string) => void, options?: {
|
|
605
|
+
temperature?: number;
|
|
606
|
+
maxTokens?: number;
|
|
607
|
+
stop?: string[];
|
|
608
|
+
}): Promise<string>;
|
|
609
|
+
/**
|
|
610
|
+
* Stream tokens from a cortex with a delay between tokens (for typewriter pacing).
|
|
611
|
+
*
|
|
612
|
+
* @param delayMs - Milliseconds to wait between tokens (default: 30ms)
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* await streamFromCortexWithDelay(cortex, prompt, (token) => {
|
|
616
|
+
* setDisplayText(prev => prev + token);
|
|
617
|
+
* }, { delayMs: 25 });
|
|
618
|
+
*/
|
|
619
|
+
declare function streamFromCortexWithDelay(cortex: ICortex, prompt: string, onChunk: (chunk: string) => void, options?: {
|
|
620
|
+
temperature?: number;
|
|
621
|
+
maxTokens?: number;
|
|
622
|
+
stop?: string[];
|
|
623
|
+
delayMs?: number;
|
|
624
|
+
}): Promise<string>;
|
|
599
625
|
|
|
600
626
|
interface RPGAgentState extends AgentState {
|
|
601
627
|
inventory: string[];
|
|
@@ -646,6 +672,6 @@ declare namespace index {
|
|
|
646
672
|
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
673
|
}
|
|
648
674
|
|
|
649
|
-
declare const SDK_VERSION = "0.5.
|
|
675
|
+
declare const SDK_VERSION = "0.5.7";
|
|
650
676
|
|
|
651
|
-
export { type AgentAction, type AgentConfig, type AgentResponse, type AgentState, type BridgeConfig, type CompletionOptions, type ContextRequest, type ContextResponse, type CortexConfig, type CortexStatus, type
|
|
677
|
+
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 SpeakRequest, type SpeakResponse, 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, streamFromCortex, streamFromCortexWithDelay, streamToCallback, streamToString, updateAgentState, uploadToArweave, validateAction, validateSoul, waitForGhostCompletion };
|