engine7 7.1.21 → 7.1.23

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.
@@ -11876,6 +11876,74 @@ ${lines.join("\n\n")}`;
11876
11876
  }
11877
11877
  });
11878
11878
 
11879
+ // src/memory/everos-sync.ts
11880
+ var everos_sync_exports = {};
11881
+ __export(everos_sync_exports, {
11882
+ createEverosSync: () => createEverosSync
11883
+ });
11884
+ function createEverosSync(cfg) {
11885
+ const { enabled, url, appId, userId } = cfg;
11886
+ async function push(event) {
11887
+ if (!enabled) return;
11888
+ if (!event.text.trim()) return;
11889
+ try {
11890
+ const resp = await fetch(`${url}/api/v1/memory/add`, {
11891
+ method: "POST",
11892
+ headers: { "Content-Type": "application/json" },
11893
+ body: JSON.stringify({
11894
+ session_id: event.sessionId,
11895
+ app_id: appId,
11896
+ project_id: "default",
11897
+ messages: [{
11898
+ sender_id: event.role === "user" ? "user" : appId,
11899
+ sender_name: event.senderName || event.role,
11900
+ role: event.role,
11901
+ timestamp: event.timestamp,
11902
+ content: event.text
11903
+ }]
11904
+ }),
11905
+ signal: AbortSignal.timeout(5e3)
11906
+ });
11907
+ if (!resp.ok) {
11908
+ console.warn(`[everos-sync] memory/add ${resp.status}`);
11909
+ }
11910
+ } catch {
11911
+ }
11912
+ }
11913
+ async function pushBatch(events) {
11914
+ if (!enabled || events.length === 0) return;
11915
+ try {
11916
+ const resp = await fetch(`${url}/api/v1/memory/add`, {
11917
+ method: "POST",
11918
+ headers: { "Content-Type": "application/json" },
11919
+ body: JSON.stringify({
11920
+ session_id: events[0].sessionId,
11921
+ app_id: appId,
11922
+ project_id: "default",
11923
+ messages: events.map((e) => ({
11924
+ sender_id: e.role === "user" ? "user" : appId,
11925
+ sender_name: e.senderName || e.role,
11926
+ role: e.role,
11927
+ timestamp: e.timestamp,
11928
+ content: e.text
11929
+ }))
11930
+ }),
11931
+ signal: AbortSignal.timeout(3e4)
11932
+ });
11933
+ if (!resp.ok) {
11934
+ console.warn(`[everos-sync] batch add ${resp.status}`);
11935
+ }
11936
+ } catch {
11937
+ }
11938
+ }
11939
+ return { push, pushBatch };
11940
+ }
11941
+ var init_everos_sync = __esm({
11942
+ "src/memory/everos-sync.ts"() {
11943
+ "use strict";
11944
+ }
11945
+ });
11946
+
11879
11947
  // src/cron/cron-plugin.ts
11880
11948
  var cron_plugin_exports = {};
11881
11949
  __export(cron_plugin_exports, {
@@ -16365,6 +16433,8 @@ var SessionWriter = class {
16365
16433
  lastId = null;
16366
16434
  stream = null;
16367
16435
  lineCount = 0;
16436
+ /** 消息写入 hook(由外部注入,如 EverOS sync) */
16437
+ onMessageWritten = null;
16368
16438
  /**
16369
16439
  * @param sessionsDir sessions 目录
16370
16440
  * @param sessionId 可选,传入则续写已有文件;不传则新建
@@ -16762,6 +16832,19 @@ var SessionWriter = class {
16762
16832
  const lineId = obj.id || obj.uuid;
16763
16833
  if (lineId) this.lastId = lineId;
16764
16834
  this.stream.write(JSON.stringify(obj) + "\n");
16835
+ if (obj.type === "message" && this.onMessageWritten && obj.message?.role && obj.message?.content) {
16836
+ const role = obj.message.role;
16837
+ let text = "";
16838
+ const content = obj.message.content;
16839
+ if (typeof content === "string") {
16840
+ text = content;
16841
+ } else if (Array.isArray(content)) {
16842
+ text = content.filter((b2) => b2.type === "text" && b2.text).map((b2) => b2.text).join("\n");
16843
+ }
16844
+ if (text.trim()) {
16845
+ this.onMessageWritten({ role, text, timestamp: obj.timestamp || (/* @__PURE__ */ new Date()).toISOString() });
16846
+ }
16847
+ }
16765
16848
  }
16766
16849
  };
16767
16850
  function cleanupArchivedSessionTranscripts(sessionsDir, olderThanMs = 30 * 24 * 60 * 60 * 1e3) {
@@ -17205,6 +17288,8 @@ var SessionManager = class {
17205
17288
  sessionsDir;
17206
17289
  indexPath;
17207
17290
  platformMapPath;
17291
+ /** 外部 hook:每次创建新 writer 时回调(如 EverOS sync 注入 onMessageWritten) */
17292
+ onWriterCreated = null;
17208
17293
  histories = /* @__PURE__ */ new Map();
17209
17294
  restoredRecallPaths = /* @__PURE__ */ new Map();
17210
17295
  writers = /* @__PURE__ */ new Map();
@@ -17319,6 +17404,7 @@ var SessionManager = class {
17319
17404
  this.index.set(sessionId, { file: writer.path, updatedAt: Date.now() });
17320
17405
  this.saveIndex();
17321
17406
  this.writers.set(sessionId, writer);
17407
+ this.onWriterCreated?.(writer, sessionId);
17322
17408
  console.log(`[session] ${existing ? "Resumed" : "New"}: ${sessionId} \u2192 ${path7.basename(writer.path)}`);
17323
17409
  }
17324
17410
  return writer;
@@ -17966,22 +18052,7 @@ ${skillsListing}`);
17966
18052
  parts.push(getEnvInfoSection(options.workspace));
