Skip to content

Commit bdf5b08

Browse files
harjothkharavincentkoc
authored andcommitted
fix(canvas): preserve widgets across derived-name collisions
Fixes #116945
1 parent 1b84119 commit bdf5b08

15 files changed

Lines changed: 1109 additions & 39 deletions

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,28 @@ public struct BoardCanvasDocumentSource: Codable, Sendable {
742742
}
743743
}
744744

745+
public struct BoardWidgetGeneratedIdentity: Codable, Sendable {
746+
public let source: String
747+
public let key: String
748+
public let fallbackname: String
749+
750+
public init(
751+
source: String,
752+
key: String,
753+
fallbackname: String)
754+
{
755+
self.source = source
756+
self.key = key
757+
self.fallbackname = fallbackname
758+
}
759+
760+
private enum CodingKeys: String, CodingKey {
761+
case source
762+
case key
763+
case fallbackname = "fallbackName"
764+
}
765+
}
766+
745767
public struct BoardGetParams: Codable, Sendable {
746768
public let sessionkey: String
747769

@@ -783,6 +805,7 @@ public struct BoardWidgetPutParams: Codable, Sendable {
783805
public let heightmode: AnyCodable?
784806
public let placement: [String: AnyCodable]?
785807
public let declared: BoardWidgetDeclared?
808+
public let generatedidentity: BoardWidgetGeneratedIdentity?
786809

787810
public init(
788811
sessionkey: String,
@@ -792,7 +815,8 @@ public struct BoardWidgetPutParams: Codable, Sendable {
792815
presentation: AnyCodable? = nil,
793816
heightmode: AnyCodable? = nil,
794817
placement: [String: AnyCodable]? = nil,
795-
declared: BoardWidgetDeclared? = nil)
818+
declared: BoardWidgetDeclared? = nil,
819+
generatedidentity: BoardWidgetGeneratedIdentity? = nil)
796820
{
797821
self.sessionkey = sessionkey
798822
self.name = name
@@ -802,6 +826,7 @@ public struct BoardWidgetPutParams: Codable, Sendable {
802826
self.heightmode = heightmode
803827
self.placement = placement
804828
self.declared = declared
829+
self.generatedidentity = generatedidentity
805830
}
806831

807832
private enum CodingKeys: String, CodingKey {
@@ -813,6 +838,37 @@ public struct BoardWidgetPutParams: Codable, Sendable {
813838
case heightmode = "heightMode"
814839
case placement
815840
case declared
841+
case generatedidentity = "generatedIdentity"
842+
}
843+
}
844+
845+
public struct BoardWidgetPutResult: Codable, Sendable {
846+
public let sessionkey: String
847+
public let revision: Int
848+
public let tabs: [BoardTab]
849+
public let widgets: [BoardWidget]
850+
public let resolvedwidgetname: String
851+
852+
public init(
853+
sessionkey: String,
854+
revision: Int,
855+
tabs: [BoardTab],
856+
widgets: [BoardWidget],
857+
resolvedwidgetname: String)
858+
{
859+
self.sessionkey = sessionkey
860+
self.revision = revision
861+
self.tabs = tabs
862+
self.widgets = widgets
863+
self.resolvedwidgetname = resolvedwidgetname
864+
}
865+
866+
private enum CodingKeys: String, CodingKey {
867+
case sessionkey = "sessionKey"
868+
case revision
869+
case tabs
870+
case widgets
871+
case resolvedwidgetname = "resolvedWidgetName"
816872
}
817873
}
818874

‎packages/gateway-protocol/src/schema/board.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
BoardWidgetAppViewResultSchema,
88
BoardWidgetGrantParamsSchema,
99
BoardWidgetPutParamsSchema,
10+
BoardWidgetPutResultSchema,
1011
BoardWidgetResizeOpSchema,
1112
} from "./board.js";
1213

@@ -165,6 +166,55 @@ describe("BoardWidgetPutParamsSchema", () => {
165166
).toBe(true);
166167
});
167168

169+
it("accepts bounded generated widget identity metadata", () => {
170+
const pin = {
171+
sessionKey: "agent:main:main",
172+
name: "status",
173+
content: { kind: "html", html: "<p>ok</p>" },
174+
generatedIdentity: {
175+
source: "show_widget",
176+
key: "a".repeat(64),
177+
fallbackName: "status-aaaaaaaa",
178+
},
179+
};
180+
expect(Value.Check(BoardWidgetPutParamsSchema, pin)).toBe(true);
181+
expect(
182+
Value.Check(BoardWidgetPutParamsSchema, {
183+
...pin,
184+
generatedIdentity: { ...pin.generatedIdentity, source: "canvas" },
185+
}),
186+
).toBe(false);
187+
expect(
188+
Value.Check(BoardWidgetPutParamsSchema, {
189+
...pin,
190+
generatedIdentity: { ...pin.generatedIdentity, key: "short" },
191+
}),
192+
).toBe(false);
193+
});
194+
195+
it("returns the committed widget name with the board snapshot", () => {
196+
expect(
197+
Value.Check(BoardWidgetPutResultSchema, {
198+
sessionKey: "agent:main:main",
199+
revision: 1,
200+
tabs: [{ tabId: "main", title: "Main", position: 0, chatDock: "right" }],
201+
widgets: [
202+
{
203+
name: "status-aaaaaaaa",
204+
tabId: "main",
205+
contentKind: "html",
206+
sizeW: 6,
207+
sizeH: 4,
208+
position: 0,
209+
grantState: "none",
210+
revision: 1,
211+
},
212+
],
213+
resolvedWidgetName: "status-aaaaaaaa",
214+
}),
215+
).toBe(true);
216+
});
217+
168218
it("rejects invalid widget presentation and height modes", () => {
169219
const pin = {
170220
sessionKey: "agent:main:main",

‎packages/gateway-protocol/src/schema/board.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export const BoardTabIdSchema = Type.String({ pattern: "^[a-z0-9-]{1,40}$" });
77
export const BoardWidgetNameSchema = Type.String({
88
pattern: "^[a-z0-9][a-z0-9._-]{0,63}$",
99
});
10+
export const BoardWidgetGeneratedIdentitySchema = closedObject({
11+
source: Type.Literal("show_widget"),
12+
key: Type.String({ pattern: "^[a-f0-9]{64}$" }),
13+
fallbackName: BoardWidgetNameSchema,
14+
});
15+
export type BoardWidgetGeneratedIdentity = Static<typeof BoardWidgetGeneratedIdentitySchema>;
1016
export const BoardWidgetPluginKindSchema = Type.String({
1117
pattern: "^[a-z0-9][a-z0-9-]{0,63}:[a-z0-9][a-z0-9._-]{0,63}$",
1218
});
@@ -92,12 +98,13 @@ export const BoardWidgetSchema = closedObject({
9298
});
9399
export type BoardWidget = Static<typeof BoardWidgetSchema>;
94100

95-
export const BoardSnapshotSchema = closedObject({
101+
const BoardSnapshotFields = {
96102
sessionKey: NonEmptyString,
97103
revision: Type.Integer({ minimum: 0 }),
98104
tabs: Type.Array(BoardTabSchema),
99105
widgets: Type.Array(BoardWidgetSchema),
100-
});
106+
};
107+
export const BoardSnapshotSchema = closedObject(BoardSnapshotFields);
101108
export type BoardSnapshot = Static<typeof BoardSnapshotSchema>;
102109

103110
export const BoardTabCreateOpSchema = closedObject({
@@ -224,12 +231,18 @@ export const BoardWidgetPutParamsSchema = closedObject({
224231
}),
225232
),
226233
declared: Type.Optional(BoardWidgetDeclaredSchema),
234+
generatedIdentity: Type.Optional(BoardWidgetGeneratedIdentitySchema),
227235
});
228236
export type BoardWidgetPutParams = Static<typeof BoardWidgetPutParamsSchema>;
229237
/** Materialized input accepted by the board store after gateway source resolution. */
230238
export type BoardWidgetMaterializedPutParams = Omit<BoardWidgetPutParams, "content"> & {
231239
content: BoardWidgetMaterializedContent;
232240
};
241+
export const BoardWidgetPutResultSchema = closedObject({
242+
...BoardSnapshotFields,
243+
resolvedWidgetName: BoardWidgetNameSchema,
244+
});
245+
export type BoardWidgetPutResult = Static<typeof BoardWidgetPutResultSchema>;
233246

234247
export const BoardWidgetGrantParamsSchema = closedObject({
235248
sessionKey: NonEmptyString,

‎packages/gateway-protocol/src/schema/protocol-schema-fragment-board.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ export const BoardProtocolSchemas = {
2222
BoardCanvasDocumentSource: board.BoardCanvasDocumentSourceSchema,
2323
BoardWidgetContent: board.BoardWidgetContentSchema,
2424
BoardWidgetPutContent: board.BoardWidgetPutContentSchema,
25+
BoardWidgetGeneratedIdentity: board.BoardWidgetGeneratedIdentitySchema,
2526
BoardGetParams: board.BoardGetParamsSchema,
2627
BoardUpdateParams: board.BoardUpdateParamsSchema,
2728
BoardWidgetPutParams: board.BoardWidgetPutParamsSchema,
29+
BoardWidgetPutResult: board.BoardWidgetPutResultSchema,
2830
BoardWidgetGrantParams: board.BoardWidgetGrantParamsSchema,
2931
BoardWidgetAppViewParams: board.BoardWidgetAppViewParamsSchema,
3032
BoardWidgetAppViewResult: board.BoardWidgetAppViewResultSchema,

0 commit comments

Comments
 (0)