@openclawcity/openclawcity 1.0.11 → 1.0.12

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.
Files changed (2) hide show
  1. package/dist/index.js +49 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4072,7 +4072,46 @@ var OpenClawCityAdapter = class {
4072
4072
 
4073
4073
  // .tsc-out/index.js
4074
4074
  var CHANNEL_ID = "openclawcity";
4075
+ var DEFAULT_API_BASE = "https://api.openbotcity.com";
4076
+ var HEARTBEAT_CACHE_MS = 5 * 60 * 1e3;
4077
+ function deriveApiBase(gatewayUrl) {
4078
+ if (!gatewayUrl)
4079
+ return DEFAULT_API_BASE;
4080
+ try {
4081
+ const url = new URL(gatewayUrl);
4082
+ const protocol = url.protocol === "wss:" ? "https:" : "http:";
4083
+ return `${protocol}//${url.host}`;
4084
+ } catch {
4085
+ return DEFAULT_API_BASE;
4086
+ }
4087
+ }
4075
4088
  var adapters = /* @__PURE__ */ new Map();
4089
+ var heartbeatCache = /* @__PURE__ */ new Map();
4090
+ async function fetchHeartbeatContext(apiBase, jwt, accountId, log) {
4091
+ const cached = heartbeatCache.get(accountId);
4092
+ const now = Date.now();
4093
+ if (cached && now - cached.fetchedAt < HEARTBEAT_CACHE_MS) {
4094
+ log?.info?.(`[OCC] Heartbeat cache hit (age=${Math.round((now - cached.fetchedAt) / 1e3)}s)`);
4095
+ return cached.data;
4096
+ }
4097
+ try {
4098
+ log?.info?.(`[OCC] Fetching heartbeat context from ${apiBase}/world/heartbeat`);
4099
+ const resp = await fetch(`${apiBase}/world/heartbeat`, {
4100
+ headers: { "Authorization": `Bearer ${jwt}` }
4101
+ });
4102
+ if (!resp.ok) {
4103
+ log?.error?.(`[OCC] Heartbeat fetch failed: ${resp.status} ${resp.statusText}`);
4104
+ return cached?.data ?? null;
4105
+ }
4106
+ const data = await resp.text();
4107
+ heartbeatCache.set(accountId, { data, fetchedAt: now });
4108
+ log?.info?.(`[OCC] Heartbeat fetched (${data.length} bytes)`);
4109
+ return data;
4110
+ } catch (err) {
4111
+ log?.error?.(`[OCC] Heartbeat fetch error: ${String(err)}`);
4112
+ return cached?.data ?? null;
4113
+ }
4114
+ }
4076
4115
  var occPlugin = {
4077
4116
  id: CHANNEL_ID,
4078
4117
  meta: {
@@ -4142,6 +4181,16 @@ var occPlugin = {
4142
4181
  signal: abortSignal,
4143
4182
  onMessage: async (envelope) => {
4144
4183
  log?.info?.(`[OCC] Event received: ${envelope.id} from=${envelope.sender.name} type=${envelope.metadata.eventType}`);
4184
+ const apiBase = deriveApiBase(account.gatewayUrl);
4185
+ const cityCtx = await fetchHeartbeatContext(apiBase, account.apiKey, accountId, log);
4186
+ if (cityCtx) {
4187
+ envelope.content.text = `[CITY CONTEXT]
4188
+ ${cityCtx}
4189
+ [/CITY CONTEXT]
4190
+
4191
+ ${envelope.content.text}`;
4192
+ log?.info?.(`[OCC] City context prepended (${cityCtx.length} bytes)`);
4193
+ }
4145
4194
  log?.info?.(`[OCC] Step 1: resolveAgentRoute...`);
4146
4195
  let route;
4147
4196
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclawcity/openclawcity",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "OpenClawCity channel plugin for OpenClaw — live city events for AI agents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",