Skip to content

Commit 9f1785b

Browse files
committed
Enhance WhatsApp pairing functionality by isolating requests and allowFrom entries by account. Update GatewayModels to include new parameters for session management and improve CLI commands for better account handling. Refactor related tests to ensure account-specific behavior is correctly implemented.
1 parent 8e9f238 commit 9f1785b

22 files changed

Lines changed: 632 additions & 66 deletions

File tree

apps/macos/Sources/OpenSoulProtocol/GatewayModels.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public struct HelloOk: Codable, Sendable {
7979
public let features: [String: AnyCodable]
8080
public let snapshot: Snapshot
8181
public let canvashosturl: String?
82+
public let canvasauthtoken: String?
8283
public let auth: [String: AnyCodable]?
8384
public let policy: [String: AnyCodable]
8485

@@ -89,6 +90,7 @@ public struct HelloOk: Codable, Sendable {
8990
features: [String: AnyCodable],
9091
snapshot: Snapshot,
9192
canvashosturl: String?,
93+
canvasauthtoken: String?,
9294
auth: [String: AnyCodable]?,
9395
policy: [String: AnyCodable]
9496
) {
@@ -98,6 +100,7 @@ public struct HelloOk: Codable, Sendable {
98100
self.features = features
99101
self.snapshot = snapshot
100102
self.canvashosturl = canvashosturl
103+
self.canvasauthtoken = canvasauthtoken
101104
self.auth = auth
102105
self.policy = policy
103106
}
@@ -108,6 +111,7 @@ public struct HelloOk: Codable, Sendable {
108111
case features
109112
case snapshot
110113
case canvashosturl = "canvasHostUrl"
114+
case canvasauthtoken = "canvasAuthToken"
111115
case auth
112116
case policy
113117
}
@@ -945,6 +949,44 @@ public struct SessionsListParams: Codable, Sendable {
945949
}
946950
}
947951

952+
public struct SessionsListTranscriptsParams: Codable, Sendable {
953+
public let sessionkey: String
954+
public let limit: Int?
955+
956+
public init(
957+
sessionkey: String,
958+
limit: Int?
959+
) {
960+
self.sessionkey = sessionkey
961+
self.limit = limit
962+
}
963+
private enum CodingKeys: String, CodingKey {
964+
case sessionkey = "sessionKey"
965+
case limit
966+
}
967+
}
968+
969+
public struct SessionsListTranscriptsResult: Codable, Sendable {
970+
public let ts: Double
971+
public let sessionkey: String
972+
public let transcripts: [[String: AnyCodable]]
973+
974+
public init(
975+
ts: Double,
976+
sessionkey: String,
977+
transcripts: [[String: AnyCodable]]
978+
) {
979+
self.ts = ts
980+
self.sessionkey = sessionkey
981+
self.transcripts = transcripts
982+
}
983+
private enum CodingKeys: String, CodingKey {
984+
case ts
985+
case sessionkey = "sessionKey"
986+
case transcripts
987+
}
988+
}
989+
948990
public struct SessionsPreviewParams: Codable, Sendable {
949991
public let keys: [String]
950992
public let limit: Int?
@@ -2563,17 +2605,21 @@ public struct DevicePairResolvedEvent: Codable, Sendable {
25632605

25642606
public struct ChatHistoryParams: Codable, Sendable {
25652607
public let sessionkey: String
2608+
public let sessionid: String?
25662609
public let limit: Int?
25672610

25682611
public init(
25692612
sessionkey: String,
2613+
sessionid: String?,
25702614
limit: Int?
25712615
) {
25722616
self.sessionkey = sessionkey
2617+
self.sessionid = sessionid
25732618
self.limit = limit
25742619
}
25752620
private enum CodingKeys: String, CodingKey {
25762621
case sessionkey = "sessionKey"
2622+
case sessionid = "sessionId"
25772623
case limit
25782624
}
25792625
}

apps/shared/OpenSoulKit/Sources/OpenSoulProtocol/GatewayModels.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public struct HelloOk: Codable, Sendable {
7979
public let features: [String: AnyCodable]
8080
public let snapshot: Snapshot
8181
public let canvashosturl: String?
82+
public let canvasauthtoken: String?
8283
public let auth: [String: AnyCodable]?
8384
public let policy: [String: AnyCodable]
8485

@@ -89,6 +90,7 @@ public struct HelloOk: Codable, Sendable {
8990
features: [String: AnyCodable],
9091
snapshot: Snapshot,
9192
canvashosturl: String?,
93+
canvasauthtoken: String?,
9294
auth: [String: AnyCodable]?,
9395
policy: [String: AnyCodable]
9496
) {
@@ -98,6 +100,7 @@ public struct HelloOk: Codable, Sendable {
98100
self.features = features
99101
self.snapshot = snapshot
100102
self.canvashosturl = canvashosturl
103+
self.canvasauthtoken = canvasauthtoken
101104
self.auth = auth
102105
self.policy = policy
103106
}
@@ -108,6 +111,7 @@ public struct HelloOk: Codable, Sendable {
108111
case features
109112
case snapshot
110113
case canvashosturl = "canvasHostUrl"
114+
case canvasauthtoken = "canvasAuthToken"
111115
case auth
112116
case policy
113117
}
@@ -945,6 +949,44 @@ public struct SessionsListParams: Codable, Sendable {
945949
}
946950
}
947951

952+
public struct SessionsListTranscriptsParams: Codable, Sendable {
953+
public let sessionkey: String
954+
public let limit: Int?
955+
956+
public init(
957+
sessionkey: String,
958+
limit: Int?
959+
) {
960+
self.sessionkey = sessionkey
961+
self.limit = limit
962+
}
963+
private enum CodingKeys: String, CodingKey {
964+
case sessionkey = "sessionKey"
965+
case limit
966+
}
967+
}
968+
969+
public struct SessionsListTranscriptsResult: Codable, Sendable {
970+
public let ts: Double
971+
public let sessionkey: String
972+
public let transcripts: [[String: AnyCodable]]
973+
974+
public init(
975+
ts: Double,
976+
sessionkey: String,
977+
transcripts: [[String: AnyCodable]]
978+
) {
979+
self.ts = ts
980+
self.sessionkey = sessionkey
981+
self.transcripts = transcripts
982+
}
983+
private enum CodingKeys: String, CodingKey {
984+
case ts
985+
case sessionkey = "sessionKey"
986+
case transcripts
987+
}
988+
}
989+
948990
public struct SessionsPreviewParams: Codable, Sendable {
949991
public let keys: [String]
950992
public let limit: Int?
@@ -2563,17 +2605,21 @@ public struct DevicePairResolvedEvent: Codable, Sendable {
25632605

25642606
public struct ChatHistoryParams: Codable, Sendable {
25652607
public let sessionkey: String
2608+
public let sessionid: String?
25662609
public let limit: Int?
25672610

25682611
public init(
25692612
sessionkey: String,
2613+
sessionid: String?,
25702614
limit: Int?
25712615
) {
25722616
self.sessionkey = sessionkey
2617+
self.sessionid = sessionid
25732618
self.limit = limit
25742619
}
25752620
private enum CodingKeys: String, CodingKey {
25762621
case sessionkey = "sessionKey"
2622+
case sessionid = "sessionId"
25772623
case limit
25782624
}
25792625
}

src/auto-reply/reply/commands-allowlist.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,14 @@ export const handleAllowlistCommand: CommandHandler = async (params, allowTextCo
349349
};
350350
}
351351
const accountId = normalizeAccountId(parsed.account ?? params.ctx.AccountId);
352+
const storeAccountId = channelId === "whatsapp" ? accountId : undefined;
352353
const scope = parsed.scope;
353354

354355
if (parsed.action === "list") {
355356
const pairingChannels = listPairingChannels();
356357
const supportsStore = pairingChannels.includes(channelId);
357358
const storeAllowFrom = supportsStore
358-
? await readChannelAllowFromStore(channelId).catch(() => [])
359+
? await readChannelAllowFromStore(channelId, process.env, storeAccountId).catch(() => [])
359360
: [];
360361

361362
let dmAllowFrom: string[] = [];
@@ -649,9 +650,17 @@ export const handleAllowlistCommand: CommandHandler = async (params, allowTextCo
649650

650651
if (shouldTouchStore) {
651652
if (parsed.action === "add") {
652-
await addChannelAllowFromStoreEntry({ channel: channelId, entry: parsed.entry });
653+
await addChannelAllowFromStoreEntry({
654+
channel: channelId,
655+
entry: parsed.entry,
656+
...(storeAccountId ? { accountId: storeAccountId } : {}),
657+
});
653658
} else if (parsed.action === "remove") {
654-
await removeChannelAllowFromStoreEntry({ channel: channelId, entry: parsed.entry });
659+
await removeChannelAllowFromStoreEntry({
660+
channel: channelId,
661+
entry: parsed.entry,
662+
...(storeAccountId ? { accountId: storeAccountId } : {}),
663+
});
655664
}
656665
}
657666

@@ -681,9 +690,17 @@ export const handleAllowlistCommand: CommandHandler = async (params, allowTextCo
681690
}
682691

683692
if (parsed.action === "add") {
684-
await addChannelAllowFromStoreEntry({ channel: channelId, entry: parsed.entry });
693+
await addChannelAllowFromStoreEntry({
694+
channel: channelId,
695+
entry: parsed.entry,
696+
...(storeAccountId ? { accountId: storeAccountId } : {}),
697+
});
685698
} else if (parsed.action === "remove") {
686-
await removeChannelAllowFromStoreEntry({ channel: channelId, entry: parsed.entry });
699+
await removeChannelAllowFromStoreEntry({
700+
channel: channelId,
701+
entry: parsed.entry,
702+
...(storeAccountId ? { accountId: storeAccountId } : {}),
703+
});
687704
}
688705

689706
const actionLabel = parsed.action === "add" ? "added" : "removed";

src/channels/plugins/pairing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function resolvePairingChannel(raw: unknown): ChannelId {
5151
export async function notifyPairingApproved(params: {
5252
channelId: ChannelId;
5353
id: string;
54+
accountId?: string;
5455
cfg: OpenSoulConfig;
5556
runtime?: RuntimeEnv;
5657
/** Extension channels can pass their adapter directly to bypass registry lookup. */
@@ -64,6 +65,7 @@ export async function notifyPairingApproved(params: {
6465
await adapter.notifyApproval({
6566
cfg: params.cfg,
6667
id: params.id,
68+
accountId: params.accountId,
6769
runtime: params.runtime,
6870
});
6971
}

src/channels/plugins/types.adapters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export type ChannelPairingAdapter = {
187187
notifyApproval?: (params: {
188188
cfg: OpenSoulConfig;
189189
id: string;
190+
accountId?: string;
190191
runtime?: RuntimeEnv;
191192
}) => Promise<void>;
192193
};

0 commit comments

Comments
 (0)