2026-03-19 01:12:17 +08:00
|
|
|
|
import type { ConfigContext, ExpoConfig } from 'expo/config';
|
|
|
|
|
|
|
|
|
|
|
|
import zh from './locales/zh.json';
|
|
|
|
|
|
import en from './locales/en.json';
|
2026-03-22 19:22:34 +08:00
|
|
|
|
import permissionsZh from './locales/permissions/zh.json';
|
|
|
|
|
|
import permissionsEn from './locales/permissions/en.json';
|
2026-03-19 01:12:17 +08:00
|
|
|
|
|
|
|
|
|
|
type PermissionKey =
|
|
|
|
|
|
| 'microphone'
|
|
|
|
|
|
| 'photos'
|
|
|
|
|
|
| 'camera'
|
|
|
|
|
|
| 'microphoneForVideo'
|
|
|
|
|
|
| 'faceId';
|
|
|
|
|
|
|
|
|
|
|
|
type LocaleMessages = {
|
|
|
|
|
|
permissions?: Partial<Record<PermissionKey, string>>;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
type PrivacyAccessedAPIType = {
|
|
|
|
|
|
NSPrivacyAccessedAPIType: string;
|
|
|
|
|
|
NSPrivacyAccessedAPITypeReasons: string[];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const LOCALES: Record<string, LocaleMessages> = {
|
2026-03-22 19:22:34 +08:00
|
|
|
|
zh: { ...zh, permissions: permissionsZh },
|
|
|
|
|
|
en: { ...en, permissions: permissionsEn },
|
2026-03-19 01:12:17 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const SUPPORTED_LOCALES = ['zh', 'en'] as const;
|
|
|
|
|
|
const PRIMARY_LOCALE = process.env.EXPO_PUBLIC_PRIMARY_LOCALE ?? 'zh';
|
feat: OpenTelemetry LGTM observability, dev tooling, and memoir UX fixes (#31)
* add staging ios app build script
* feat(api): add OpenTelemetry LGTM stack for local observability
Wire OTel traces, metrics, and logs through a collector to Tempo,
Prometheus, and Loki, with custom LLM instrumentation, dev compose overlay,
Grafana provisioning, env templates, and development.sh auto-start.
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat: expand observability, harden dev tooling, and fix expo staging UX
Add business and LLM Prometheus metrics with Grafana dashboards, alerting,
and a metrics verification script. Wire telemetry through adapters and core
LLM paths, and document the local LGTM workflow.
Fix development.sh for macOS bash 3.2, open Grafana and eval-web in Chrome,
and repair eval-web auto-open (unbound EVAL_WEB_BROWSER_SCHEDULED). Merge
internal-eval into the main dev script with improved compose handling.
Require EXPO_PUBLIC_* at build time, improve iOS HTTP ATS for staging IPs,
show memoir empty state instead of load errors when no chapters exist, and
add jest env setup plus chapter list response normalization.
Co-authored-by: Cursor <cursoragent@cursor.com>
* chore: enable Grafana Assistant Cursor plugin
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix: memoir empty state and repair withdrawn 0020_chapters_book_id stamp
Show empty memoir UI when the chapter list succeeds with no items; treat auth/404 as non-fatal. Extend alembic revision repair so local dev DBs stamped with the removed 0020_chapters_book_id migration can roll back and upgrade to 0019.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Kevin <kevin@brighteng.org>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-20 15:12:21 +08:00
|
|
|
|
const API_BASE_URL = process.env.EXPO_PUBLIC_API_URL?.trim() ?? '';
|
|
|
|
|
|
const WS_BASE_URL = process.env.EXPO_PUBLIC_WS_URL?.trim() ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
if (!API_BASE_URL || !WS_BASE_URL) {
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
|
'[app.config] Missing EXPO_PUBLIC_API_URL or EXPO_PUBLIC_WS_URL. ' +
|
|
|
|
|
|
'Run `npm run use-env -- <development|staging|production>` in app-expo before prebuild or Metro.',
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-19 15:43:16 +08:00
|
|
|
|
const ALLOW_INSECURE_HTTP = API_BASE_URL.startsWith('http://');
|
|
|
|
|
|
|
|
|
|
|
|
const APP_VARIANT =
|
|
|
|
|
|
process.env.APP_VARIANT ??
|
|
|
|
|
|
process.env.EXPO_PUBLIC_APP_VARIANT ??
|
|
|
|
|
|
'development';
|
|
|
|
|
|
const IS_STAGING = APP_VARIANT === 'staging';
|
|
|
|
|
|
const IS_PRODUCTION = APP_VARIANT === 'production';
|
|
|
|
|
|
|
|
|
|
|
|
const IOS_BUNDLE_IDENTIFIER = IS_STAGING
|
|
|
|
|
|
? 'org.brighteng.lifecho.staging'
|
|
|
|
|
|
: IS_PRODUCTION
|
|
|
|
|
|
? 'org.brighteng.lifecho'
|
|
|
|
|
|
: 'com.anonymous.app-expo';
|
|
|
|
|
|
|
|
|
|
|
|
const ANDROID_PACKAGE = IS_STAGING
|
|
|
|
|
|
? 'org.brighteng.lifecho.staging'
|
|
|
|
|
|
: IS_PRODUCTION
|
|
|
|
|
|
? 'org.brighteng.lifecho'
|
|
|
|
|
|
: 'com.anonymous.appexpo';
|
|
|
|
|
|
|
|
|
|
|
|
const APP_DISPLAY_NAME = IS_STAGING ? 'Life Echo (Staging)' : 'Life Echo';
|
2026-03-19 01:12:17 +08:00
|
|
|
|
|
|
|
|
|
|
const PERMISSION_FALLBACKS: Record<PermissionKey, string> = {
|
|
|
|
|
|
microphone: 'Allow $(PRODUCT_NAME) to access your microphone.',
|
|
|
|
|
|
photos: 'Allow $(PRODUCT_NAME) to access your photos.',
|
|
|
|
|
|
camera: 'Allow $(PRODUCT_NAME) to access your camera.',
|
|
|
|
|
|
microphoneForVideo: 'Allow $(PRODUCT_NAME) to access your microphone.',
|
|
|
|
|
|
faceId: 'Allow $(PRODUCT_NAME) to access Face ID.',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* iOS privacy manifest required-reason APIs.
|
|
|
|
|
|
*
|
|
|
|
|
|
* These values are aggregated from the PrivacyInfo.xcprivacy files shipped by the
|
|
|
|
|
|
* Expo native modules currently used in this app, because Apple may not always
|
|
|
|
|
|
* correctly parse all static CocoaPods dependency manifests during submission.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Sources checked in node_modules:
|
|
|
|
|
|
* - expo-task-manager
|
|
|
|
|
|
* - expo-media-library
|
|
|
|
|
|
* - expo-localization
|
|
|
|
|
|
* - expo-file-system
|
|
|
|
|
|
* - expo-system-ui
|
|
|
|
|
|
* - expo-device
|
|
|
|
|
|
* - expo-constants
|
|
|
|
|
|
*/
|
|
|
|
|
|
const REQUIRED_PRIVACY_ACCESSED_API_TYPES: PrivacyAccessedAPIType[] = [
|
|
|
|
|
|
{
|
|
|
|
|
|
NSPrivacyAccessedAPIType: 'NSPrivacyAccessedAPICategoryUserDefaults',
|
|
|
|
|
|
NSPrivacyAccessedAPITypeReasons: ['CA92.1'],
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
NSPrivacyAccessedAPIType: 'NSPrivacyAccessedAPICategoryFileTimestamp',
|
|
|
|
|
|
NSPrivacyAccessedAPITypeReasons: ['0A2A.1', '3B52.1'],
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
NSPrivacyAccessedAPIType: 'NSPrivacyAccessedAPICategoryDiskSpace',
|
|
|
|
|
|
NSPrivacyAccessedAPITypeReasons: ['E174.1', '85F4.1'],
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
NSPrivacyAccessedAPIType: 'NSPrivacyAccessedAPICategorySystemBootTime',
|
|
|
|
|
|
NSPrivacyAccessedAPITypeReasons: ['35F9.1'],
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const localePermissions = LOCALES[PRIMARY_LOCALE]?.permissions ?? {};
|
|
|
|
|
|
|
|
|
|
|
|
function getPermissionMessage(key: PermissionKey): string {
|
|
|
|
|
|
return localePermissions[key] ?? PERMISSION_FALLBACKS[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function mergePrivacyAccessedApiTypes(
|
|
|
|
|
|
existing: PrivacyAccessedAPIType[] = [],
|
|
|
|
|
|
required: PrivacyAccessedAPIType[] = [],
|
|
|
|
|
|
): PrivacyAccessedAPIType[] {
|
|
|
|
|
|
const merged = new Map<string, Set<string>>();
|
|
|
|
|
|
|
|
|
|
|
|
for (const item of [...existing, ...required]) {
|
|
|
|
|
|
const reasons =
|
|
|
|
|
|
merged.get(item.NSPrivacyAccessedAPIType) ?? new Set<string>();
|
|
|
|
|
|
for (const reason of item.NSPrivacyAccessedAPITypeReasons) {
|
|
|
|
|
|
reasons.add(reason);
|
|
|
|
|
|
}
|
|
|
|
|
|
merged.set(item.NSPrivacyAccessedAPIType, reasons);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Array.from(merged.entries()).map(([apiType, reasons]) => ({
|
|
|
|
|
|
NSPrivacyAccessedAPIType: apiType,
|
|
|
|
|
|
NSPrivacyAccessedAPITypeReasons: Array.from(reasons),
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
export default ({ config }: ConfigContext): ExpoConfig => {
|
|
|
|
|
|
const existingPrivacyAccessedApiTypes = (config?.ios?.privacyManifests
|
|
|
|
|
|
?.NSPrivacyAccessedAPITypes ?? []) as PrivacyAccessedAPIType[];
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
...config,
|
2026-05-19 15:43:16 +08:00
|
|
|
|
name: APP_DISPLAY_NAME,
|
2026-03-23 11:33:02 +08:00
|
|
|
|
slug: 'life-echo',
|
2026-05-12 13:44:57 +08:00
|
|
|
|
version: '1.2.0',
|
2026-03-19 01:12:17 +08:00
|
|
|
|
orientation: 'portrait',
|
|
|
|
|
|
icon: './assets/images/icon.png',
|
2026-03-23 11:33:02 +08:00
|
|
|
|
scheme: 'lifeecho',
|
2026-03-19 01:12:17 +08:00
|
|
|
|
userInterfaceStyle: 'automatic',
|
|
|
|
|
|
ios: {
|
|
|
|
|
|
...config?.ios,
|
2026-03-23 10:25:51 +08:00
|
|
|
|
icon: './assets/images/icon.png',
|
2026-05-19 15:43:16 +08:00
|
|
|
|
bundleIdentifier: IOS_BUNDLE_IDENTIFIER,
|
2026-03-19 01:12:17 +08:00
|
|
|
|
config: {
|
|
|
|
|
|
usesNonExemptEncryption: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
infoPlist: {
|
|
|
|
|
|
...config?.ios?.infoPlist,
|
|
|
|
|
|
CFBundleAllowMixedLocalizations: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
privacyManifests: {
|
|
|
|
|
|
...config?.ios?.privacyManifests,
|
|
|
|
|
|
NSPrivacyAccessedAPITypes: mergePrivacyAccessedApiTypes(
|
|
|
|
|
|
existingPrivacyAccessedApiTypes,
|
|
|
|
|
|
REQUIRED_PRIVACY_ACCESSED_API_TYPES,
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
android: {
|
|
|
|
|
|
...config?.android,
|
2026-03-23 14:20:12 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* `resize` → `adjustResize`:键盘顶起时缩小窗口,聊天输入框随内容上移。
|
|
|
|
|
|
* 与 `KeyboardAvoidingView` + `behavior="height"` 叠用会重复处理,易错位(见 Expo Keyboard 指南)。
|
|
|
|
|
|
*/
|
|
|
|
|
|
softwareKeyboardLayoutMode: 'resize',
|
2026-03-20 16:36:42 +08:00
|
|
|
|
// Reverse-DNS; no hyphens (Android package name rules). Matches iOS bundle id intent.
|
2026-05-19 15:43:16 +08:00
|
|
|
|
package: ANDROID_PACKAGE,
|
2026-03-19 01:12:17 +08:00
|
|
|
|
adaptiveIcon: {
|
|
|
|
|
|
backgroundColor: '#E6F4FE',
|
|
|
|
|
|
foregroundImage: './assets/images/android-icon-foreground.png',
|
|
|
|
|
|
monochromeImage: './assets/images/android-icon-monochrome.png',
|
|
|
|
|
|
},
|
|
|
|
|
|
predictiveBackGestureEnabled: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
plugins: [
|
2026-03-20 17:25:42 +08:00
|
|
|
|
// CI/local release: android/app/keystore.properties + store file → release signing; -PversionName/-PversionCode
|
|
|
|
|
|
'./plugins/withAndroidReleaseSigning',
|
2026-05-09 16:16:48 +08:00
|
|
|
|
[
|
|
|
|
|
|
'./plugins/withAndroidCleartextTraffic',
|
2026-05-19 15:43:16 +08:00
|
|
|
|
{ enabled: ALLOW_INSECURE_HTTP },
|
2026-05-09 16:16:48 +08:00
|
|
|
|
],
|
feat: OpenTelemetry LGTM observability, dev tooling, and memoir UX fixes (#31)
* add staging ios app build script
* feat(api): add OpenTelemetry LGTM stack for local observability
Wire OTel traces, metrics, and logs through a collector to Tempo,
Prometheus, and Loki, with custom LLM instrumentation, dev compose overlay,
Grafana provisioning, env templates, and development.sh auto-start.
Co-authored-by: Cursor <cursoragent@cursor.com>
* feat: expand observability, harden dev tooling, and fix expo staging UX
Add business and LLM Prometheus metrics with Grafana dashboards, alerting,
and a metrics verification script. Wire telemetry through adapters and core
LLM paths, and document the local LGTM workflow.
Fix development.sh for macOS bash 3.2, open Grafana and eval-web in Chrome,
and repair eval-web auto-open (unbound EVAL_WEB_BROWSER_SCHEDULED). Merge
internal-eval into the main dev script with improved compose handling.
Require EXPO_PUBLIC_* at build time, improve iOS HTTP ATS for staging IPs,
show memoir empty state instead of load errors when no chapters exist, and
add jest env setup plus chapter list response normalization.
Co-authored-by: Cursor <cursoragent@cursor.com>
* chore: enable Grafana Assistant Cursor plugin
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix: memoir empty state and repair withdrawn 0020_chapters_book_id stamp
Show empty memoir UI when the chapter list succeeds with no items; treat auth/404 as non-fatal. Extend alembic revision repair so local dev DBs stamped with the removed 0020_chapters_book_id migration can roll back and upgrade to 0019.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Kevin <kevin@brighteng.org>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-20 15:12:21 +08:00
|
|
|
|
[
|
|
|
|
|
|
'./plugins/withIosInsecureHttp',
|
|
|
|
|
|
{
|
|
|
|
|
|
enabled: ALLOW_INSECURE_HTTP,
|
|
|
|
|
|
apiUrl: API_BASE_URL,
|
|
|
|
|
|
wsUrl: WS_BASE_URL,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2026-03-23 14:20:12 +08:00
|
|
|
|
'expo-router',
|
2026-03-19 01:12:17 +08:00
|
|
|
|
[
|
|
|
|
|
|
'expo-splash-screen',
|
|
|
|
|
|
{
|
2026-05-08 17:28:31 +08:00
|
|
|
|
// 与 android.adaptiveIcon.backgroundColor、品牌浅紫一致(见 scripts/generate-app-icon.sh,源图为 assets/logo.png)
|
2026-03-23 10:25:51 +08:00
|
|
|
|
backgroundColor: '#E6F4FE',
|
|
|
|
|
|
image: './assets/images/splash-icon.png',
|
|
|
|
|
|
resizeMode: 'contain',
|
|
|
|
|
|
imageWidth: 200,
|
2026-03-19 01:12:17 +08:00
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'expo-localization',
|
|
|
|
|
|
{
|
|
|
|
|
|
supportedLocales: {
|
|
|
|
|
|
ios: SUPPORTED_LOCALES,
|
|
|
|
|
|
android: SUPPORTED_LOCALES,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
'expo-asset',
|
|
|
|
|
|
[
|
|
|
|
|
|
'expo-audio',
|
|
|
|
|
|
{
|
|
|
|
|
|
microphonePermission: getPermissionMessage('microphone'),
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
[
|
|
|
|
|
|
'expo-image-picker',
|
|
|
|
|
|
{
|
|
|
|
|
|
photosPermission: getPermissionMessage('photos'),
|
|
|
|
|
|
cameraPermission: getPermissionMessage('camera'),
|
|
|
|
|
|
microphonePermission: getPermissionMessage('microphoneForVideo'),
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
'expo-image',
|
|
|
|
|
|
'expo-sqlite',
|
|
|
|
|
|
[
|
|
|
|
|
|
'expo-secure-store',
|
|
|
|
|
|
{
|
|
|
|
|
|
configureAndroidBackup: true,
|
|
|
|
|
|
faceIDPermission: getPermissionMessage('faceId'),
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
'expo-font',
|
|
|
|
|
|
],
|
|
|
|
|
|
locales: {
|
|
|
|
|
|
zh: './locales/zh.json',
|
|
|
|
|
|
en: './locales/en.json',
|
|
|
|
|
|
},
|
|
|
|
|
|
extra: {
|
|
|
|
|
|
...config?.extra,
|
|
|
|
|
|
supportsRTL: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
experiments: {
|
|
|
|
|
|
...config?.experiments,
|
|
|
|
|
|
typedRoutes: true,
|
|
|
|
|
|
reactCompiler: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|