@axlsdk/axl 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/README.md +253 -83
- package/dist/index.cjs +141 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -65
- package/dist/index.d.ts +69 -65
- package/dist/index.js +141 -124
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -2128,10 +2128,13 @@ function resolveConfig(config) {
|
|
|
2128
2128
|
resolved.defaultProvider = process.env.AXL_DEFAULT_PROVIDER;
|
|
2129
2129
|
}
|
|
2130
2130
|
if (process.env.AXL_STATE_STORE) {
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2131
|
+
const envStore = process.env.AXL_STATE_STORE;
|
|
2132
|
+
if (envStore === "memory" || envStore === "sqlite") {
|
|
2133
|
+
resolved.state = {
|
|
2134
|
+
...resolved.state,
|
|
2135
|
+
store: envStore
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2135
2138
|
}
|
|
2136
2139
|
if (process.env.AXL_TRACE_ENABLED !== void 0) {
|
|
2137
2140
|
resolved.trace = { ...resolved.trace, enabled: process.env.AXL_TRACE_ENABLED === "true" };
|
|
@@ -4258,122 +4261,6 @@ var SQLiteStore = class {
|
|
|
4258
4261
|
}
|
|
4259
4262
|
};
|
|
4260
4263
|
|
|
4261
|
-
// src/state/redis.ts
|
|
4262
|
-
var RedisStore = class {
|
|
4263
|
-
client;
|
|
4264
|
-
constructor(url) {
|
|
4265
|
-
let Redis;
|
|
4266
|
-
try {
|
|
4267
|
-
const mod = require("ioredis");
|
|
4268
|
-
Redis = mod.default ?? mod;
|
|
4269
|
-
} catch {
|
|
4270
|
-
throw new Error("ioredis is required for RedisStore. Install it with: npm install ioredis");
|
|
4271
|
-
}
|
|
4272
|
-
this.client = url ? new Redis(url) : new Redis();
|
|
4273
|
-
}
|
|
4274
|
-
// ── Key helpers ──────────────────────────────────────────────────────
|
|
4275
|
-
checkpointKey(executionId) {
|
|
4276
|
-
return `axl:checkpoint:${executionId}`;
|
|
4277
|
-
}
|
|
4278
|
-
sessionKey(sessionId) {
|
|
4279
|
-
return `axl:session:${sessionId}`;
|
|
4280
|
-
}
|
|
4281
|
-
sessionMetaKey(sessionId) {
|
|
4282
|
-
return `axl:session-meta:${sessionId}`;
|
|
4283
|
-
}
|
|
4284
|
-
decisionsKey() {
|
|
4285
|
-
return "axl:decisions";
|
|
4286
|
-
}
|
|
4287
|
-
executionStateKey(executionId) {
|
|
4288
|
-
return `axl:exec-state:${executionId}`;
|
|
4289
|
-
}
|
|
4290
|
-
pendingExecSetKey() {
|
|
4291
|
-
return "axl:pending-executions";
|
|
4292
|
-
}
|
|
4293
|
-
// ── Checkpoints ──────────────────────────────────────────────────────
|
|
4294
|
-
async saveCheckpoint(executionId, step, data) {
|
|
4295
|
-
await this.client.hset(this.checkpointKey(executionId), String(step), JSON.stringify(data));
|
|
4296
|
-
}
|
|
4297
|
-
async getCheckpoint(executionId, step) {
|
|
4298
|
-
const raw = await this.client.hget(this.checkpointKey(executionId), String(step));
|
|
4299
|
-
return raw !== null ? JSON.parse(raw) : null;
|
|
4300
|
-
}
|
|
4301
|
-
async getLatestCheckpoint(executionId) {
|
|
4302
|
-
const all = await this.client.hgetall(this.checkpointKey(executionId));
|
|
4303
|
-
if (!all || Object.keys(all).length === 0) return null;
|
|
4304
|
-
let maxStep = -1;
|
|
4305
|
-
let maxData = null;
|
|
4306
|
-
for (const [stepStr, raw] of Object.entries(all)) {
|
|
4307
|
-
const step = Number(stepStr);
|
|
4308
|
-
if (step > maxStep) {
|
|
4309
|
-
maxStep = step;
|
|
4310
|
-
maxData = JSON.parse(raw);
|
|
4311
|
-
}
|
|
4312
|
-
}
|
|
4313
|
-
return { step: maxStep, data: maxData };
|
|
4314
|
-
}
|
|
4315
|
-
// ── Sessions ─────────────────────────────────────────────────────────
|
|
4316
|
-
async saveSession(sessionId, history) {
|
|
4317
|
-
await this.client.set(this.sessionKey(sessionId), JSON.stringify(history));
|
|
4318
|
-
await this.client.sadd("axl:session-ids", sessionId);
|
|
4319
|
-
}
|
|
4320
|
-
async getSession(sessionId) {
|
|
4321
|
-
const raw = await this.client.get(this.sessionKey(sessionId));
|
|
4322
|
-
return raw ? JSON.parse(raw) : [];
|
|
4323
|
-
}
|
|
4324
|
-
async deleteSession(sessionId) {
|
|
4325
|
-
await this.client.del(this.sessionKey(sessionId));
|
|
4326
|
-
await this.client.del(this.sessionMetaKey(sessionId));
|
|
4327
|
-
await this.client.srem("axl:session-ids", sessionId);
|
|
4328
|
-
}
|
|
4329
|
-
async saveSessionMeta(sessionId, key, value) {
|
|
4330
|
-
await this.client.hset(this.sessionMetaKey(sessionId), key, JSON.stringify(value));
|
|
4331
|
-
}
|
|
4332
|
-
async getSessionMeta(sessionId, key) {
|
|
4333
|
-
const raw = await this.client.hget(this.sessionMetaKey(sessionId), key);
|
|
4334
|
-
return raw !== null ? JSON.parse(raw) : null;
|
|
4335
|
-
}
|
|
4336
|
-
// ── Pending Decisions ────────────────────────────────────────────────
|
|
4337
|
-
async savePendingDecision(executionId, decision) {
|
|
4338
|
-
await this.client.hset(this.decisionsKey(), executionId, JSON.stringify(decision));
|
|
4339
|
-
}
|
|
4340
|
-
async getPendingDecisions() {
|
|
4341
|
-
const all = await this.client.hgetall(this.decisionsKey());
|
|
4342
|
-
if (!all) return [];
|
|
4343
|
-
return Object.values(all).map((raw) => JSON.parse(raw));
|
|
4344
|
-
}
|
|
4345
|
-
async resolveDecision(executionId, _result) {
|
|
4346
|
-
await this.client.hdel(this.decisionsKey(), executionId);
|
|
4347
|
-
}
|
|
4348
|
-
// ── Execution State ──────────────────────────────────────────────────
|
|
4349
|
-
async saveExecutionState(executionId, state) {
|
|
4350
|
-
await this.client.set(this.executionStateKey(executionId), JSON.stringify(state));
|
|
4351
|
-
if (state.status === "waiting") {
|
|
4352
|
-
await this.client.sadd(this.pendingExecSetKey(), executionId);
|
|
4353
|
-
} else {
|
|
4354
|
-
await this.client.srem(this.pendingExecSetKey(), executionId);
|
|
4355
|
-
}
|
|
4356
|
-
}
|
|
4357
|
-
async getExecutionState(executionId) {
|
|
4358
|
-
const raw = await this.client.get(this.executionStateKey(executionId));
|
|
4359
|
-
return raw ? JSON.parse(raw) : null;
|
|
4360
|
-
}
|
|
4361
|
-
async listPendingExecutions() {
|
|
4362
|
-
return this.client.smembers(this.pendingExecSetKey());
|
|
4363
|
-
}
|
|
4364
|
-
// ── Sessions (Studio introspection) ────────────────────────────────────
|
|
4365
|
-
async listSessions() {
|
|
4366
|
-
return this.client.smembers("axl:session-ids");
|
|
4367
|
-
}
|
|
4368
|
-
/** Close the Redis connection. */
|
|
4369
|
-
async close() {
|
|
4370
|
-
await this.client.quit();
|
|
4371
|
-
}
|
|
4372
|
-
async deleteCheckpoints(executionId) {
|
|
4373
|
-
await this.client.del(this.checkpointKey(executionId));
|
|
4374
|
-
}
|
|
4375
|
-
};
|
|
4376
|
-
|
|
4377
4264
|
// src/session.ts
|
|
4378
4265
|
var Session = class _Session {
|
|
4379
4266
|
constructor(sessionId, runtime, store, options) {
|
|
@@ -5260,12 +5147,11 @@ var AxlRuntime = class extends import_node_events2.EventEmitter {
|
|
|
5260
5147
|
return this.mcpManager;
|
|
5261
5148
|
}
|
|
5262
5149
|
createStateStore() {
|
|
5263
|
-
const
|
|
5264
|
-
|
|
5150
|
+
const storeOption = this.config.state?.store ?? "memory";
|
|
5151
|
+
if (typeof storeOption !== "string") return storeOption;
|
|
5152
|
+
switch (storeOption) {
|
|
5265
5153
|
case "sqlite":
|
|
5266
5154
|
return new SQLiteStore(this.config.state?.sqlite?.path ?? "./data/axl.db");
|
|
5267
|
-
case "redis":
|
|
5268
|
-
return new RedisStore(this.config.state?.redis?.url);
|
|
5269
5155
|
case "memory":
|
|
5270
5156
|
default:
|
|
5271
5157
|
return new MemoryStore();
|
|
@@ -5896,6 +5782,137 @@ var AxlRuntime = class extends import_node_events2.EventEmitter {
|
|
|
5896
5782
|
}
|
|
5897
5783
|
};
|
|
5898
5784
|
|
|
5785
|
+
// src/state/redis.ts
|
|
5786
|
+
var RedisStore = class _RedisStore {
|
|
5787
|
+
constructor(client) {
|
|
5788
|
+
this.client = client;
|
|
5789
|
+
}
|
|
5790
|
+
/**
|
|
5791
|
+
* Create a connected RedisStore instance.
|
|
5792
|
+
*
|
|
5793
|
+
* @param url - Redis connection URL (e.g. `redis://localhost:6379`). Defaults to `redis://localhost:6379`.
|
|
5794
|
+
*/
|
|
5795
|
+
static async create(url) {
|
|
5796
|
+
let createClient;
|
|
5797
|
+
try {
|
|
5798
|
+
const mod = require("redis");
|
|
5799
|
+
createClient = mod.createClient ?? mod.default?.createClient;
|
|
5800
|
+
if (typeof createClient !== "function") {
|
|
5801
|
+
throw new Error(
|
|
5802
|
+
"redis package does not export createClient. Ensure you have redis ^5.0.0 installed: npm install redis"
|
|
5803
|
+
);
|
|
5804
|
+
}
|
|
5805
|
+
} catch (err) {
|
|
5806
|
+
if (err instanceof Error && err.message.includes("createClient")) throw err;
|
|
5807
|
+
throw new Error("redis is required for RedisStore. Install it with: npm install redis");
|
|
5808
|
+
}
|
|
5809
|
+
const client = url ? createClient({ url }) : createClient();
|
|
5810
|
+
await client.connect();
|
|
5811
|
+
return new _RedisStore(client);
|
|
5812
|
+
}
|
|
5813
|
+
// ── Key helpers ──────────────────────────────────────────────────────
|
|
5814
|
+
checkpointKey(executionId) {
|
|
5815
|
+
return `axl:checkpoint:${executionId}`;
|
|
5816
|
+
}
|
|
5817
|
+
sessionKey(sessionId) {
|
|
5818
|
+
return `axl:session:${sessionId}`;
|
|
5819
|
+
}
|
|
5820
|
+
sessionMetaKey(sessionId) {
|
|
5821
|
+
return `axl:session-meta:${sessionId}`;
|
|
5822
|
+
}
|
|
5823
|
+
decisionsKey() {
|
|
5824
|
+
return "axl:decisions";
|
|
5825
|
+
}
|
|
5826
|
+
executionStateKey(executionId) {
|
|
5827
|
+
return `axl:exec-state:${executionId}`;
|
|
5828
|
+
}
|
|
5829
|
+
pendingExecSetKey() {
|
|
5830
|
+
return "axl:pending-executions";
|
|
5831
|
+
}
|
|
5832
|
+
// ── Checkpoints ──────────────────────────────────────────────────────
|
|
5833
|
+
async saveCheckpoint(executionId, step, data) {
|
|
5834
|
+
await this.client.hSet(this.checkpointKey(executionId), String(step), JSON.stringify(data));
|
|
5835
|
+
}
|
|
5836
|
+
async getCheckpoint(executionId, step) {
|
|
5837
|
+
const raw = await this.client.hGet(this.checkpointKey(executionId), String(step));
|
|
5838
|
+
return raw != null ? JSON.parse(raw) : null;
|
|
5839
|
+
}
|
|
5840
|
+
async getLatestCheckpoint(executionId) {
|
|
5841
|
+
const all = await this.client.hGetAll(this.checkpointKey(executionId));
|
|
5842
|
+
if (!all || Object.keys(all).length === 0) return null;
|
|
5843
|
+
let maxStep = -1;
|
|
5844
|
+
let maxData = null;
|
|
5845
|
+
for (const [stepStr, raw] of Object.entries(all)) {
|
|
5846
|
+
const step = Number(stepStr);
|
|
5847
|
+
if (step > maxStep) {
|
|
5848
|
+
maxStep = step;
|
|
5849
|
+
maxData = JSON.parse(raw);
|
|
5850
|
+
}
|
|
5851
|
+
}
|
|
5852
|
+
return { step: maxStep, data: maxData };
|
|
5853
|
+
}
|
|
5854
|
+
// ── Sessions ─────────────────────────────────────────────────────────
|
|
5855
|
+
async saveSession(sessionId, history) {
|
|
5856
|
+
await this.client.set(this.sessionKey(sessionId), JSON.stringify(history));
|
|
5857
|
+
await this.client.sAdd("axl:session-ids", sessionId);
|
|
5858
|
+
}
|
|
5859
|
+
async getSession(sessionId) {
|
|
5860
|
+
const raw = await this.client.get(this.sessionKey(sessionId));
|
|
5861
|
+
return raw ? JSON.parse(raw) : [];
|
|
5862
|
+
}
|
|
5863
|
+
async deleteSession(sessionId) {
|
|
5864
|
+
await this.client.del(this.sessionKey(sessionId));
|
|
5865
|
+
await this.client.del(this.sessionMetaKey(sessionId));
|
|
5866
|
+
await this.client.sRem("axl:session-ids", sessionId);
|
|
5867
|
+
}
|
|
5868
|
+
async saveSessionMeta(sessionId, key, value) {
|
|
5869
|
+
await this.client.hSet(this.sessionMetaKey(sessionId), key, JSON.stringify(value));
|
|
5870
|
+
}
|
|
5871
|
+
async getSessionMeta(sessionId, key) {
|
|
5872
|
+
const raw = await this.client.hGet(this.sessionMetaKey(sessionId), key);
|
|
5873
|
+
return raw != null ? JSON.parse(raw) : null;
|
|
5874
|
+
}
|
|
5875
|
+
// ── Pending Decisions ────────────────────────────────────────────────
|
|
5876
|
+
async savePendingDecision(executionId, decision) {
|
|
5877
|
+
await this.client.hSet(this.decisionsKey(), executionId, JSON.stringify(decision));
|
|
5878
|
+
}
|
|
5879
|
+
async getPendingDecisions() {
|
|
5880
|
+
const all = await this.client.hGetAll(this.decisionsKey());
|
|
5881
|
+
if (!all) return [];
|
|
5882
|
+
return Object.values(all).map((raw) => JSON.parse(raw));
|
|
5883
|
+
}
|
|
5884
|
+
async resolveDecision(executionId, _result) {
|
|
5885
|
+
await this.client.hDel(this.decisionsKey(), executionId);
|
|
5886
|
+
}
|
|
5887
|
+
// ── Execution State ──────────────────────────────────────────────────
|
|
5888
|
+
async saveExecutionState(executionId, state) {
|
|
5889
|
+
await this.client.set(this.executionStateKey(executionId), JSON.stringify(state));
|
|
5890
|
+
if (state.status === "waiting") {
|
|
5891
|
+
await this.client.sAdd(this.pendingExecSetKey(), executionId);
|
|
5892
|
+
} else {
|
|
5893
|
+
await this.client.sRem(this.pendingExecSetKey(), executionId);
|
|
5894
|
+
}
|
|
5895
|
+
}
|
|
5896
|
+
async getExecutionState(executionId) {
|
|
5897
|
+
const raw = await this.client.get(this.executionStateKey(executionId));
|
|
5898
|
+
return raw ? JSON.parse(raw) : null;
|
|
5899
|
+
}
|
|
5900
|
+
async listPendingExecutions() {
|
|
5901
|
+
return this.client.sMembers(this.pendingExecSetKey());
|
|
5902
|
+
}
|
|
5903
|
+
// ── Sessions (Studio introspection) ────────────────────────────────────
|
|
5904
|
+
async listSessions() {
|
|
5905
|
+
return this.client.sMembers("axl:session-ids");
|
|
5906
|
+
}
|
|
5907
|
+
/** Close the Redis connection. */
|
|
5908
|
+
async close() {
|
|
5909
|
+
await this.client.quit();
|
|
5910
|
+
}
|
|
5911
|
+
async deleteCheckpoints(executionId) {
|
|
5912
|
+
await this.client.del(this.checkpointKey(executionId));
|
|
5913
|
+
}
|
|
5914
|
+
};
|
|
5915
|
+
|
|
5899
5916
|
// src/memory/embedder-openai.ts
|
|
5900
5917
|
var OpenAIEmbedder = class {
|
|
5901
5918
|
apiKey;
|