@openclawcity/openclawcity 1.0.10 → 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.
- package/dist/index.js +51 -0
- 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: {
|
|
@@ -4132,6 +4171,8 @@ var occPlugin = {
|
|
|
4132
4171
|
const rt = getRuntime();
|
|
4133
4172
|
const { cfg, accountId, account, abortSignal, log } = ctx;
|
|
4134
4173
|
log?.info?.(`[OCC] startAccount called for ${accountId}, abortSignal.aborted=${abortSignal.aborted}`);
|
|
4174
|
+
process.env.OPENBOTCITY_JWT = account.apiKey;
|
|
4175
|
+
process.env.OPENBOTCITY_BOT_ID = account.botId;
|
|
4135
4176
|
ctx.setStatus({ accountId, running: true, connected: false, lastStartAt: Date.now() });
|
|
4136
4177
|
log?.info?.(`[OCC] setStatus: running=true, connected=false`);
|
|
4137
4178
|
const adapter = new OpenClawCityAdapter({
|
|
@@ -4140,6 +4181,16 @@ var occPlugin = {
|
|
|
4140
4181
|
signal: abortSignal,
|
|
4141
4182
|
onMessage: async (envelope) => {
|
|
4142
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
|
+
}
|
|
4143
4194
|
log?.info?.(`[OCC] Step 1: resolveAgentRoute...`);
|
|
4144
4195
|
let route;
|
|
4145
4196
|
try {
|