17967
18053
  const now = /* @__PURE__ */ new Date();
17968
18054
  const dateStr = now.toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" });
17969
- const platformLabel = options.platform || "unknown";
17970
- const contextParts = [`\u5F53\u524D\u65F6\u95F4: ${dateStr}`, `\u5E73\u53F0: ${platformLabel}`];
17971
- const meta = options.inboundMeta;
17972
- if (meta) {
17973
- contextParts.push(`\u6765\u6E90: ${meta.channel}`);
17974
- if (meta.channelType) contextParts.push(`\u6D88\u606F\u7C7B\u578B: ${meta.channelType === "dm" ? "\u79C1\u4FE1" : "\u7FA4\u804A"}`);
17975
- if (meta.channel_id) contextParts.push(`\u9891\u9053ID: ${meta.channel_id}`);
17976
- contextParts.push(`\u53D1\u9001\u8005ID: ${meta.from}`);
17977
- if (meta.fromName) contextParts.push(`\u53D1\u9001\u8005\u540D\u79F0: ${meta.fromName}`);
17978
- if (meta.messageId) contextParts.push(`\u6D88\u606FID: ${meta.messageId}`);
17979
- } else if (options.channel) {
17980
- contextParts.push(`\u6765\u6E90: ${options.channel}`);
17981
- }
17982
- if (options.sessionId) contextParts.push(`\u4F1A\u8BDDID: ${options.sessionId}`);
17983
- parts.push(`# \u8FD0\u884C\u65F6\u4E0A\u4E0B\u6587
17984
- ${contextParts.join("\n")}`);
18055
+ parts.push(`\u5F53\u524D\u65F6\u95F4: ${dateStr}`);
17985
18056
  console.log(`[dynamic-prompt] Loaded: ${loaded2.length > 0 ? loaded2.join(", ") : "(none)"}`);
17986
18057
  return parts.join("\n\n");
17987
18058
  }
@@ -27472,6 +27543,28 @@ ${content}`
27472
27543
  sessions.migrateOldSessions();
27473
27544
  sessions.startIdleCleanup();
27474
27545
  cleanupArchivedSessionTranscripts(sessions.sessionsDir);
27546
+ const everosCfg = config.everos;
27547
+ if (everosCfg?.enabled) {
27548
+ const { createEverosSync: createEverosSync2 } = await Promise.resolve().then(() => (init_everos_sync(), everos_sync_exports));
27549
+ const everosSync = createEverosSync2({
27550
+ enabled: true,
27551
+ url: everosCfg.everosUrl || "http://127.0.0.1:8100",
27552
+ appId: everosCfg.userId || "default",
27553
+ userId: everosCfg.userId || "default"
27554
+ });
27555
+ sessions.onWriterCreated = (writer, sessionId) => {
27556
+ writer.onMessageWritten = (msg2) => {
27557
+ everosSync.push({
27558
+ sessionId: writer.engineSessionId || sessionId,
27559
+ role: msg2.role === "toolResult" ? "tool" : msg2.role,
27560
+ text: msg2.text,
27561
+ timestamp: new Date(msg2.timestamp).getTime()
27562
+ }).catch(() => {
27563
+ });
27564
+ };
27565
+ };
27566
+ console.log(`[everos-sync] hook registered (appId=${everosCfg.userId})`);
27567
+ }
27475
27568
  const channelManager = new ChannelManager();
27476
27569
  const memoryRecallProvider = createMemorySideProvider(
27477
27570
  config.topics?.recall,
package/dist/main.mjs CHANGED
@@ -12231,6 +12231,74 @@ ${lines.join("\n\n")}`;
12231
12231
  }
