Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/backend-profiles-and-rooms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"grok-bot-cli": patch
---

Grok Bot 1.1 support for bot profiles and groups. `bots update` now saves a cloud bot's edited profile fields on the backend (`UpdateGrokBotAgent`, partial update) before telling the box, like the app does; a box-only write reported success but was undone by the next sync. `groups create` now creates the group on the backend (`CreateGrokBotRoom`), waits for the box to mirror it, then applies title and avatar; the gateway's `createGroup` answers 502 "A Sand box session is not permitted on this endpoint". The gateway remains the fallback for sessions without app credentials.
2 changes: 1 addition & 1 deletion artifact/agent-bundle.compile-evidence.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifact/agent-bundle.manifest.json

Large diffs are not rendered by default.

118 changes: 111 additions & 7 deletions artifact/bin/gbot-flight.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29932,6 +29932,57 @@ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
});
return unwrapOne(data);
}
const PROFILE_FIELDS = [
"name",
"description",
"title",
"avatarShape",
"avatarColor"
];
async function backendJson(session, method, body, signal) {
const state = reconnectStates.get(session);
if (!state) return null;
const credentials = state.accountKey ? (0, _app_session_js__rspack_import_2.gF)({
...state.appSessionOptions,
expectedAccountKey: state.accountKey
}) : {
accessToken: state.accessToken
};
if (!credentials?.accessToken) return null;
const url = (0, _url_policy_js__rspack_import_4.Re)(backendBase(), {
kind: "backend"
}) + "/aiserver.v1.GrokBotService/" + method;
const res = await fetch(url, {
method: "POST",
redirect: "error",
signal: gatewayDeadline(signal),
headers: {
...(0, _headers_js__rspack_import_1._6)(credentials.accessToken),
"x-cursor-client-os": process.platform,
"x-cursor-client-source": "sand-desktop",
"x-ghost-mode": "true",
"x-request-id": (0, node_crypto__rspack_import_0.randomUUID)(),
...credentials.teamId === undefined ? {} : {
"x-cursor-team-id": credentials.teamId
}
},
body: JSON.stringify(body)
});
const data = await readJson(res);
if (!res.ok) {
const detail = data.message || data.error || data.raw || res.statusText;
throw new GatewayError(method + " failed: " + res.status + " " + (0, _url_policy_js__rspack_import_4.fp)(String(detail).slice(0, 300)), {
status: res.status,
method
});
}
return data;
}
async function ownedServerAgentId(session, agentId) {
const data = await backendJson(session, "ListGrokBotAgents", {});
const agent = (data?.agents || []).find((a)=>a.agentId === agentId);
return agent && agent.viewerIsOwner !== false && agent.harness === "temporal" ? String(agent.id) : null;
}
async function updateAgent(session, ref, patch = {}) {
const rec = await resolveRef(session, ref);
if (patch.name !== undefined && !String(patch.name).trim()) {
Expand All @@ -29944,10 +29995,35 @@ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
if (patch.title !== undefined) profile.title = String(patch.title);
if (patch.avatarShape !== undefined) profile.avatarShape = assertAvatar("shape", patch.avatarShape, _store_js__rspack_import_3.Jb);
if (patch.avatarColor !== undefined) profile.avatarColor = assertAvatar("color", patch.avatarColor, _store_js__rspack_import_3.T7);
await gatewayCall(session, "updateAgent", {
id: rec.id,
profile
});
const editedFields = PROFILE_FIELDS.filter((field)=>patch[field] !== undefined);
if (editedFields.length) {
let held = {};
const serverId = await ownedServerAgentId(session, rec.id);
if (serverId) {
const changed = Object.fromEntries(editedFields.map((field)=>[
field,
profile[field]
]));
const saved = await backendJson(session, "UpdateGrokBotAgent", {
id: serverId,
...changed,
partialUpdate: true
});
const savedAtMs = Number(saved?.agent?.updatedAtMs);
held = {
serverHeldFields: editedFields,
...savedAtMs > 0 ? {
serverSavedAtMs: savedAtMs
} : {}
};
}
await gatewayCall(session, "updateAgent", {
id: rec.id,
profile,
editedFields,
...held
});
}
if (patch.notifyOnAgentUpdates !== undefined) {
await gatewayCall(session, "setAgentNotifyOnUpdates", {
id: rec.id,
Expand Down Expand Up @@ -30069,15 +30145,43 @@ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
...memberIds
];
}
async function backendCreateRoom(session, { name, description, memberAgentIds }) {
const clientNonce = (0, node_crypto__rspack_import_0.randomUUID)();
const data = await backendJson(session, "CreateGrokBotRoom", {
agentId: clientNonce,
name,
description,
memberAgentIds,
humanMemberUserIds: []
});
if (data === null) return null;
if (data?.agent?.agentId !== clientNonce) {
throw new GatewayError("CreateGrokBotRoom did not confirm the new group's id", {
method: "CreateGrokBotRoom"
});
}
for(let attempt = 0; attempt < 20; attempt++){
const rec = (await listAgents(session)).find((r)=>r.id === clientNonce);
if (rec) return rec;
await new Promise((resolve)=>setTimeout(resolve, 1000));
}
return {
id: clientNonce,
name,
description,
memberIds: memberAgentIds,
isGroup: true
};
}
async function createGroup(session, input) {
const records = await listAgents(session);
const memberAgentIds = normalizeMemberIds(records, input.memberIds || []);
const data = await gatewayCall(session, "createGroup", {
const fields = {
name: input.name,
description: input.description || "",
memberAgentIds
});
const rec = unwrapOne(data);
};
const rec = await backendCreateRoom(session, fields) ?? unwrapOne(await gatewayCall(session, "createGroup", fields));
const extras = {};
if (input.title) extras.title = input.title;
if (input.avatarShape) extras.avatarShape = input.avatarShape;
Expand Down
118 changes: 111 additions & 7 deletions artifact/bin/gbot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48361,6 +48361,57 @@ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
});
return unwrapOne(data);
}
const PROFILE_FIELDS = [
"name",
"description",
"title",
"avatarShape",
"avatarColor"
];
async function backendJson(session, method, body, signal) {
const state = reconnectStates.get(session);
if (!state) return null;
const credentials = state.accountKey ? (0, _app_session_js__rspack_import_2.gF)({
...state.appSessionOptions,
expectedAccountKey: state.accountKey
}) : {
accessToken: state.accessToken
};
if (!credentials?.accessToken) return null;
const url = (0, _url_policy_js__rspack_import_4.Re)(backendBase(), {
kind: "backend"
}) + "/aiserver.v1.GrokBotService/" + method;
const res = await fetch(url, {
method: "POST",
redirect: "error",
signal: gatewayDeadline(signal),
headers: {
...(0, _headers_js__rspack_import_1._6)(credentials.accessToken),
"x-cursor-client-os": process.platform,
"x-cursor-client-source": "sand-desktop",
"x-ghost-mode": "true",
"x-request-id": (0, node_crypto__rspack_import_0.randomUUID)(),
...credentials.teamId === undefined ? {} : {
"x-cursor-team-id": credentials.teamId
}
},
body: JSON.stringify(body)
});
const data = await readJson(res);
if (!res.ok) {
const detail = data.message || data.error || data.raw || res.statusText;
throw new GatewayError(method + " failed: " + res.status + " " + (0, _url_policy_js__rspack_import_4.fp)(String(detail).slice(0, 300)), {
status: res.status,
method
});
}
return data;
}
async function ownedServerAgentId(session, agentId) {
const data = await backendJson(session, "ListGrokBotAgents", {});
const agent = (data?.agents || []).find((a)=>a.agentId === agentId);
return agent && agent.viewerIsOwner !== false && agent.harness === "temporal" ? String(agent.id) : null;
}
async function updateAgent(session, ref, patch = {}) {
const rec = await resolveRef(session, ref);
if (patch.name !== undefined && !String(patch.name).trim()) {
Expand All @@ -48373,10 +48424,35 @@ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
if (patch.title !== undefined) profile.title = String(patch.title);
if (patch.avatarShape !== undefined) profile.avatarShape = assertAvatar("shape", patch.avatarShape, _store_js__rspack_import_3.Jb);
if (patch.avatarColor !== undefined) profile.avatarColor = assertAvatar("color", patch.avatarColor, _store_js__rspack_import_3.T7);
await gatewayCall(session, "updateAgent", {
id: rec.id,
profile
});
const editedFields = PROFILE_FIELDS.filter((field)=>patch[field] !== undefined);
if (editedFields.length) {
let held = {};
const serverId = await ownedServerAgentId(session, rec.id);
if (serverId) {
const changed = Object.fromEntries(editedFields.map((field)=>[
field,
profile[field]
]));
const saved = await backendJson(session, "UpdateGrokBotAgent", {
id: serverId,
...changed,
partialUpdate: true
});
const savedAtMs = Number(saved?.agent?.updatedAtMs);
held = {
serverHeldFields: editedFields,
...savedAtMs > 0 ? {
serverSavedAtMs: savedAtMs
} : {}
};
}
await gatewayCall(session, "updateAgent", {
id: rec.id,
profile,
editedFields,
...held
});
}
if (patch.notifyOnAgentUpdates !== undefined) {
await gatewayCall(session, "setAgentNotifyOnUpdates", {
id: rec.id,
Expand Down Expand Up @@ -48498,15 +48574,43 @@ ts() { date -u +%Y-%m-%dT%H:%M:%SZ; }
...memberIds
];
}
async function backendCreateRoom(session, { name, description, memberAgentIds }) {
const clientNonce = (0, node_crypto__rspack_import_0.randomUUID)();
const data = await backendJson(session, "CreateGrokBotRoom", {
agentId: clientNonce,
name,
description,
memberAgentIds,
humanMemberUserIds: []
});
if (data === null) return null;
if (data?.agent?.agentId !== clientNonce) {
throw new GatewayError("CreateGrokBotRoom did not confirm the new group's id", {
method: "CreateGrokBotRoom"
});
}
for(let attempt = 0; attempt < 20; attempt++){
const rec = (await listAgents(session)).find((r)=>r.id === clientNonce);
if (rec) return rec;
await new Promise((resolve)=>setTimeout(resolve, 1000));
}
return {
id: clientNonce,
name,
description,
memberIds: memberAgentIds,
isGroup: true
};
}
async function createGroup(session, input) {
const records = await listAgents(session);
const memberAgentIds = normalizeMemberIds(records, input.memberIds || []);
const data = await gatewayCall(session, "createGroup", {
const fields = {
name: input.name,
description: input.description || "",
memberAgentIds
});
const rec = unwrapOne(data);
};
const rec = await backendCreateRoom(session, fields) ?? unwrapOne(await gatewayCall(session, "createGroup", fields));
const extras = {};
if (input.title) extras.title = input.title;
if (input.avatarShape) extras.avatarShape = input.avatarShape;
Expand Down
Loading