惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
H
Help Net Security
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
V
V2EX
M
MIT News - Artificial intelligence
Vercel News
Vercel News
WordPress大学
WordPress大学
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
D
Docker
V
Visual Studio Blog
博客园 - 叶小钗
美团技术团队
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(protocol): emit Swift enums for literal unions · open...
steipete · 2026-06-15 · via Recent Commits to openclaw:main

File tree

  • apps/shared/OpenClawKit/Sources/OpenClawProtocol

  • packages/gateway-protocol/src

Original file line numberDiff line numberDiff line change

@@ -46,6 +46,17 @@ public enum NodePresenceAliveReason: String, Codable, Sendable {

4646

case connect = "connect"

4747

}

4848
49+

public enum SessionFileKind: String, Codable, Sendable {

50+

case modified = "modified"

51+

case read = "read"

52+

}

53+
54+

public enum SessionFileRelevance: String, Codable, Sendable {

55+

case modified = "modified"

56+

case read = "read"

57+

case mixed = "mixed"

58+

}

59+
4960

public struct ConnectParams: Codable, Sendable {

5061

public let minprotocol: Int

5162

public let maxprotocol: Int

Original file line numberDiff line numberDiff line change

@@ -2,6 +2,7 @@

22

import fs from "node:fs/promises";

33

import path from "node:path";

44

import { describe, it } from "vitest";

5+

import { ProtocolSchemas } from "./schema/protocol-schemas.js";

56

import { MIN_CLIENT_PROTOCOL_VERSION, PROTOCOL_VERSION } from "./version.js";

67
78

/**

@@ -178,4 +179,37 @@ describe("native Gateway protocol levels", () => {

178179

);

179180

}

180181

});

182+
183+

it("emits named string-literal unions as Swift enums", async () => {

184+

const swiftGeneratedPath =

185+

"apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift";

186+

const swiftGenerated = await readRepoFile(swiftGeneratedPath);

187+
188+

for (const [name, schema] of Object.entries(ProtocolSchemas)) {

189+

const branches = schema.anyOf ?? schema.oneOf;

190+

if (!branches || branches.length < 2) {

191+

continue;

192+

}

193+

const values = branches.map((branch) => branch.const);

194+

if (values.some((value) => typeof value !== "string")) {

195+

continue;

196+

}

197+
198+

const enumStart = `public enum ${name}: String, Codable, Sendable {`;

199+

const start = swiftGenerated.indexOf(enumStart);

200+

if (start < 0) {

201+

throw new Error(`${swiftGeneratedPath}: missing Swift enum for ${name}.`);

202+

}

203+

const end = swiftGenerated.indexOf("\n}\n", start);

204+

const enumSource = swiftGenerated.slice(start, end);

205+

for (const value of values) {

206+

assertPattern(

207+

enumSource,

208+

swiftGeneratedPath,

209+

new RegExp(`= ${JSON.stringify(value)}$`, "m"),

210+

`${name} must include the ${JSON.stringify(value)} literal.`,

211+

);

212+

}

213+

}

214+

});

181215

});

Original file line numberDiff line numberDiff line change

@@ -244,6 +244,19 @@ function emitEnum(name: string, schema: JsonSchema): string {

244244

].join("\n");

245245

}

246246
247+

function stringLiteralUnionValues(schema: JsonSchema): string[] | undefined {

248+

const branches = schema.oneOf ?? schema.anyOf;

249+

if (!branches || branches.length < 2) {

250+

return undefined;

251+

}

252+

const values = branches.map((branch) => literalSchemaValue(branch));

253+

if (values.some((value) => typeof value !== "string")) {

254+

return undefined;

255+

}

256+

const stringValues = values as string[];

257+

return new Set(stringValues).size === stringValues.length ? stringValues : undefined;

258+

}

259+
247260

function emitStruct(name: string, schema: JsonSchema): string {

248261

const props = schema.properties ?? {};

249262

const required = new Set(schema.required ?? []);

@@ -608,6 +621,11 @@ async function generate() {

608621

}

609622

if (schema.type === "string" && schema.enum) {

610623

parts.push(emitEnum(name, schema));

624+

continue;

625+

}

626+

const literalUnionValues = stringLiteralUnionValues(schema);

627+

if (literalUnionValues) {

628+

parts.push(emitEnum(name, { enum: literalUnionValues }));

611629

}

612630

}

613631