Skip to content
Merged
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
6 changes: 2 additions & 4 deletions apps/xmtp.chat/src/components/App/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ export const AppLayout: React.FC = () => {
}, [client]);

useEffect(() => {
if (!client) {
const sessionSdkEnv = client?.env;
if (!client || !sessionSdkEnv) {
return;
}

// the session's actual SDK environment from client options
const sessionSdkEnv = client.options?.env ?? "dev";
const isInvalidEnvironment =
!envParam ||
!isValidEnvironment(envParam) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Badge, Box, Group, Stack, Text } from "@mantine/core";
import {
BackupElementSelectionOption,
HistorySyncUrls,
} from "@xmtp/browser-sdk";
import { useCallback, useEffect, useRef } from "react";
import { ConversationsList } from "@/components/Conversations/ConversationList";
import { ConversationsMenu } from "@/components/Conversations/ConversationsMenu";
Expand Down Expand Up @@ -48,7 +52,21 @@ export const ConversationsNavbar: React.FC = () => {
}, [syncAll, startStreams, stopStreams]);

const handleSendSyncRequest = useCallback(async () => {
await client.sendSyncRequest();
const env = client.env;
if (!env) {
return;
}
const serverUrl = HistorySyncUrls[env];
await client.sendSyncRequest(
{
elements: [
BackupElementSelectionOption.Messages,
BackupElementSelectionOption.Consent,
],
excludeDisappearingMessages: false,
},
serverUrl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these updates

);
}, [client]);

// loading conversations on mount, and start streaming
Expand Down
6 changes: 4 additions & 2 deletions apps/xmtp.chat/src/contexts/XMTPContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
Client,
type BuiltInContentTypes,
type ClientOptions,
type NetworkOptions,
type Signer,
type XmtpEnv,
} from "@xmtp/browser-sdk";
import {
createContext,
Expand All @@ -20,7 +22,7 @@ export type ContentTypes = BuiltInContentTypes;
export type InitializeClientOptions = {
apiUrl?: string;
dbEncryptionKey?: Uint8Array;
env?: ClientOptions["env"];
env?: XmtpEnv;
loggingLevel?: ClientOptions["loggingLevel"];
signer: Signer;
gatewayHost?: string;
Expand Down Expand Up @@ -122,7 +124,7 @@ export const XMTPProvider: React.FC<XMTPProviderProps> = ({
dbEncryptionKey,
appVersion: "xmtp.chat/0",
gatewayHost,
});
} as Omit<ClientOptions & NetworkOptions, "codecs">);
setClient(xmtpClient);
} catch (e) {
setClient(undefined);
Expand Down
2 changes: 1 addition & 1 deletion apps/xmtp.chat/src/helpers/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const getFileType = (filename: string) => {
}
};

export const formatFileSize = (fileSize: number) => {
export const formatFileSize = (fileSize: number | undefined) => {
if (!fileSize) return "";
const kb = fileSize / 1024;
if (kb < 1024) {
Expand Down
14 changes: 6 additions & 8 deletions apps/xmtp.chat/src/helpers/names.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
createBackend,
getInboxIdForIdentifier,
IdentifierKind,
type XmtpEnv,
Expand Down Expand Up @@ -84,14 +85,11 @@ export const getInboxIdForAddress = async (
return null;
}

const inboxId = await getInboxIdForIdentifier(
{
identifier: address.toLowerCase(),
identifierKind: IdentifierKind.Ethereum,
},
environment,
gatewayHost,
);
const backend = await createBackend({ env: environment, gatewayHost });
const inboxId = await getInboxIdForIdentifier(backend, {
identifier: address.toLowerCase(),
identifierKind: IdentifierKind.Ethereum,
});

return inboxId ?? null;
};
2 changes: 1 addition & 1 deletion content-types/content-type-primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
]
},
"dependencies": {
"@xmtp/node-bindings": "1.9.1"
"@xmtp/node-bindings": "1.10.0-dev.2334796"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/xmtp-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@oclif/plugin-help": "^6.2.37",
"@oclif/plugin-not-found": "^3.2.74",
"@oclif/plugin-warn-if-update-available": "^3.1.55",
"@xmtp/node-sdk": "5.3.0",
"@xmtp/node-sdk": "5.4.0",
"viem": "^2.44.4"
},
"devDependencies": {
Expand Down
25 changes: 13 additions & 12 deletions packages/xmtp-cli/src/commands/client/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ application instance using your identity.`;
async run(): Promise<void> {
const client = await this.initClient();

const options = client.options ?? {};
const options = client.options;
const hasNetworkOptions = options && "env" in options;

const properties = {
address: client.accountIdentifier?.identifier,
Expand All @@ -46,17 +47,17 @@ application instance using your identity.`;
};