12232
12232
  });
12233
12233
 
12234
+ // src/memory/everos-sync.ts
12235
+ var everos_sync_exports = {};
12236
+ __export(everos_sync_exports, {
12237
+ createEverosSync: () => createEverosSync
12238
+ });
12239
+ function createEverosSync(cfg) {
12240
+ const { enabled, url, appId, userId } = cfg;
12241
+ async function push(event) {
12242
+ if (!enabled) return;
12243
+ if (!event.text.trim()) return;
12244
+ try {
12245
+ const resp = await fetch(`${url}/api/v1/memory/add`, {
12246
+ method: "POST",
12247
+ headers: { "Content-Type": "application/json" },
12248
+ body: JSON.stringify({
12249
+ session_id: event.sessionId,
12250
+ app_id: appId,
12251
+ project_id: "default",
12252
+ messages: [{
12253
+ sender_id: event.role === "user" ? "user" : appId,
12254
+ sender_name: event.senderName || event.role,
12255
+ role: event.role,
12256
+ timestamp: event.timestamp,
12257
+ content: event.text
12258
+ }]
12259
+ }),
12260
+ signal: AbortSignal.timeout(5e3)
12261
+ });
12262
+ if (!resp.ok) {
12263
+ console.warn(`[everos-sync] memory/add ${resp.status}`);
12264
+ }
12265
+ } catch {
12266
+ }
12267
+ }
12268
+ async function pushBatch(events) {
12269
+ if (!enabled || events.length === 0) return;
12270
+ try {
12271
+ const resp = await fetch(`${url}/api/v1/memory/add`, {
12272
+ method: "POST",
12273
+ headers: { "Content-Type": "application/json" },
12274
+ body: JSON.stringify({
12275
+ session_id: events[0].sessionId,
12276
+ app_id: appId,
12277
+ project_id: "default",
12278
+ messages: events.map((e) => ({
12279
+ sender_id: e.role === "user" ? "user" : appId,
12280
+ sender_name: e.senderName || e.role,
12281
+ role: e.role,
12282
+ timestamp: e.timestamp,
12283
+ content: e.text
12284
+ }))
12285
+ }),
12286
+ signal: AbortSignal.timeout(3e4)
12287
+ });
12288
+ if (!resp.ok) {
12289
+ console.warn(`[everos-sync] batch add ${resp.status}`);
12290
+ }
12291
+ } catch {
12292
+ }
12293
+ }
12294
+ return { push, pushBatch };
12295
+ }
12296
+ var init_everos_sync = __esm({
12297
+ "src/memory/everos-sync.ts"() {
12298
+ "use strict";
12299
+ }
12300
+ });
12301
+
12234
12302
  // src/cron/cron-plugin.ts
12235
12303
  var cron_plugin_exports = {};
12236
12304
  __export(cron_plugin_exports, {
@@ -16723,6 +16791,8 @@ var SessionWriter = class {
16723
16791
  lastId = null;
16724
16792
  stream = null;
16725
16793
  lineCount = 0;
16794
+ /** 消息写入 hook(由外部注入,如 EverOS sync) */
16795
+ onMessageWritten = null;
16726
16796
  /**
16727
16797
  * @param sessionsDir sessions 目录
16728
16798
  * @param sessionId 可选,传入则续写已有文件;不传则新建
@@ -17120,6 +17190,19 @@ var SessionWriter = class {
17120
17190
  const lineId = obj.id || obj.uuid;
17121
17191
  if (lineId) this.lastId = lineId;
17122
17192
  this.stream.write(JSON.stringify(obj) + "\n");
17193
+ if (obj.type === "message" && this.onMessageWritten && obj.message?.role && obj.message?.content) {
17194
+ const role = obj.message.role;
17195
+ let text = "";
17196
+ const content = obj.message.content;
17197
+ if (typeof content === "string") {
17198
+ text = content;
17199
+ } else if (Array.isArray(content)) {
17200
+ text = content.filter((b2) => b2.type === "text" && b2.text).map((b2) => b2.text).join("\n");
17201
+ }
17202
+ if (text.trim()) {
17203
+ this.onMessageWritten({ role, text, timestamp: obj.timestamp || (/* @__PURE__ */ new Date()).toISOString() });
17204
+ }
17205
+ }
17123
17206
  }
17124
17207
  };
17125
17208
  function cleanupArchivedSessionTranscripts(sessionsDir, olderThanMs = 30 * 24 * 60 * 60 * 1e3) {
@@ -17563,6 +17646,8 @@ var SessionManager = class {
17563
17646
  sessionsDir;
17564
17647
  indexPath;
17565
17648
  platformMapPath;
17649
+ /** 外部 hook:每次创建新 writer 时回调(如 EverOS sync 注入 onMessageWritten) */
17650
+ onWriterCreated = null;
17566
17651
  histories = /* @__PURE__ */ new Map();
17567
17652
  restoredRecallPaths = /* @__PURE__ */ new Map();
17568
17653
  writers = /* @__PURE__ */ new Map();
@@ -17677,6 +17762,7 @@ var SessionManager = class {
17677
17762
  this.index.set(sessionId, { file: writer.path, updatedAt: Date.now() });
17678
17763
  this.saveIndex();
17679
17764
  this.writers.set(sessionId, writer);
17765
+ this.onWriterCreated?.(writer, sessionId);
17680
17766
  console.log(`[session] ${existing ? "Resumed" : "New"}: ${sessionId} \u2192 ${path7.basename(writer.path)}`);
17681
17767
  }
17682
17768
  return writer;
@@ -18324,22 +18410,7 @@ ${skillsListing}`);
18324
18410
  parts.push(getEnvInfoSection(options.workspace));
18325
18411
  const now = /* @__PURE__ */ new Date();
18326
18412
  const dateStr = now.toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" });
18327
- const platformLabel = options.platform || "unknown";
18328
- const contextParts = [`\u5F53\u524D\u65F6\u95F4: ${dateStr}`, `\u5E73\u53F0: ${platformLabel}`];
18329
- const meta = options.inboundMeta;
18330
- if (meta) {
18331
- contextParts.push(`\u6765\u6E90: ${meta.channel}`);
18332
- if (meta.channelType) contextParts.push(`\u6D88\u606F\u7C7B\u578B: ${meta.channelType === "dm" ? "\u79C1\u4FE1" : "\u7FA4\u804A"}`);
18333
- if (meta.channel_id) contextParts.push(`\u9891\u9053ID: ${meta.channel_id}`);
18334
- contextParts.push(`\u53D1\u9001\u8005ID: ${meta.from}`);
18335
- if (meta.fromName) contextParts.push(`\u53D1\u9001\u8005\u540D\u79F0: ${meta.fromName}`);
18336
- if (meta.messageId) contextParts.push(`\u6D88\u606FID: ${meta.messageId}`);
18337
- } else if (options.channel) {
18338
- contextParts.push(`\u6765\u6E90: ${options.channel}`);
18339
- }
18340
- if (options.sessionId) contextParts.push(`\u4F1A\u8BDDID: ${options.sessionId}`);
18341
- parts.push(`# \u8FD0\u884C\u65F6\u4E0A\u4E0B\u6587
18342
- ${contextParts.join("\n")}`);
18413
+ parts.push(`\u5F53\u524D\u65F6\u95F4: ${dateStr}`);
18343
18414
  console.log(`[dynamic-prompt] Loaded: ${loaded2.length > 0 ? loaded2.join(", ") : "(none)"}`);
18344
18415
  return parts.join("\n\n");
18345
18416
  }
@@ -27538,6 +27609,28 @@ ${content}`
27538
27609
  sessions.migrateOldSessions();
27539
27610
  sessions.startIdleCleanup();
27540
27611
  cleanupArchivedSessionTranscripts(sessions.sessionsDir);
27612
+ const everosCfg = config2.everos;
27613
+ if (everosCfg?.enabled) {
27614
+ const { createEverosSync: createEverosSync2 } = await Promise.resolve().then(() => (init_everos_sync(), everos_sync_exports));
27615
+ const everosSync = createEverosSync2({
27616
+ enabled: true,
27617
+ url: everosCfg.everosUrl || "http://127.0.0.1:8100",
27618
+ appId: everosCfg.userId || "default",
27619
+ userId: everosCfg.userId || "default"
27620
+ });
27621
+ sessions.onWriterCreated = (writer, sessionId) => {
27622
+ writer.onMessageWritten = (msg2) => {
27623
+ everosSync.push({
27624
+ sessionId: writer.engineSessionId || sessionId,
27625
+ role: msg2.role === "toolResult" ? "tool" : msg2.role,
27626
+ text: msg2.text,
27627
+ timestamp: new Date(msg2.timestamp).getTime()
27628
+ }).catch(() => {
27629
+ });
27630
+ };
27631
+ };
27632
+ console.log(`[everos-sync] hook registered (appId=${everosCfg.userId})`);
27633
+ }
27541
27634
  const channelManager = new ChannelManager();
27542
27635
  const memoryRecallProvider = createMemorySideProvider(
27543
27636
  config2.topics?.recall,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "engine7",
3
- "version": "7.1.21",
3
+ "version": "7.1.23",
4
4
  "type": "module",
5
5
  "description": "Engine 7 — Self-hosted AI agent engine",
6
6
  "main": "dist/main.mjs",