const clientOptions = {
env: options.env,
apiUrl: options.apiUrl,
historySyncUrl: options.historySyncUrl,
gatewayHost: options.gatewayHost,
dbPath: options.dbPath,
loggingLevel: options.loggingLevel,
structuredLogging: options.structuredLogging,
disableAutoRegister: options.disableAutoRegister,
disableDeviceSync: options.disableDeviceSync,
appVersion: options.appVersion,
nonce: options.nonce,
env: client.env,
apiUrl: hasNetworkOptions ? options.apiUrl : undefined,
historySyncUrl: options?.historySyncUrl,
gatewayHost: hasNetworkOptions ? options.gatewayHost : undefined,
dbPath: options?.dbPath,
loggingLevel: options?.loggingLevel,
structuredLogging: options?.structuredLogging,
disableAutoRegister: options?.disableAutoRegister,
disableDeviceSync: options?.disableDeviceSync,
appVersion: hasNetworkOptions ? options.appVersion : undefined,
nonce: options?.nonce,
};

if (this.jsonOutput) {
Expand Down
18 changes: 14 additions & 4 deletions packages/xmtp-cli/src/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { mkdir } from "node:fs/promises";
import { dirname } from "node:path";
import { Client, IdentifierKind, LogLevel, type Signer } from "@xmtp/node-sdk";
import {
Client,
IdentifierKind,
LogLevel,
type NetworkOptions,
type Signer,
} from "@xmtp/node-sdk";
import { isHex, toBytes } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import type { XmtpConfig } from "./config.js";
Expand Down Expand Up @@ -79,15 +85,19 @@ export async function createClient(config: XmtpConfig): Promise<Client> {
await mkdir(dirname(config.dbPath), { recursive: true });
}

const client = await Client.create(signer, {
const networkOptions: NetworkOptions = {
env: config.env,
gatewayHost: config.gatewayHost,
appVersion: config.appVersion,
};

const client = await Client.create(signer, {
...networkOptions,
dbEncryptionKey: hexToBytes(config.dbEncryptionKey),
dbPath: config.dbPath ?? undefined,
gatewayHost: config.gatewayHost,
loggingLevel: parseLogLevel(config.logLevel),
structuredLogging: config.structuredLogging,
disableDeviceSync: config.disableDeviceSync,
appVersion: config.appVersion,
});

return client;
Expand Down
2 changes: 1 addition & 1 deletion sdks/agent-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
},
"dependencies": {
"@xmtp/content-type-primitives": "3.0.1",
"@xmtp/node-sdk": "5.3.0",
"@xmtp/node-sdk": "5.4.0",
"viem": "^2.37.6"
},
"devDependencies": {
Expand Down
20 changes: 16 additions & 4 deletions sdks/agent-sdk/src/core/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fs from "node:fs";
import path from "node:path";
import type { ContentCodec } from "@xmtp/content-type-primitives";
import {
ApiUrls,
Client,
DecodedMessage,
Dm,
Expand Down Expand Up @@ -37,6 +36,7 @@ import {
type Intent,
type LeaveRequest,
type MultiRemoteAttachment,
type NetworkOptions,
type Reaction,
type ReadReceipt,
type RemoteAttachment,
Expand Down Expand Up @@ -127,6 +127,9 @@ export type AgentErrorMiddleware<ContentTypes = unknown> = (
next: (err?: unknown) => Promise<void> | void,
) => Promise<void> | void;

export type AgentCreateOptions<ContentCodecs extends ContentCodec[] = []> =
Omit<ClientOptions & NetworkOptions, "codecs"> & { codecs?: ContentCodecs };

export type AgentStreamingOptions = Omit<StreamOptions, "onValue" | "onError">;

export type StreamAllMessagesOptions<ContentTypes> = Parameters<
Expand Down Expand Up @@ -187,7 +190,7 @@ export class Agent<ContentTypes = unknown> extends EventEmitter<
static async create<ContentCodecs extends ContentCodec[] = []>(
signer: Parameters<typeof Client.create>[0],
// Note: we need to omit this so that "Client.create" can correctly infer the codecs.
options?: Omit<ClientOptions, "codecs"> & { codecs?: ContentCodecs },
options?: AgentCreateOptions<ContentCodecs>,
) {
const initializedOptions = { ...(options ?? {}) };
initializedOptions.appVersion ??= `agent-sdk/${appVersion}`;
Expand Down Expand Up @@ -225,7 +228,7 @@ export class Agent<ContentTypes = unknown> extends EventEmitter<

static async createFromEnv<ContentCodecs extends ContentCodec[] = []>(
// Note: we need to omit this so that "Client.create" can correctly infer the codecs.
options?: Omit<ClientOptions, "codecs"> & { codecs?: ContentCodecs },
options?: AgentCreateOptions<ContentCodecs>,
) {
const {
XMTP_DB_DIRECTORY,
Expand Down Expand Up @@ -253,7 +256,16 @@ export class Agent<ContentTypes = unknown> extends EventEmitter<
: `0x${XMTP_DB_ENCRYPTION_KEY}`
: undefined;

if (XMTP_ENV && Object.keys(ApiUrls).includes(XMTP_ENV)) {
const validEnvs: XmtpEnv[] = [
"local",
"dev",
"production",
"testnet-staging",
"testnet-dev",
"testnet",
"mainnet",
];
if (XMTP_ENV && validEnvs.includes(XMTP_ENV as XmtpEnv)) {
initializedOptions.env = XMTP_ENV as XmtpEnv;
}

Expand Down
23 changes: 14 additions & 9 deletions sdks/agent-sdk/src/debug/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ export const parseLogLevel = (rawLevel: string) => {

export const logDetails = async <ContentTypes>(agent: Agent<ContentTypes>) => {
const xmtp = `\x1b[38;2;252;76;52m
██╗ ██╗███╗ ███╗████████╗██████╗
██╗ ██╗███╗ ███╗████████╗██████╗
╚██╗██╔╝████╗ ████║╚══██╔══╝██╔══██╗
╚███╔╝ ██╔████╔██║ ██║ ██████╔╝
██╔██╗ ██║╚██╔╝██║ ██║ ██╔═══╝
██╔╝ ██╗██║ ╚═╝ ██║ ██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
██╔██╗ ██║╚██╔╝██║ ██║ ██╔═══╝
██╔╝ ██╗██║ ╚═╝ ██║ ██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
\x1b[0m`;

const client = agent.client;
const clientsByAddress = client.accountIdentifier?.identifier;
const inboxId = client.inboxId;
const installationId = client.installationId;
const env = client.options?.env ?? "dev";
const env = client.env;

const urls = [`http://xmtp.chat/${env}/dm/${clientsByAddress}`];

Expand All @@ -64,7 +64,7 @@ export const logDetails = async <ContentTypes>(agent: Agent<ContentTypes>) => {
}
console.log(`
${xmtp}

✓ XMTP Client:
• InboxId: ${inboxId}
• LibXMTP Version: ${agent.libxmtpVersion}
Expand All @@ -86,7 +86,7 @@ export const logDetails = async <ContentTypes>(agent: Agent<ContentTypes>) => {
*/
export const getTestUrl = <ContentTypes>(client: Client<ContentTypes>) => {
const address = client.accountIdentifier?.identifier;
const env = client.options?.env ?? "dev";
const env = client.env;
return `http://xmtp.chat/${env}/dm/${address}`;
};

Expand All @@ -103,10 +103,15 @@ export const getInstallationInfo = async <ContentTypes>(
const myInboxId = client.inboxId;
const myInstallationId = client.installationId;

const env = client.env;
const gatewayHost =
client.options && "gatewayHost" in client.options
? client.options.gatewayHost
: undefined;
const inboxStates = await Client.fetchInboxStates(
[myInboxId],
client.options?.env,
client.options?.gatewayHost,
env,
gatewayHost,
);

const installations =
Expand Down
11 changes: 9 additions & 2 deletions sdks/agent-sdk/src/util/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import {
type ContentTypeId,
type EncodedContent,
} from "@xmtp/content-type-primitives";
import { Client, generateInboxId, type ClientOptions } from "@xmtp/node-sdk";
import {
Client,
generateInboxId,
type ClientOptions,
type NetworkOptions,
} from "@xmtp/node-sdk";
import { createSigner, createUser } from "@/user/User";

export const createClient = async <ContentCodecs extends ContentCodec[] = []>(
options?: Omit<ClientOptions, "codecs"> & {
options?: Omit<ClientOptions & NetworkOptions, "codecs"> & {
codecs?: ContentCodecs;
},
) => {
Expand All @@ -28,6 +33,8 @@ export const createClient = async <ContentCodecs extends ContentCodec[] = []>(
historySyncUrl: undefined,
disableDeviceSync: true,
env: "local",
} as Omit<ClientOptions & NetworkOptions, "codecs"> & {
codecs?: ContentCodecs;
});
};

Expand Down
2 changes: 1 addition & 1 deletion sdks/browser-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"dependencies": {
"@xmtp/content-type-primitives": "3.0.0",
"@xmtp/wasm-bindings": "1.9.1"
"@xmtp/wasm-bindings": "1.10.0-dev.2334796"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
Expand Down
Loading
Loading