@elizaos/app-core 2.0.0-beta.2 → 2.0.11-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-bridge.d.ts +27 -0
- package/agent-bridge.d.ts.map +1 -0
- package/agent-bridge.js +26 -0
- package/api/__tests__/sandbox-test-helpers.js +1 -1
- package/api/auth/audit.js +1 -1
- package/api/auth/auth-context.js +1 -1
- package/api/auth/bootstrap-token.js +2 -2
- package/api/auth/index.d.ts +9 -10
- package/api/auth/index.d.ts.map +1 -1
- package/api/auth/index.js +9 -10
- package/api/auth/passwords.js +2 -2
- package/api/auth/sensitive-rate-limit.d.ts +1 -4
- package/api/auth/sensitive-rate-limit.d.ts.map +1 -1
- package/api/auth/sensitive-rate-limit.js +6 -6
- package/api/auth/sessions.js +2 -2
- package/api/auth-bootstrap-routes.d.ts +6 -13
- package/api/auth-bootstrap-routes.d.ts.map +1 -1
- package/api/auth-bootstrap-routes.js +14 -27
- package/api/auth-pairing-routes.d.ts +17 -0
- package/api/auth-pairing-routes.d.ts.map +1 -0
- package/api/auth-pairing-routes.js +300 -0
- package/api/auth-session-routes.d.ts.map +1 -1
- package/api/auth-session-routes.js +36 -15
- package/api/auth.d.ts +12 -19
- package/api/auth.d.ts.map +1 -1
- package/api/auth.js +32 -27
- package/api/automations-compat-routes.d.ts.map +1 -1
- package/api/automations-compat-routes.js +5 -5
- package/api/background-tasks-routes.d.ts +4 -0
- package/api/background-tasks-routes.d.ts.map +1 -0
- package/api/background-tasks-routes.js +63 -0
- package/api/catalog-routes.js +3 -3
- package/api/cloud-pair-route.d.ts +26 -0
- package/api/cloud-pair-route.d.ts.map +1 -0
- package/api/cloud-pair-route.js +222 -0
- package/api/cloud-voice-routes.d.ts +52 -0
- package/api/cloud-voice-routes.d.ts.map +1 -0
- package/api/cloud-voice-routes.js +50 -0
- package/api/compat-route-shared.d.ts +2 -2
- package/api/compat-route-shared.d.ts.map +1 -1
- package/api/compat-route-shared.js +11 -7
- package/api/credential-resolver.d.ts +2 -2
- package/api/credential-resolver.d.ts.map +1 -1
- package/api/credential-resolver.js +8 -2
- package/api/database-rows-compat-routes.d.ts.map +1 -1
- package/api/database-rows-compat-routes.js +69 -31
- package/api/dev-boot-history.d.ts +26 -0
- package/api/dev-boot-history.d.ts.map +1 -0
- package/api/dev-boot-history.js +69 -0
- package/api/dev-compat-routes.d.ts +5 -0
- package/api/dev-compat-routes.d.ts.map +1 -1
- package/api/dev-compat-routes.js +127 -4
- package/api/dev-console-log.d.ts +2 -2
- package/api/dev-console-log.d.ts.map +1 -1
- package/api/dev-console-log.js +8 -5
- package/api/dev-route-catalog.d.ts +58 -0
- package/api/dev-route-catalog.d.ts.map +1 -0
- package/api/dev-route-catalog.js +447 -0
- package/api/dev-stack.d.ts.map +1 -1
- package/api/dev-stack.js +6 -9
- package/api/first-run-routes.d.ts +4 -0
- package/api/first-run-routes.d.ts.map +1 -0
- package/api/first-run-routes.js +208 -0
- package/api/first-run-tts-route.d.ts +19 -0
- package/api/first-run-tts-route.d.ts.map +1 -0
- package/api/first-run-tts-route.js +59 -0
- package/api/internal-routes.d.ts +23 -0
- package/api/internal-routes.d.ts.map +1 -0
- package/api/internal-routes.js +203 -0
- package/api/ios-local-agent-transport.d.ts +36 -0
- package/api/ios-local-agent-transport.d.ts.map +1 -0
- package/api/ios-local-agent-transport.js +566 -0
- package/api/onboarding-voice-lines.d.ts +23 -0
- package/api/onboarding-voice-lines.d.ts.map +1 -0
- package/api/onboarding-voice-lines.js +8 -0
- package/api/perf-instrument.d.ts +43 -0
- package/api/perf-instrument.d.ts.map +1 -0
- package/api/perf-instrument.js +113 -0
- package/api/response.d.ts.map +1 -1
- package/api/response.js +14 -14
- package/api/runtime-mode-routes.d.ts.map +1 -1
- package/api/runtime-mode-routes.js +2 -2
- package/api/secrets-inventory-routes.js +2 -2
- package/api/secrets-manager-routes.d.ts +1 -1
- package/api/secrets-manager-routes.d.ts.map +1 -1
- package/api/secrets-manager-routes.js +9 -10
- package/api/sensitive-request-routes.d.ts.map +1 -1
- package/api/sensitive-request-routes.js +5 -5
- package/api/sensitive-request-store.d.ts +12 -3
- package/api/sensitive-request-store.d.ts.map +1 -1
- package/api/server-cors.d.ts.map +1 -1
- package/api/server-cors.js +13 -2
- package/api/server-first-run-helpers.d.ts +26 -0
- package/api/server-first-run-helpers.d.ts.map +1 -0
- package/api/server-first-run-helpers.js +271 -0
- package/api/server-security.js +1 -1
- package/api/server-startup.d.ts.map +1 -1
- package/api/server-startup.js +3 -4
- package/api/server-wallet-trade.js +1 -1
- package/api/server.d.ts +4 -4
- package/api/server.d.ts.map +1 -1
- package/api/server.js +222 -88
- package/api/setup-contract.d.ts +63 -0
- package/api/setup-contract.d.ts.map +1 -0
- package/api/setup-contract.js +39 -0
- package/api/training-benchmarks.d.ts +97 -0
- package/api/training-benchmarks.d.ts.map +1 -0
- package/api/training-benchmarks.js +307 -0
- package/api/workbench-compat-routes.js +2 -2
- package/benchmark/cerebras-autowire.d.ts +28 -0
- package/benchmark/cerebras-autowire.d.ts.map +1 -0
- package/benchmark/cerebras-autowire.js +62 -0
- package/benchmark/lifeops-bench-handler.d.ts +36 -0
- package/benchmark/lifeops-bench-handler.d.ts.map +1 -1
- package/benchmark/lifeops-bench-handler.js +63 -1
- package/benchmark/lifeops-fake-backend.d.ts +39 -0
- package/benchmark/lifeops-fake-backend.d.ts.map +1 -1
- package/benchmark/lifeops-fake-backend.js +993 -21
- package/benchmark/mock-plugin.d.ts.map +1 -1
- package/benchmark/mock-plugin.js +0 -24
- package/benchmark/plugin.d.ts +2 -1
- package/benchmark/plugin.d.ts.map +1 -1
- package/benchmark/plugin.js +989 -68
- package/benchmark/replay-capture.d.ts +2 -2
- package/benchmark/replay-capture.d.ts.map +1 -1
- package/benchmark/replay-capture.js +3 -3
- package/benchmark/server-utils.d.ts +162 -9
- package/benchmark/server-utils.d.ts.map +1 -1
- package/benchmark/server-utils.js +625 -62
- package/benchmark/server.d.ts.map +1 -1
- package/benchmark/server.js +1962 -118
- package/boot-profile.d.ts +3 -0
- package/boot-profile.d.ts.map +1 -0
- package/boot-profile.js +30 -0
- package/browser.d.ts +23 -1
- package/browser.d.ts.map +1 -1
- package/browser.js +20 -1
- package/cli/argv.js +1 -1
- package/cli/banner.js +1 -1
- package/cli/command-format.js +2 -2
- package/cli/doctor/checks.d.ts.map +1 -1
- package/cli/doctor/checks.js +6 -6
- package/cli/plugins-cli.d.ts.map +1 -1
- package/cli/plugins-cli.js +77 -32
- package/cli/profile.d.ts.map +1 -1
- package/cli/profile.js +5 -4
- package/cli/program/build-program.js +4 -4
- package/cli/program/command-registry.d.ts.map +1 -1
- package/cli/program/command-registry.js +13 -11
- package/cli/program/help.js +5 -5
- package/cli/program/preaction.js +5 -5
- package/cli/program/register.auth.d.ts.map +1 -1
- package/cli/program/register.auth.js +6 -12
- package/cli/program/register.capability-router.d.ts +29 -0
- package/cli/program/register.capability-router.d.ts.map +1 -0
- package/cli/program/register.capability-router.js +568 -0
- package/cli/program/register.config.js +1 -1
- package/cli/program/register.configure.d.ts.map +1 -1
- package/cli/program/register.configure.js +1 -1
- package/cli/program/register.dashboard.d.ts.map +1 -1
- package/cli/program/register.dashboard.js +6 -7
- package/cli/program/register.db.d.ts.map +1 -1
- package/cli/program/register.db.js +3 -4
- package/cli/program/register.doctor.js +7 -7
- package/cli/program/register.setup.d.ts.map +1 -1
- package/cli/program/register.setup.js +14 -10
- package/cli/program/register.start.d.ts.map +1 -1
- package/cli/program/register.start.js +5 -3
- package/cli/program/register.subclis.js +3 -3
- package/cli/program/register.update.d.ts +6 -0
- package/cli/program/register.update.d.ts.map +1 -1
- package/cli/program/register.update.js +58 -6
- package/cli/program.js +1 -1
- package/cli/run-main.js +4 -4
- package/config/app-config.d.ts +2 -0
- package/config/app-config.d.ts.map +1 -0
- package/config/app-config.js +1 -0
- package/connectors/capacitor-jsc.d.ts.map +1 -1
- package/connectors/capacitor-jsc.js +16 -10
- package/connectors/capacitor-quickjs.d.ts.map +1 -1
- package/connectors/capacitor-quickjs.js +18 -13
- package/connectors/capacitor-sqlite.d.ts.map +1 -1
- package/connectors/capacitor-sqlite.js +27 -12
- package/dispatch/approval-queue.d.ts +37 -0
- package/dispatch/approval-queue.d.ts.map +1 -0
- package/dispatch/approval-queue.js +25 -0
- package/dispatch/channel-registry.d.ts +30 -0
- package/dispatch/channel-registry.d.ts.map +1 -0
- package/dispatch/channel-registry.js +22 -0
- package/dispatch/connector-registry.d.ts +39 -0
- package/dispatch/connector-registry.d.ts.map +1 -0
- package/dispatch/connector-registry.js +24 -0
- package/dispatch/index.d.ts +14 -0
- package/dispatch/index.d.ts.map +1 -0
- package/dispatch/index.js +13 -0
- package/dispatch/send-policy.d.ts +36 -0
- package/dispatch/send-policy.d.ts.map +1 -0
- package/dispatch/send-policy.js +16 -0
- package/entry.js +28 -11
- package/first-run/first-run-config.d.ts +55 -0
- package/first-run/first-run-config.d.ts.map +1 -0
- package/first-run/first-run-config.js +178 -0
- package/first-run/runtime-target.d.ts +4 -0
- package/first-run/runtime-target.d.ts.map +1 -0
- package/first-run/runtime-target.js +13 -0
- package/index.d.ts +16 -3
- package/index.d.ts.map +1 -1
- package/index.js +57 -33
- package/package.json +159 -50
- package/packaging/debian/apt-repo-config/README.md +18 -0
- package/packaging/debian/apt-repo-config/conf/distributions +11 -0
- package/packaging/flatpak/README.md +26 -16
- package/packaging/flatpak/ai.elizaos.App.metainfo.xml +17 -12
- package/packaging/flatpak/ai.elizaos.App.store.yml +5 -5
- package/packaging/flatpak/ai.elizaos.App.yml +10 -24
- package/packaging/flatpak/elizaos-app-wrapper.store.sh +2 -2
- package/packaging/flatpak/generate-sources.sh +74 -0
- package/packaging/flatpak/node-sources.json +7930 -0
- package/packaging/inno/build-inno.ps1 +34 -9
- package/packaging/msix/AppxManifest.store.xml +1 -1
- package/packaging/msix/README.md +39 -19
- package/packaging/msix/build-msix.ps1 +44 -14
- package/packaging/snap/snapcraft.yaml +22 -21
- package/packaging/test-packaging.sh +2 -2
- package/permissions/types.d.ts +1 -1
- package/permissions/types.js +1 -1
- package/platform/elizaos-agent-browser-stub.d.ts +144 -0
- package/platform/elizaos-agent-browser-stub.d.ts.map +1 -0
- package/platform/elizaos-agent-browser-stub.js +158 -0
- package/platform/elizaos-plugin-elizacloud-browser-stub.d.ts +34 -0
- package/platform/elizaos-plugin-elizacloud-browser-stub.d.ts.map +1 -0
- package/platform/elizaos-plugin-elizacloud-browser-stub.js +51 -0
- package/platform/empty-node-module.d.ts +148 -0
- package/platform/empty-node-module.d.ts.map +1 -1
- package/platform/empty-node-module.js +140 -3
- package/platform/ios-runtime-backends.d.ts +83 -0
- package/platform/ios-runtime-backends.d.ts.map +1 -0
- package/platform/ios-runtime-backends.js +133 -0
- package/platform/ios-runtime-bridge.d.ts +15 -0
- package/platform/ios-runtime-bridge.d.ts.map +1 -0
- package/platform/ios-runtime-bridge.js +527 -0
- package/platform/native-library-policy.d.ts +23 -0
- package/platform/native-library-policy.d.ts.map +1 -0
- package/platform/native-library-policy.js +112 -0
- package/platform/native-plugin-entrypoints.d.ts +19 -0
- package/platform/native-plugin-entrypoints.d.ts.map +1 -0
- package/platform/native-plugin-entrypoints.js +29 -0
- package/platforms/android/README.md +68 -10
- package/platforms/android/app/build.gradle +268 -3
- package/platforms/android/app/capacitor.build.gradle +18 -1
- package/platforms/android/app/proguard-rules.pro +17 -2
- package/platforms/android/app/src/androidTest/java/ai/elizaos/app/ElizaOsInstrumentedTest.java +1 -1
- package/platforms/android/app/src/main/AndroidManifest.xml +334 -17
- package/platforms/android/app/src/main/assets/runners/eliza-tasks.js +177 -0
- package/platforms/android/app/src/main/elizavoice-jni/CMakeLists.txt +75 -0
- package/platforms/android/app/src/main/elizavoice-jni/elizavoice-jni.cpp +1045 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/AgentPlugin.java +111 -171
- package/platforms/android/app/src/main/java/ai/elizaos/app/AndroidVirtualizationBridge.java +284 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/BatteryOptimizationPlugin.java +95 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAccessibilityService.java +55 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAgentService.java +1198 -141
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAndroidSystemBridge.java +83 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaAssistActivity.java +50 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaBootReceiver.java +90 -8
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaBrowserActivity.java +2 -2
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaCalendarActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaCameraActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaClockActivity.java +2 -2
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaContactsActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaDialActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaInCallService.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaMmsReceiver.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaNativeBridge.java +22 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaNotificationListenerService.java +45 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaQuickActionsWidgetProvider.java +68 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaShareActivity.java +132 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaSmsComposeActivity.java +1 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaSmsGatewayService.java +268 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaSmsReceiver.java +12 -1
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaTasksWorker.java +194 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoiceCaptureService.java +198 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoiceNative.java +160 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoicePlugin.java +450 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaVoiceTileService.java +39 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/ElizaWorkScheduler.java +60 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/GatewayConnectionService.java +53 -19
- package/platforms/android/app/src/main/java/ai/elizaos/app/MainActivity.java +160 -33
- package/platforms/android/app/src/main/java/ai/elizaos/app/ResourceProbePlugin.java +169 -0
- package/platforms/android/app/src/main/java/ai/elizaos/app/VoiceCapturePlugin.java +119 -0
- package/platforms/android/app/src/main/res/drawable/eliza_widget_background.xml +10 -0
- package/platforms/android/app/src/main/res/drawable/eliza_widget_button_background.xml +13 -0
- package/platforms/android/app/src/main/res/drawable/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-hdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-mdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-xhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-xxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-land-xxxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-hdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-mdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-xhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-xxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/drawable-port-xxxhdpi/splash.png +0 -0
- package/platforms/android/app/src/main/res/layout/eliza_quick_actions_widget.xml +86 -0
- package/platforms/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +2 -1
- package/platforms/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +2 -1
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png +0 -0
- package/platforms/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/platforms/android/app/src/main/res/values/android_app_actions.xml +48 -0
- package/platforms/android/app/src/main/res/values/colors.xml +8 -0
- package/platforms/android/app/src/main/res/values/ic_launcher_background.xml +2 -2
- package/platforms/android/app/src/main/res/values/strings.xml +2 -2
- package/platforms/android/app/src/main/res/values/styles.xml +25 -1
- package/platforms/android/app/src/main/res/xml/eliza_accessibility_service.xml +9 -0
- package/platforms/android/app/src/main/res/xml/eliza_quick_actions_widget.xml +13 -0
- package/platforms/android/app/src/main/res/xml/shortcuts.xml +121 -0
- package/platforms/android/build.gradle +2 -2
- package/platforms/android/capacitor-cordova-android-plugins/build.gradle +9 -3
- package/platforms/android/capacitor-cordova-android-plugins/cordova.variables.gradle +6 -2
- package/platforms/android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml +7 -2
- package/platforms/android/capacitor-cordova-android-plugins/src/main/java/.gitkeep +0 -1
- package/platforms/android/capacitor.settings.gradle +66 -16
- package/platforms/android/gradle.properties +1 -0
- package/platforms/android/update-manifest/generate-manifest.mjs +97 -0
- package/platforms/android/update-manifest/schema.json +26 -0
- package/platforms/apple-store-entitlements.reviewed.json +155 -0
- package/platforms/electrobun/.generated/brand-config.json +3 -2
- package/platforms/electrobun/LICENSE +21 -0
- package/platforms/electrobun/README.md +15 -1
- package/platforms/electrobun/assets/appIcon.icns +0 -0
- package/platforms/electrobun/assets/appIcon.ico +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_128x128.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_128x128@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_16x16.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_16x16@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_256x256.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_256x256@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_32x32.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_32x32@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.iconset/icon_512x512.png +0 -0
- package/platforms/electrobun/assets/brand-config.json +6 -6
- package/platforms/electrobun/biome.json +9 -9
- package/platforms/electrobun/docs/capability-collapse-matrix.json +318 -0
- package/platforms/electrobun/docs/capability-collapse-matrix.md +129 -0
- package/platforms/electrobun/docs/capability-routing.md +86 -0
- package/platforms/electrobun/docs/convergence-audit.json +3505 -0
- package/platforms/electrobun/docs/convergence-audit.md +694 -0
- package/platforms/electrobun/docs/database-boot-policy.md +90 -0
- package/platforms/electrobun/docs/riscv64-port.md +175 -0
- package/platforms/electrobun/docs/startup-first-run-cleanup.md +18 -0
- package/platforms/electrobun/docs/trace-first-annotations.md +52 -0
- package/platforms/electrobun/docs/ui-boundary-audit.json +580 -0
- package/platforms/electrobun/docs/ui-boundary-audit.md +257 -0
- package/platforms/electrobun/electrobun.config.ts +592 -364
- package/platforms/electrobun/entitlements/JUSTIFICATIONS.md +141 -0
- package/platforms/electrobun/entitlements/README.md +34 -6
- package/platforms/electrobun/entitlements/mas-bun.entitlements +15 -0
- package/platforms/electrobun/entitlements/mas.entitlements +6 -4
- package/platforms/electrobun/native/macos/window-effects.mm +1522 -0
- package/platforms/electrobun/package.json +18 -12
- package/platforms/electrobun/remotes/fs/README.md +70 -0
- package/platforms/electrobun/remotes/fs/electrobun.config.ts +38 -0
- package/platforms/electrobun/remotes/fs/package.json +12 -0
- package/platforms/electrobun/remotes/fs/plugin.json +25 -0
- package/platforms/electrobun/remotes/fs/src/bun/errors.ts +57 -0
- package/platforms/electrobun/remotes/fs/src/bun/file-limits.ts +50 -0
- package/platforms/electrobun/remotes/fs/src/bun/fs-service.ts +389 -0
- package/platforms/electrobun/remotes/fs/src/bun/path-guard.ts +270 -0
- package/platforms/electrobun/remotes/fs/src/bun/protocol.ts +149 -0
- package/platforms/electrobun/remotes/fs/src/bun/worker.ts +174 -0
- package/platforms/electrobun/remotes/fs/src/dev/phase5-smoke.ts +171 -0
- package/platforms/electrobun/remotes/fs/src/web/index.html +8 -0
- package/platforms/electrobun/remotes/git/README.md +75 -0
- package/platforms/electrobun/remotes/git/electrobun.config.ts +44 -0
- package/platforms/electrobun/remotes/git/package.json +12 -0
- package/platforms/electrobun/remotes/git/plugin.json +31 -0
- package/platforms/electrobun/remotes/git/src/bun/errors.ts +69 -0
- package/platforms/electrobun/remotes/git/src/bun/git-command.ts +156 -0
- package/platforms/electrobun/remotes/git/src/bun/git-service.ts +446 -0
- package/platforms/electrobun/remotes/git/src/bun/operation-history.ts +124 -0
- package/platforms/electrobun/remotes/git/src/bun/protocol.ts +252 -0
- package/platforms/electrobun/remotes/git/src/bun/worker.ts +316 -0
- package/platforms/electrobun/remotes/git/src/dev/phase7-smoke.ts +141 -0
- package/platforms/electrobun/remotes/git/src/web/index.html +8 -0
- package/platforms/electrobun/remotes/local-model/README.md +138 -0
- package/platforms/electrobun/remotes/local-model/electrobun.config.ts +46 -0
- package/platforms/electrobun/remotes/local-model/package.json +12 -0
- package/platforms/electrobun/remotes/local-model/plugin.json +33 -0
- package/platforms/electrobun/remotes/local-model/src/bun/download-state.ts +115 -0
- package/platforms/electrobun/remotes/local-model/src/bun/eliza1-catalog.ts +425 -0
- package/platforms/electrobun/remotes/local-model/src/bun/errors.ts +74 -0
- package/platforms/electrobun/remotes/local-model/src/bun/hf-eliza1-client.ts +169 -0
- package/platforms/electrobun/remotes/local-model/src/bun/local-inference-api-client.ts +245 -0
- package/platforms/electrobun/remotes/local-model/src/bun/model-service.ts +490 -0
- package/platforms/electrobun/remotes/local-model/src/bun/protocol.ts +301 -0
- package/platforms/electrobun/remotes/local-model/src/bun/worker.ts +248 -0
- package/platforms/electrobun/remotes/local-model/src/dev/phase8-smoke.ts +117 -0
- package/platforms/electrobun/remotes/local-model/src/web/index.html +13 -0
- package/platforms/electrobun/remotes/pty/README.md +65 -0
- package/platforms/electrobun/remotes/pty/electrobun.config.ts +47 -0
- package/platforms/electrobun/remotes/pty/package.json +12 -0
- package/platforms/electrobun/remotes/pty/plugin.json +34 -0
- package/platforms/electrobun/remotes/pty/src/bun/errors.ts +57 -0
- package/platforms/electrobun/remotes/pty/src/bun/output-buffer.ts +127 -0
- package/platforms/electrobun/remotes/pty/src/bun/protocol.ts +192 -0
- package/platforms/electrobun/remotes/pty/src/bun/pty-service.ts +562 -0
- package/platforms/electrobun/remotes/pty/src/bun/worker.ts +218 -0
- package/platforms/electrobun/remotes/pty/src/dev/phase6-smoke.ts +127 -0
- package/platforms/electrobun/remotes/pty/src/web/index.html +8 -0
- package/platforms/electrobun/remotes/runtime/README.md +370 -0
- package/platforms/electrobun/remotes/runtime/electrobun.config.ts +48 -0
- package/platforms/electrobun/remotes/runtime/package.json +14 -0
- package/platforms/electrobun/remotes/runtime/plugin.json +30 -0
- package/platforms/electrobun/remotes/runtime/src/bun/api-client.ts +620 -0
- package/platforms/electrobun/remotes/runtime/src/bun/errors.ts +45 -0
- package/platforms/electrobun/remotes/runtime/src/bun/log-buffer.ts +33 -0
- package/platforms/electrobun/remotes/runtime/src/bun/protocol.ts +366 -0
- package/platforms/electrobun/remotes/runtime/src/bun/route-discovery.ts +419 -0
- package/platforms/electrobun/remotes/runtime/src/bun/runtime-manager.ts +423 -0
- package/platforms/electrobun/remotes/runtime/src/bun/sse-parser.ts +99 -0
- package/platforms/electrobun/remotes/runtime/src/bun/stream-manager.ts +887 -0
- package/platforms/electrobun/remotes/runtime/src/bun/worker.ts +1231 -0
- package/platforms/electrobun/remotes/runtime/src/dev/phase1-smoke.ts +34 -0
- package/platforms/electrobun/remotes/runtime/src/dev/phase2-smoke.ts +86 -0
- package/platforms/electrobun/remotes/runtime/src/dev/phase3-smoke.ts +141 -0
- package/platforms/electrobun/remotes/runtime/src/web/index.css +187 -0
- package/platforms/electrobun/remotes/runtime/src/web/index.html +76 -0
- package/platforms/electrobun/remotes/runtime/src/web/index.ts +192 -0
- package/platforms/electrobun/remotes/surface/README.md +201 -0
- package/platforms/electrobun/remotes/surface/electrobun.config.ts +38 -0
- package/platforms/electrobun/remotes/surface/package.json +12 -0
- package/platforms/electrobun/remotes/surface/plugin.json +28 -0
- package/platforms/electrobun/remotes/surface/src/bun/worker.ts +132 -0
- package/platforms/electrobun/remotes/surface/src/dev/phase4-smoke.ts +566 -0
- package/platforms/electrobun/remotes/surface/src/protocol/event-types.ts +84 -0
- package/platforms/electrobun/remotes/surface/src/protocol/runtime-client.ts +673 -0
- package/platforms/electrobun/remotes/surface/src/web/app.ts +595 -0
- package/platforms/electrobun/remotes/surface/src/web/index.css +460 -0
- package/platforms/electrobun/remotes/surface/src/web/index.html +466 -0
- package/platforms/electrobun/remotes/surface/src/web/index.ts +5 -0
- package/platforms/electrobun/remotes/surface/src/web/render.ts +455 -0
- package/platforms/electrobun/remotes/surface/src/web/state.ts +427 -0
- package/platforms/electrobun/scripts/build-macos-effects.sh +4 -0
- package/platforms/electrobun/scripts/ensure-build-folder.ts +28 -0
- package/platforms/electrobun/scripts/ensure-whisper-gguf.sh +55 -0
- package/platforms/electrobun/scripts/ensure-whisper-model.sh +22 -80
- package/platforms/electrobun/scripts/generate-convergence-audit.ts +1203 -0
- package/platforms/electrobun/scripts/local-adhoc-sign-macos.ts +159 -159
- package/platforms/electrobun/scripts/postwrap-diagnostics.ts +424 -339
- package/platforms/electrobun/scripts/postwrap-sign-runtime-macos.ts +302 -271
- package/platforms/electrobun/scripts/smoke-test-windows.ps1 +17 -16
- package/platforms/electrobun/scripts/smoke-test.sh +5 -7
- package/platforms/electrobun/scripts/sync-web-assets.mjs +13 -13
- package/platforms/electrobun/scripts/verify-rpc-handlers.ts +109 -110
- package/platforms/electrobun/scripts/verify-windows-installer-proof.ps1 +3 -8
- package/platforms/electrobun/src/__stubs__/bun-ffi.ts +31 -31
- package/platforms/electrobun/src/__stubs__/electrobun-bun.ts +1 -1
- package/platforms/electrobun/src/agent-ready-state.ts +8 -8
- package/platforms/electrobun/src/agent-reset-from-main.test.ts +162 -0
- package/platforms/electrobun/src/agent-reset-from-main.ts +62 -62
- package/platforms/electrobun/src/agent-status-rpc.test.ts +95 -0
- package/platforms/electrobun/src/agent-status-rpc.ts +156 -0
- package/platforms/electrobun/src/api-base.test.ts +247 -0
- package/platforms/electrobun/src/api-base.ts +202 -93
- package/platforms/electrobun/src/application-menu-action-registry.ts +9 -9
- package/platforms/electrobun/src/application-menu.ts +348 -348
- package/platforms/electrobun/src/background-notice.ts +36 -36
- package/platforms/electrobun/src/boot-progress.test.ts +188 -0
- package/platforms/electrobun/src/boot-progress.ts +111 -0
- package/platforms/electrobun/src/brand-config.test.ts +39 -0
- package/platforms/electrobun/src/brand-config.ts +141 -129
- package/platforms/electrobun/src/bridge/browser-tabs-renderer-registry.ts +28 -28
- package/platforms/electrobun/src/bridge/electrobun-boot-config.ts +42 -0
- package/platforms/electrobun/src/bridge/electrobun-crypto-ready.ts +120 -0
- package/platforms/electrobun/src/bridge/electrobun-direct-rpc.ts +342 -357
- package/platforms/electrobun/src/bridge/electrobun-stub.ts +13 -13
- package/platforms/electrobun/src/browser-workspace-bridge-server.ts +285 -243
- package/platforms/electrobun/src/cloud-auth-window.ts +136 -136
- package/platforms/electrobun/src/cloud-disconnect-from-main.ts +90 -90
- package/platforms/electrobun/src/config-and-auth-rpc.test.ts +256 -0
- package/platforms/electrobun/src/config-and-auth-rpc.ts +302 -0
- package/platforms/electrobun/src/conversations-and-character-rpc.test.ts +185 -0
- package/platforms/electrobun/src/conversations-and-character-rpc.ts +131 -0
- package/platforms/electrobun/src/dashboard-rpc.test.ts +200 -0
- package/platforms/electrobun/src/dashboard-rpc.ts +344 -0
- package/platforms/electrobun/src/database/database-lock.ts +141 -0
- package/platforms/electrobun/src/database/database-mode.ts +149 -0
- package/platforms/electrobun/src/database/database-recovery.ts +72 -0
- package/platforms/electrobun/src/database/database-snapshot.ts +190 -0
- package/platforms/electrobun/src/database/database.test.ts +196 -0
- package/platforms/electrobun/src/database/index.ts +5 -0
- package/platforms/electrobun/src/database/pglite-paths.ts +100 -0
- package/platforms/electrobun/src/desktop-deep-link-events.test.ts +30 -0
- package/platforms/electrobun/src/desktop-deep-link-events.ts +17 -0
- package/platforms/electrobun/src/desktop-http-request.test.ts +73 -73
- package/platforms/electrobun/src/desktop-http-request.ts +85 -85
- package/platforms/electrobun/src/desktop-pill-config.test.ts +27 -0
- package/platforms/electrobun/src/desktop-pill-config.ts +40 -0
- package/platforms/electrobun/src/desktop-test-bridge-server.ts +204 -204
- package/platforms/electrobun/src/desktop-tray-config.test.ts +87 -0
- package/platforms/electrobun/src/desktop-tray-config.ts +84 -0
- package/platforms/electrobun/src/devtools-layout.ts +41 -41
- package/platforms/electrobun/src/diagnostic-format.test.ts +71 -0
- package/platforms/electrobun/src/diagnostic-format.ts +75 -36
- package/platforms/electrobun/src/dynamic-view-rpc-schema.test.ts +37 -0
- package/platforms/electrobun/src/dynamic-views/README.md +44 -0
- package/platforms/electrobun/src/dynamic-views/demo/agent-run-trace.html +135 -0
- package/platforms/electrobun/src/dynamic-views/errors.ts +29 -0
- package/platforms/electrobun/src/dynamic-views/host.test.ts +353 -0
- package/platforms/electrobun/src/dynamic-views/host.ts +332 -0
- package/platforms/electrobun/src/dynamic-views/index.ts +57 -0
- package/platforms/electrobun/src/dynamic-views/kiosk-canvas.ts +89 -0
- package/platforms/electrobun/src/dynamic-views/registry.test.ts +139 -0
- package/platforms/electrobun/src/dynamic-views/registry.ts +196 -0
- package/platforms/electrobun/src/dynamic-views/session-manager.test.ts +355 -0
- package/platforms/electrobun/src/dynamic-views/session-manager.ts +348 -0
- package/platforms/electrobun/src/dynamic-views/types.ts +105 -0
- package/platforms/electrobun/src/electrobun-boot-config.test.ts +50 -0
- package/platforms/electrobun/src/electrobun-config.test.ts +62 -0
- package/platforms/electrobun/src/electrobun-crypto-ready.test.ts +65 -0
- package/platforms/electrobun/src/electrobun-window-options.ts +25 -0
- package/platforms/electrobun/src/extension-rpc.test.ts +88 -0
- package/platforms/electrobun/src/extension-rpc.ts +102 -0
- package/platforms/electrobun/src/fatal-shutdown.test.ts +10 -10
- package/platforms/electrobun/src/fatal-shutdown.ts +1 -1
- package/platforms/electrobun/src/first-party-remotes.test.ts +169 -0
- package/platforms/electrobun/src/first-party-remotes.ts +297 -0
- package/platforms/electrobun/src/first-run-rpc.test.ts +192 -0
- package/platforms/electrobun/src/first-run-rpc.ts +146 -0
- package/platforms/electrobun/src/floating-chat-window.ts +181 -181
- package/platforms/electrobun/src/inbox-rpc.test.ts +123 -0
- package/platforms/electrobun/src/inbox-rpc.ts +158 -0
- package/platforms/electrobun/src/index.ts +2555 -2096
- package/platforms/electrobun/src/kiosk-mode.ts +50 -0
- package/platforms/electrobun/src/launch/index.ts +4 -0
- package/platforms/electrobun/src/launch/launch-dynamic-view.ts +37 -0
- package/platforms/electrobun/src/launch/launch-orchestrator.test.ts +224 -0
- package/platforms/electrobun/src/launch/launch-orchestrator.ts +456 -0
- package/platforms/electrobun/src/launch/launch-store.test.ts +97 -0
- package/platforms/electrobun/src/launch/launch-store.ts +134 -0
- package/platforms/electrobun/src/launch/types.ts +103 -0
- package/platforms/electrobun/src/launch/views/launch-diagnostics.html +205 -0
- package/platforms/electrobun/src/lifecycle/agent-ready-publish.test.ts +50 -0
- package/platforms/electrobun/src/lifecycle/agent-ready-publish.ts +27 -0
- package/platforms/electrobun/src/lifecycle/api-base-owner.ts +42 -31
- package/platforms/electrobun/src/lifecycle/desktop-session-prime.ts +44 -44
- package/platforms/electrobun/src/logger.ts +14 -14
- package/platforms/electrobun/src/main-window-runtime.ts +83 -83
- package/platforms/electrobun/src/main-window-session.test.ts +109 -0
- package/platforms/electrobun/src/main-window-session.ts +87 -51
- package/platforms/electrobun/src/menu-reset-from-main.ts +158 -158
- package/platforms/electrobun/src/native/agent-env.test.ts +52 -0
- package/platforms/electrobun/src/native/agent-runtime-layout.test.ts +42 -0
- package/platforms/electrobun/src/native/agent-state-dir.test.ts +91 -0
- package/platforms/electrobun/src/native/agent.ts +2122 -1682
- package/platforms/electrobun/src/native/auth-bridge.test.ts +67 -0
- package/platforms/electrobun/src/native/auth-bridge.ts +464 -360
- package/platforms/electrobun/src/native/browser-workspace.ts +723 -471
- package/platforms/electrobun/src/native/camera.ts +50 -50
- package/platforms/electrobun/src/native/canvas.ts +444 -445
- package/platforms/electrobun/src/native/credentials.ts +673 -616
- package/platforms/electrobun/src/native/desktop-window.test.ts +300 -0
- package/platforms/electrobun/src/native/desktop.ts +2196 -2156
- package/platforms/electrobun/src/native/editor-bridge.ts +201 -201
- package/platforms/electrobun/src/native/file-watcher.ts +154 -154
- package/platforms/electrobun/src/native/gateway.ts +179 -180
- package/platforms/electrobun/src/native/gpu-window.ts +256 -256
- package/platforms/electrobun/src/native/index.ts +76 -74
- package/platforms/electrobun/src/native/location.test.ts +44 -0
- package/platforms/electrobun/src/native/location.ts +90 -80
- package/platforms/electrobun/src/native/loopback-port.ts +60 -60
- package/platforms/electrobun/src/native/mac-window-effects.ts +166 -104
- package/platforms/electrobun/src/native/music-player.ts +38 -38
- package/platforms/electrobun/src/native/permissions-shared.ts +249 -150
- package/platforms/electrobun/src/native/permissions.ts +301 -208
- package/platforms/electrobun/src/native/power-state.ts +129 -129
- package/platforms/electrobun/src/native/remote-plugin-host.test.ts +1394 -0
- package/platforms/electrobun/src/native/remote-plugin-host.ts +1531 -0
- package/platforms/electrobun/src/native/screencapture.ts +667 -573
- package/platforms/electrobun/src/native/steward.ts +207 -204
- package/platforms/electrobun/src/native/swabble.ts +68 -324
- package/platforms/electrobun/src/native/talkmode.ts +253 -422
- package/platforms/electrobun/src/native/webgpu-browser-support.test.ts +18 -0
- package/platforms/electrobun/src/native/webgpu-browser-support.ts +165 -147
- package/platforms/electrobun/src/native/whisper-env.test.ts +71 -0
- package/platforms/electrobun/src/native/whisper-env.ts +68 -0
- package/platforms/electrobun/src/native-onboarding.ts +270 -0
- package/platforms/electrobun/src/onboarding-overlay-window.ts +141 -0
- package/platforms/electrobun/src/persisted-deployment.ts +91 -0
- package/platforms/electrobun/src/pill-window.test.ts +91 -0
- package/platforms/electrobun/src/pill-window.ts +99 -0
- package/platforms/electrobun/src/preload-validation.ts +44 -44
- package/platforms/electrobun/src/preload.js +1 -1
- package/platforms/electrobun/src/print-electrobun-dev-settings-banner.ts +120 -120
- package/platforms/electrobun/src/renderer-api-proxy.test.ts +73 -0
- package/platforms/electrobun/src/renderer-api-proxy.ts +86 -0
- package/platforms/electrobun/src/renderer-static.test.ts +53 -0
- package/platforms/electrobun/src/renderer-static.ts +144 -57
- package/platforms/electrobun/src/rpc-handler-slices.ts +121 -0
- package/platforms/electrobun/src/rpc-handlers.test.ts +267 -0
- package/platforms/electrobun/src/rpc-handlers.ts +1306 -913
- package/platforms/electrobun/src/rpc-parse-utils.ts +57 -0
- package/platforms/electrobun/src/rpc-port-resolver.test.ts +45 -0
- package/platforms/electrobun/src/rpc-port-resolver.ts +31 -0
- package/platforms/electrobun/src/rpc-schema.ts +2556 -1619
- package/platforms/electrobun/src/runtime-layout.ts +105 -105
- package/platforms/electrobun/src/runtime-permissions.ts +95 -95
- package/platforms/electrobun/src/runtime-rpc.test.ts +126 -0
- package/platforms/electrobun/src/runtime-rpc.ts +237 -0
- package/platforms/electrobun/src/screenshot-dev-server.ts +87 -87
- package/platforms/electrobun/src/settings-mutations-rpc.test.ts +193 -0
- package/platforms/electrobun/src/settings-mutations-rpc.ts +220 -0
- package/platforms/electrobun/src/startup-trace.ts +274 -270
- package/platforms/electrobun/src/subscription-rpc.test.ts +89 -0
- package/platforms/electrobun/src/subscription-rpc.ts +192 -0
- package/platforms/electrobun/src/surface-windows.test.ts +355 -0
- package/platforms/electrobun/src/surface-windows.ts +410 -410
- package/platforms/electrobun/src/trace/README.md +73 -0
- package/platforms/electrobun/src/trace/errors.ts +21 -0
- package/platforms/electrobun/src/trace/index.ts +40 -0
- package/platforms/electrobun/src/trace/trace-dynamic-view.ts +40 -0
- package/platforms/electrobun/src/trace/trace-host-requests.ts +473 -0
- package/platforms/electrobun/src/trace/trace-service.test.ts +186 -0
- package/platforms/electrobun/src/trace/trace-service.ts +324 -0
- package/platforms/electrobun/src/trace/trace-store.test.ts +141 -0
- package/platforms/electrobun/src/trace/trace-store.ts +551 -0
- package/platforms/electrobun/src/trace/types.ts +250 -0
- package/platforms/electrobun/src/trace/views/agent-run-trace.html +311 -0
- package/platforms/electrobun/src/types/web-speech.d.ts +28 -28
- package/platforms/electrobun/src/types.ts +5 -5
- package/platforms/electrobun/src/update-availability.test.ts +72 -0
- package/platforms/electrobun/src/update-availability.ts +90 -0
- package/platforms/electrobun/src/update-rpc.test.ts +83 -0
- package/platforms/electrobun/src/update-rpc.ts +123 -0
- package/platforms/electrobun/src/voice/README.md +184 -0
- package/platforms/electrobun/src/voice/errors.ts +42 -0
- package/platforms/electrobun/src/voice/index.ts +78 -0
- package/platforms/electrobun/src/voice/types.ts +316 -0
- package/platforms/electrobun/src/voice/voice-host-requests.ts +259 -0
- package/platforms/electrobun/src/voice/voice-latency-budget.test.ts +66 -0
- package/platforms/electrobun/src/voice/voice-latency-budget.ts +243 -0
- package/platforms/electrobun/src/voice/voice-live-validation.test.ts +352 -0
- package/platforms/electrobun/src/voice/voice-live-validation.ts +838 -0
- package/platforms/electrobun/src/voice/voice-pipeline.ts +250 -0
- package/platforms/electrobun/src/voice/voice-playback-adapter.ts +31 -0
- package/platforms/electrobun/src/voice/voice-runtime-adapter.test.ts +213 -0
- package/platforms/electrobun/src/voice/voice-runtime-adapter.ts +686 -0
- package/platforms/electrobun/src/voice/voice-service.test.ts +561 -0
- package/platforms/electrobun/src/voice/voice-service.ts +1027 -0
- package/platforms/electrobun/src/voice/voice-stream-coordinator.test.ts +115 -0
- package/platforms/electrobun/src/voice/voice-stream-coordinator.ts +270 -0
- package/platforms/electrobun/src/voice/voice-trace.ts +97 -0
- package/platforms/electrobun/src/voice/voice-tts-chunker.test.ts +91 -0
- package/platforms/electrobun/src/voice/voice-tts-chunker.ts +194 -0
- package/platforms/electrobun/src/windows-cef-profile.ts +88 -88
- package/platforms/electrobun/tsconfig.json +73 -13
- package/platforms/electrobun/update-channels.json +22 -0
- package/platforms/electrobun/vitest.electrobun.config.ts +72 -42
- package/platforms/ios/App/App/App.entitlements +4 -0
- package/platforms/ios/App/App/AppDelegate.swift +80 -18
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ios-marketing-1024.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20x20@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-20x20@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29x29@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-29x29@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40x40@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-40x40@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76x76@1x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-76x76@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-ipad-83_5x83_5@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20x20@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-20x20@3x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29x29@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-29x29@3x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40x40@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-40x40@3x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60x60@2x.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-iphone-60x60@3x.png +0 -0
- package/platforms/ios/App/App/Base.lproj/LaunchScreen.storyboard +1 -4
- package/platforms/ios/App/App/ComputerUseBridge.swift +589 -0
- package/platforms/ios/App/App/DeviceActivityMonitorExtension/DeviceActivityMonitorExtension.entitlements +12 -0
- package/platforms/ios/App/App/DeviceActivityMonitorExtension/DeviceActivityMonitorExtension.swift +34 -0
- package/platforms/ios/App/App/DeviceActivityMonitorExtension/Info.plist +29 -0
- package/platforms/ios/App/App/DeviceActivityReportExtension/DeviceActivityReportExtension.entitlements +12 -0
- package/platforms/ios/App/App/DeviceActivityReportExtension/DeviceActivityReportExtension.swift +53 -0
- package/platforms/ios/App/App/DeviceActivityReportExtension/Info.plist +27 -0
- package/platforms/ios/App/App/ElizaAppIntents.swift +183 -0
- package/platforms/ios/App/App/ElizaIntentPlugin.swift +342 -5
- package/platforms/ios/App/App/Info.plist +17 -1
- package/platforms/ios/App/App/runners/eliza-tasks.js +177 -0
- package/platforms/ios/App/App.xcodeproj/project.pbxproj +262 -6
- package/platforms/ios/App/BroadcastExtension/SampleHandler.swift +100 -0
- package/platforms/ios/App/Podfile +5 -0
- package/platforms/ios/App/Podfile.lock +83 -59
- package/register-runtime-hooks.js +11 -5
- package/registry/app-registry.d.ts +14 -0
- package/registry/app-registry.d.ts.map +1 -0
- package/registry/app-registry.js +29 -0
- package/registry/entries/apps/app-polymarket.json +31 -0
- package/registry/entries/apps/clawville.json +27 -0
- package/registry/entries/apps/companion.json +28 -0
- package/registry/entries/apps/database-viewer.json +27 -0
- package/registry/entries/apps/defense-of-the-agents.json +27 -0
- package/registry/entries/apps/documents.json +30 -0
- package/registry/entries/apps/feed.json +27 -0
- package/registry/entries/apps/hyperliquid.json +31 -0
- package/registry/entries/apps/log-viewer.json +27 -0
- package/registry/entries/apps/memory-viewer.json +27 -0
- package/registry/entries/apps/model-tester.json +31 -0
- package/registry/entries/apps/plugin-viewer.json +27 -0
- package/registry/entries/apps/relationship-viewer.json +27 -0
- package/registry/entries/apps/runtime-debugger.json +27 -0
- package/registry/entries/apps/shopify.json +31 -0
- package/registry/entries/apps/skills-viewer.json +27 -0
- package/registry/entries/apps/steward.json +31 -0
- package/registry/entries/apps/training.json +54 -0
- package/registry/entries/apps/trajectory-viewer.json +27 -0
- package/registry/entries/apps/vincent.json +31 -0
- package/registry/entries/connectors/bluebubbles.json +99 -0
- package/registry/entries/connectors/bluesky.json +173 -0
- package/registry/entries/connectors/discord.json +119 -0
- package/registry/entries/connectors/farcaster.json +174 -0
- package/registry/entries/connectors/feishu.json +79 -0
- package/registry/entries/connectors/google-chat.json +120 -0
- package/registry/entries/connectors/google.json +82 -0
- package/registry/entries/connectors/imessage.json +96 -0
- package/registry/entries/connectors/instagram.json +64 -0
- package/registry/entries/connectors/line.json +86 -0
- package/registry/entries/connectors/matrix.json +94 -0
- package/registry/entries/connectors/mattermost.json +110 -0
- package/registry/entries/connectors/msteams.json +104 -0
- package/registry/entries/connectors/nextcloud-talk.json +104 -0
- package/registry/entries/connectors/nostr.json +70 -0
- package/registry/entries/connectors/signal.json +81 -0
- package/registry/entries/connectors/slack.json +102 -0
- package/registry/entries/connectors/telegram.json +71 -0
- package/registry/entries/connectors/tlon.json +94 -0
- package/registry/entries/connectors/twitch.json +110 -0
- package/registry/entries/connectors/whatsapp.json +113 -0
- package/registry/entries/connectors/x.json +231 -0
- package/registry/entries/connectors/zalo.json +112 -0
- package/registry/entries/connectors/zalouser.json +122 -0
- package/registry/entries/plugins/agent-orchestrator.json +33 -0
- package/registry/entries/plugins/agent-skills.json +72 -0
- package/registry/entries/plugins/anthropic.json +73 -0
- package/registry/entries/plugins/app-control.json +23 -0
- package/registry/entries/plugins/auto-trader.json +203 -0
- package/registry/entries/plugins/background-runner.json +26 -0
- package/registry/entries/plugins/blooio.json +102 -0
- package/registry/entries/plugins/browser.json +75 -0
- package/registry/entries/plugins/cli.json +40 -0
- package/registry/entries/plugins/clipboard.json +44 -0
- package/registry/entries/plugins/coding-tools.json +71 -0
- package/registry/entries/plugins/commands.json +63 -0
- package/registry/entries/plugins/computeruse.json +74 -0
- package/registry/entries/plugins/copilot-proxy.json +93 -0
- package/registry/entries/plugins/directives.json +63 -0
- package/registry/entries/plugins/edge-tts.json +97 -0
- package/registry/entries/plugins/elevenlabs.json +169 -0
- package/registry/entries/plugins/elizacloud.json +208 -0
- package/registry/entries/plugins/evm.json +134 -0
- package/registry/entries/plugins/experience.json +34 -0
- package/registry/entries/plugins/facewear.json +131 -0
- package/registry/entries/plugins/form.json +26 -0
- package/registry/entries/plugins/github.json +93 -0
- package/registry/entries/plugins/gmail-watch.json +25 -0
- package/registry/entries/plugins/goals.json +77 -0
- package/registry/entries/plugins/google-genai.json +106 -0
- package/registry/entries/plugins/groq.json +93 -0
- package/registry/entries/plugins/hedera.json +48 -0
- package/registry/entries/plugins/inmemorydb.json +25 -0
- package/registry/entries/plugins/linear.json +51 -0
- package/registry/entries/plugins/local-inference.json +142 -0
- package/registry/entries/plugins/local-storage.json +36 -0
- package/registry/entries/plugins/localdb.json +25 -0
- package/registry/entries/plugins/mcp.json +44 -0
- package/registry/entries/plugins/memory.json +124 -0
- package/registry/entries/plugins/minecraft.json +79 -0
- package/registry/entries/plugins/moltbook.json +83 -0
- package/registry/entries/plugins/music.json +155 -0
- package/registry/entries/plugins/mysticism.json +48 -0
- package/registry/entries/plugins/nearai.json +82 -0
- package/registry/entries/plugins/ngrok.json +69 -0
- package/registry/entries/plugins/ollama.json +96 -0
- package/registry/entries/plugins/openai.json +189 -0
- package/registry/entries/plugins/openrouter.json +188 -0
- package/registry/entries/plugins/pdf.json +26 -0
- package/registry/entries/plugins/plugin-manager.json +23 -0
- package/registry/entries/plugins/prose.json +48 -0
- package/registry/entries/plugins/rlm.json +26 -0
- package/registry/entries/plugins/roblox.json +88 -0
- package/registry/entries/plugins/rss.json +64 -0
- package/registry/entries/plugins/s3-storage.json +91 -0
- package/registry/entries/plugins/scheduling.json +35 -0
- package/registry/entries/plugins/shell.json +94 -0
- package/registry/entries/plugins/social-alpha.json +72 -0
- package/registry/entries/plugins/tailscale.json +81 -0
- package/registry/entries/plugins/tee.json +53 -0
- package/registry/entries/plugins/todos.json +26 -0
- package/registry/entries/plugins/trajectory-logger.json +33 -0
- package/registry/entries/plugins/trust.json +39 -0
- package/registry/entries/plugins/tts.json +71 -0
- package/registry/entries/plugins/tunnel.json +45 -0
- package/registry/entries/plugins/twilio.json +168 -0
- package/registry/entries/plugins/vercel-ai-gateway.json +128 -0
- package/registry/entries/plugins/video.json +23 -0
- package/registry/entries/plugins/vision.json +43 -0
- package/registry/entries/plugins/webhooks.json +23 -0
- package/registry/entries/plugins/workflow.json +25 -0
- package/registry/entries/plugins/xai.json +75 -0
- package/registry/index.d.ts +2 -1
- package/registry/index.d.ts.map +1 -1
- package/registry/index.js +46 -12
- package/registry/loader.d.ts +2 -1
- package/registry/loader.d.ts.map +1 -1
- package/registry/loader.js +49 -2
- package/registry/schema.d.ts +244 -34
- package/registry/schema.d.ts.map +1 -1
- package/registry/schema.js +36 -0
- package/runtime/android-avf-microdroid-bridge.d.ts +29 -0
- package/runtime/android-avf-microdroid-bridge.d.ts.map +1 -0
- package/runtime/android-avf-microdroid-bridge.js +149 -0
- package/runtime/api-dev-settings-banner.d.ts.map +1 -1
- package/runtime/api-dev-settings-banner.js +5 -13
- package/runtime/app-core-runtime-hooks.d.ts +21 -0
- package/runtime/app-core-runtime-hooks.d.ts.map +1 -0
- package/runtime/app-core-runtime-hooks.js +10 -0
- package/runtime/autonomy-policy.d.ts +2 -0
- package/runtime/autonomy-policy.d.ts.map +1 -0
- package/runtime/autonomy-policy.js +4 -0
- package/runtime/desktop/AppWindowRenderer.d.ts +17 -0
- package/runtime/desktop/AppWindowRenderer.d.ts.map +1 -0
- package/runtime/desktop/AppWindowRenderer.js +360 -0
- package/runtime/desktop/DesktopSurfaceNavigationRuntime.d.ts +2 -0
- package/runtime/desktop/DesktopSurfaceNavigationRuntime.d.ts.map +1 -0
- package/runtime/desktop/DesktopSurfaceNavigationRuntime.js +41 -0
- package/runtime/desktop/DesktopTrayRuntime.d.ts +2 -0
- package/runtime/desktop/DesktopTrayRuntime.d.ts.map +1 -0
- package/runtime/desktop/DesktopTrayRuntime.js +174 -0
- package/runtime/desktop/DetachedShellRoot.d.ts +10 -0
- package/runtime/desktop/DetachedShellRoot.d.ts.map +1 -0
- package/runtime/desktop/DetachedShellRoot.js +111 -0
- package/runtime/desktop/index.d.ts +6 -0
- package/runtime/desktop/index.d.ts.map +1 -0
- package/runtime/desktop/index.js +5 -0
- package/runtime/desktop/tray-menu.d.ts +20 -0
- package/runtime/desktop/tray-menu.d.ts.map +1 -0
- package/runtime/desktop/tray-menu.js +143 -0
- package/runtime/dev-server.d.ts +1 -1
- package/runtime/dev-server.d.ts.map +1 -1
- package/runtime/dev-server.js +93 -17
- package/runtime/eliza.d.ts +75 -1
- package/runtime/eliza.d.ts.map +1 -1
- package/runtime/eliza.js +596 -122
- package/runtime/ensure-text-to-speech-handler.d.ts.map +1 -1
- package/runtime/ensure-text-to-speech-handler.js +10 -3
- package/runtime/mobile-safe-runtime.d.ts +181 -2
- package/runtime/mobile-safe-runtime.d.ts.map +1 -1
- package/runtime/mobile-safe-runtime.js +1019 -12
- package/runtime/mode/remote-forwarder.d.ts.map +1 -1
- package/runtime/mode/remote-forwarder.js +2 -2
- package/runtime/mode/route-mode-guard.d.ts +1 -2
- package/runtime/mode/route-mode-guard.d.ts.map +1 -1
- package/runtime/mode/route-mode-guard.js +4 -5
- package/runtime/mode/route-mode-matrix.d.ts.map +1 -1
- package/runtime/mode/route-mode-matrix.js +14 -1
- package/runtime/mode/runtime-mode.d.ts +1 -1
- package/runtime/mode/runtime-mode.d.ts.map +1 -1
- package/runtime/mode/runtime-mode.js +15 -4
- package/runtime/runtime-bootstrap-policy.d.ts.map +1 -1
- package/runtime/runtime-bootstrap-policy.js +14 -2
- package/runtime/telegram-standalone-handler.d.ts.map +1 -1
- package/runtime/telegram-standalone-handler.js +10 -9
- package/runtime/tts-cache-wiring.d.ts +29 -0
- package/runtime/tts-cache-wiring.d.ts.map +1 -0
- package/runtime/tts-cache-wiring.js +114 -0
- package/runtime/voice-warmup.d.ts +81 -0
- package/runtime/voice-warmup.d.ts.map +1 -0
- package/runtime/voice-warmup.js +111 -0
- package/scripts/android-sms-gateway-template.test.mjs +1014 -0
- package/scripts/aosp/README.md +19 -15
- package/scripts/aosp/compile-libllama.mjs +1344 -248
- package/scripts/aosp/compile-shim.mjs +47 -18
- package/scripts/aosp/deploy-pixel.mjs +405 -0
- package/scripts/aosp/lib/load-variant-config.mjs +3 -3
- package/scripts/aosp/llama-cpp-patches/README.md +8 -8
- package/scripts/aosp/llama-cpp-patches/apply-patches.mjs +23 -6
- package/scripts/aosp/llama-cpp-patches/polarquant/README.md +37 -0
- package/scripts/aosp/llama-cpp-patches/qjl/README.md +37 -0
- package/scripts/aosp/seccomp-shim/sigsys-handler-arm64.c +169 -0
- package/scripts/aosp/seccomp-shim/sigsys-handler-riscv64.c +217 -0
- package/scripts/aosp/smoke-cuttlefish.mjs +34 -4
- package/scripts/aosp/stage-default-models.mjs +18 -18
- package/scripts/aosp/variant-config-schema.ts +2 -2
- package/scripts/assert-required-bundled-packages.test.ts +534 -0
- package/scripts/audit-apple-store-sandbox.mjs +146 -0
- package/scripts/audit-live-test-surface.mjs +5 -2
- package/scripts/build-capacitor-app.mjs +21 -0
- package/scripts/build-flatpak.mjs +5 -5
- package/scripts/build-helpers/arm64-simd.mjs +72 -0
- package/scripts/build-helpers/omnivoice-merged.mjs +87 -0
- package/scripts/build-helpers/verify-fused-symbols.mjs +567 -0
- package/scripts/build-image.sh +1 -1
- package/scripts/build-llama-cpp-mtp.mjs +487 -0
- package/scripts/build-native-plugins.mjs +230 -18
- package/scripts/build-patched-electrobun-cli.mjs +68 -10
- package/scripts/build-win.mjs +1 -1
- package/scripts/bun-riscv64/Dockerfile +418 -0
- package/scripts/bun-riscv64/README.md +316 -0
- package/scripts/bun-riscv64/build.sh +469 -0
- package/scripts/bun-riscv64/bun-patches/0001-config-add-riscv64-arch.patch +74 -0
- package/scripts/bun-riscv64/bun-patches/0002-flags-add-riscv64-march-mabi.patch +16 -0
- package/scripts/bun-riscv64/bun-patches/0003-zig-add-riscv64-target-triple-and-cpu.patch +26 -0
- package/scripts/bun-riscv64/bun-patches/0004-webkit-force-local-mode-on-riscv64.patch +33 -0
- package/scripts/bun-riscv64/bun-patches/0005-tinycc-disable-on-riscv64.patch +16 -0
- package/scripts/bun-riscv64/bun-patches/0006-build-add-riscv64-cli-validation.patch +15 -0
- package/scripts/bun-riscv64/bun-patches/0007-deps-per-dep-riscv64-checks.patch +24 -0
- package/scripts/bun-riscv64/bun-patches/0008-source-stabilize-riscv64-musl-build.patch +226 -0
- package/scripts/bun-riscv64/bun-patches/0009-disable-wasm-streaming-hooks-for-c-loop.patch +162 -0
- package/scripts/bun-riscv64/bun-patches/0010-disable-inspector-profiler-for-riscv64-c-loop.patch +80 -0
- package/scripts/bun-riscv64/bun-patches/0011-process-arch-add-riscv64.patch +23 -0
- package/scripts/bun-riscv64/bun-patches/0012-cpu-features-add-riscv64-fallback.patch +13 -0
- package/scripts/bun-riscv64/bun-patches/0013-disable-console-inspector-hooks-for-riscv64-c-loop.patch +43 -0
- package/scripts/bun-riscv64/bun-patches/0014-disable-custom-inspector-dispatchers-on-riscv64.patch +127 -0
- package/scripts/bun-riscv64/bun-patches/0015-disable-jsc-profiler-builtins-on-riscv64.patch +75 -0
- package/scripts/bun-riscv64/bun-patches/0016-node-vm-disable-jit-cached-data-on-riscv64-c-loop.patch +96 -0
- package/scripts/bun-riscv64/bun-patches/0017-disable-performance-domjit-signature-on-riscv64-c-loop.patch +34 -0
- package/scripts/bun-riscv64/bun-patches/0018-fix-serialized-script-identifier-big-endian-path.patch +19 -0
- package/scripts/bun-riscv64/bun-patches/0019-add-wtf-timer-fire-bridge-for-c-loop.patch +24 -0
- package/scripts/bun-riscv64/bun-patches/0020-run-riscv64-smoke-test-under-qemu.patch +13 -0
- package/scripts/bun-riscv64/bun-patches/0021-fix-riscv64-linux-open-flags.patch +25 -0
- package/scripts/bun-riscv64/bun-patches/0022-zlib-riscv64-generic-kernels.patch +25 -0
- package/scripts/bun-riscv64/bun-patches/README.md +127 -0
- package/scripts/bun-riscv64/bun-version.json +202 -0
- package/scripts/bun-riscv64/run-build.sh +162 -0
- package/scripts/bun-riscv64/rust-core/0001-riscv64-rust-core-port.patch +868 -0
- package/scripts/bun-riscv64/rust-core/0002-second-wave-riscv64-source-gaps.patch +130 -0
- package/scripts/bun-riscv64/rust-core/0003-third-wave-riscv64-crash-handler-gaps.patch +78 -0
- package/scripts/bun-riscv64/rust-core/0004-rust-target-cpu-riscv64.patch +39 -0
- package/scripts/bun-riscv64/rust-core/0005-fifth-wave-riscv64-source-gaps.patch +96 -0
- package/scripts/bun-riscv64/rust-core/0006-cpp-wasm-and-inspector-guards-riscv64.patch +91 -0
- package/scripts/bun-riscv64/rust-core/0007-bun-alloc-max-align-t-riscv64.patch +36 -0
- package/scripts/bun-riscv64/rust-core/0008-workspace-lints-warn-not-deny-riscv64.patch +75 -0
- package/scripts/bun-riscv64/rust-core/0009-zigglobalobject-wasm-streaming-guards-riscv64.patch +109 -0
- package/scripts/bun-riscv64/rust-core/0010-tcc-externs-stub-on-riscv64.patch +62 -0
- package/scripts/bun-riscv64/rust-core/0011-clippy-ptr-cast-lints-warn-riscv64.patch +61 -0
- package/scripts/bun-riscv64/rust-core/README.md +80 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0003-disable-dfg-ftl-on-riscv64.patch +60 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0004-riscv64-do-not-force-wasm-in-c-loop.patch +31 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0005-domjit-effect-allow-no-dfg-c-loop.patch +40 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0006-disable-usewasm-when-webassembly-compiled-out.patch +33 -0
- package/scripts/bun-riscv64/rust-core/webkit-patches/0007-restore-dropped-includes-and-llint-fwd-decl.patch +31 -0
- package/scripts/bun-riscv64/validate.sh +264 -0
- package/scripts/bun-riscv64/webkit-patches/0001-cherry-pick-llint-riscv64.recipe +155 -0
- package/scripts/bun-riscv64/webkit-patches/0002-cherry-pick-baseline-jit-riscv64.recipe +40 -0
- package/scripts/bun-riscv64/webkit-patches/0003-disable-dfg-ftl-on-riscv64.patch +60 -0
- package/scripts/bun-riscv64/webkit-patches/0004-riscv64-do-not-force-wasm-in-c-loop.patch +31 -0
- package/scripts/bun-riscv64/webkit-patches/0005-domjit-effect-allow-no-dfg-c-loop.patch +40 -0
- package/scripts/bun-riscv64/webkit-patches/0006-disable-usewasm-when-webassembly-compiled-out.patch +33 -0
- package/scripts/bun-riscv64/webkit-patches/0007-restore-dropped-includes-and-llint-fwd-decl.patch +72 -0
- package/scripts/bun-riscv64/webkit-patches/README.md +146 -0
- package/scripts/check-homepage-public-readiness.mjs +353 -0
- package/scripts/check-homepage-release-data.mjs +110 -0
- package/scripts/check-i18n.mjs +2 -1
- package/scripts/check-real-local-chat.ts +147 -0
- package/scripts/check-real-local-provisioning.ts +104 -0
- package/scripts/check-real-local-reset.ts +249 -0
- package/scripts/check-sms-gateway-completion-audit.mjs +428 -0
- package/scripts/check-sms-gateway-readiness.mjs +266 -0
- package/scripts/clean-repo.mjs +5 -5
- package/scripts/codesign-mas.mjs +222 -16
- package/scripts/collect-docker-runtime-deps.mjs +229 -0
- package/scripts/continue-sms-gateway-work.mjs +121 -0
- package/scripts/copy-runtime-node-modules.ts +903 -195
- package/scripts/deploy-cloud-api-production-gateway.mjs +52 -0
- package/scripts/desktop-build.mjs +655 -101
- package/scripts/dev-platform.mjs +346 -102
- package/scripts/dev-startup-smoke.mjs +248 -0
- package/scripts/dev-ui.mjs +418 -176
- package/scripts/disable-local-eliza-workspace.mjs +35 -0
- package/scripts/docker-ci-smoke.sh +298 -96
- package/scripts/docker-entrypoint.sh +62 -1
- package/scripts/docker-entrypoint.test.ts +283 -0
- package/scripts/ensure-avatars.mjs +2 -2
- package/scripts/ensure-electrobun-core.mjs +1 -1
- package/scripts/ensure-generated-core-proto-js.mjs +1 -1
- package/scripts/ensure-type-package-aliases.mjs +62 -5
- package/scripts/ensure-vision-deps.mjs +20 -1
- package/scripts/entry.ts +1 -1
- package/scripts/ffi-stub/Makefile +64 -0
- package/scripts/ffi-stub/README.md +391 -0
- package/scripts/ffi-stub/asr-ffi-smoke.ts +139 -0
- package/scripts/ffi-stub/ffi-stub.c +539 -0
- package/scripts/ffi-stub/ffi.h +538 -0
- package/scripts/ffi-stub/libelizainference_stub.so +0 -0
- package/scripts/ffi-stub/tts-stream-ffi-smoke.ts +349 -0
- package/scripts/generate-first-run-voicelines.mjs +194 -0
- package/scripts/generate-plugin-index.js +4 -3
- package/scripts/generate-static-asset-manifest.mjs +1 -1
- package/scripts/i18n-dynamic-keys.json +5 -5
- package/scripts/init-submodules.mjs +2 -2
- package/scripts/install-android-sms-gateway.md +177 -0
- package/scripts/install-android-sms-gateway.mjs +1088 -0
- package/scripts/ios-xcframework/README.md +74 -72
- package/scripts/ios-xcframework/build-xcframework.mjs +204 -43
- package/scripts/ios-xcframework/run-physical-device-smoke.mjs +1943 -0
- package/scripts/ios-xcframework/runtime-symbol-shim.c +450 -0
- package/scripts/kernel-patches/cpu-polar-kernels.mjs +441 -0
- package/scripts/kernel-patches/cpu-simd-kernels.mjs +253 -0
- package/scripts/kernel-patches/cpu-thread-parallelism.mjs +368 -0
- package/scripts/kernel-patches/cuda-kernels.mjs +117 -0
- package/scripts/kernel-patches/metal-kernels.mjs +1698 -109
- package/scripts/kernel-patches/server-omnivoice-route.mjs +718 -0
- package/scripts/kernel-patches/server-structured-output.mjs +279 -0
- package/scripts/kernel-patches/vulkan-dispatch-log.mjs +166 -0
- package/scripts/kernel-patches/vulkan-dispatch-log.test.mjs +50 -0
- package/scripts/kernel-patches/vulkan-dispatch-patches/01-vulkan-shaders-gen.patch +30 -16
- package/scripts/kernel-patches/vulkan-dispatch-patches/02-ggml-vulkan-pipelines.patch +75 -30
- package/scripts/kernel-patches/vulkan-kernels.mjs +800 -49
- package/scripts/lib/agent-source-watcher.mjs +174 -0
- package/scripts/lib/agent-source-watcher.test.mjs +184 -0
- package/scripts/lib/api-supervisor.mjs +78 -9
- package/scripts/lib/api-supervisor.test.mjs +121 -0
- package/scripts/lib/app-dir.mjs +2 -16
- package/scripts/lib/apple-entitlement-audit.mjs +655 -0
- package/scripts/lib/apple-entitlement-audit.test.mjs +144 -0
- package/scripts/lib/bun-version-guard.mjs +13 -13
- package/scripts/lib/capacitor-plugin-build-needed.mjs +4 -3
- package/scripts/lib/capacitor-plugin-names.mjs +30 -14
- package/scripts/lib/desktop-preflight.mjs +9 -5
- package/scripts/lib/desktop-startup-embedding-warmup-policy.mjs +51 -0
- package/scripts/lib/desktop-startup-embedding-warmup-policy.test.mjs +55 -0
- package/scripts/lib/duet-bridge.d.mts +63 -0
- package/scripts/lib/duet-bridge.mjs +193 -0
- package/scripts/lib/node-path-env.mjs +4 -2
- package/scripts/lib/orchestrator-desktop-dev-banner.mjs +12 -3
- package/scripts/lib/patch-bun-exports.mjs +90 -27
- package/scripts/lib/patch-bun-exports.test.mjs +79 -0
- package/scripts/lib/renderer-build-action.mjs +35 -0
- package/scripts/lib/renderer-build-action.test.mjs +70 -0
- package/scripts/lib/stage-android-agent.mjs +748 -99
- package/scripts/lib/sync-eliza-env-aliases.mjs +3 -25
- package/scripts/lib/ui-smoke-stub-decision.mjs +33 -0
- package/scripts/lib/ui-smoke-stub-decision.test.mjs +46 -0
- package/scripts/lib/vite-renderer-dist-stale.mjs +5 -0
- package/scripts/lib/voice-latency-report.mjs +154 -0
- package/scripts/lifeops-prompt-benchmark.ts +21 -12
- package/scripts/link-docker-local-app-packages.mjs +89 -36
- package/scripts/local-stt-bench.ts +192 -0
- package/scripts/maintain-cloud-api-production-gateway.mjs +54 -0
- package/scripts/mas-smoke.mjs +459 -0
- package/scripts/mas-smoke.test.mjs +220 -0
- package/scripts/mobile-auth-simulator-smoke.mjs +0 -1
- package/scripts/normalize-eliza-capture.ts +97 -0
- package/scripts/omnivoice-fuse/prepare.mjs +2543 -23
- package/scripts/pack-upstreams.mjs +65 -5
- package/scripts/package-electrobun-linux.mjs +303 -0
- package/scripts/patch-deps.mjs +5 -3
- package/scripts/patches/llama-mobile-kokoro-tts.patch +480 -0
- package/scripts/playwright-ui-live-stack.ts +194 -49
- package/scripts/playwright-ui-smoke-api-stub.mjs +3501 -109
- package/scripts/pre-review-local.mjs +2 -2
- package/scripts/prepare-ios-cocoapods.sh +41 -3
- package/scripts/release-check.ts +180 -84
- package/scripts/release-workflow-drift.test.ts +57 -0
- package/scripts/relink-workspace-packages-to-dist.mjs +21 -4
- package/scripts/rt.mjs +16 -1
- package/scripts/run-biome-check.mjs +1 -1
- package/scripts/run-coding-agent-e2e.mjs +3 -3
- package/scripts/run-eliza-app-core-script.mjs +34 -0
- package/scripts/run-local-plugin-live-smoke.mjs +71 -2
- package/scripts/run-mobile-build-android-app-actions.test.mjs +426 -0
- package/scripts/run-mobile-build.mjs +4757 -607
- package/scripts/run-node-runtime.mjs +184 -7
- package/scripts/run-node-runtime.test.mjs +167 -0
- package/scripts/run-node-tsx.mjs +80 -33
- package/scripts/run-node.mjs +41 -1
- package/scripts/run-production-build.mjs +34 -27
- package/scripts/run-release-check.mjs +19 -0
- package/scripts/run-release-contract-suite.mjs +107 -14
- package/scripts/run-ui-smoke-playwright-suite.mjs +0 -2
- package/scripts/runtime-package-manifest.ts +21 -3
- package/scripts/setup-upstreams.mjs +42 -1
- package/scripts/sms-gateway-status.mjs +194 -0
- package/scripts/stage-android-agent.test.mjs +97 -0
- package/scripts/stage-elizavoice-lib.mjs +203 -0
- package/scripts/startup-integration-script-drift.test.ts +82 -4
- package/scripts/streaming-pipeline-bench.ts +543 -0
- package/scripts/sync-homepage-porkbun-dns.mjs +262 -0
- package/scripts/test-sms-gateway-software.mjs +100 -0
- package/scripts/type-audit.mjs +1 -1
- package/scripts/validate-bluebubbles-outbound.mjs +293 -0
- package/scripts/validate-cdn-assets.mjs +15 -7
- package/scripts/validate-regression-matrix.mjs +109 -8
- package/scripts/verify-android-sms-gateway-e2e.mjs +362 -0
- package/scripts/verify-bluebubbles-gateway-e2e.mjs +191 -0
- package/scripts/verify-bluebubbles-inbound-readiness.mjs +88 -0
- package/scripts/verify-cloud-api-production-deploy.mjs +87 -0
- package/scripts/verify-cloud-sms-onboarding-flow.mjs +336 -0
- package/scripts/voice/freeze-voice.mjs +521 -0
- package/scripts/voice-attribution-smoke.ts +538 -0
- package/scripts/voice-create-profile.mjs +379 -0
- package/scripts/voice-duet.mjs +1355 -0
- package/scripts/voice-e2e-hardware.ts +871 -0
- package/scripts/voice-interactive.mjs +1750 -0
- package/scripts/voice-latency-report.mjs +96 -0
- package/scripts/voice-latency-report.test.ts +176 -0
- package/scripts/voice-preset/build-default-voice-preset.mjs +249 -0
- package/scripts/voice-preset/build-onboarding-voice.mjs +281 -0
- package/scripts/watch-sms-gateway-readiness.mjs +303 -0
- package/scripts/write-homepage-release-data.mjs +458 -26
- package/security/agent-vault-id.d.ts +1 -1
- package/security/agent-vault-id.js +1 -1
- package/security/hydrate-wallet-keys-from-platform-store.d.ts.map +1 -1
- package/security/hydrate-wallet-keys-from-platform-store.js +23 -14
- package/security/platform-secure-store-node.d.ts +2 -2
- package/security/platform-secure-store-node.js +3 -3
- package/security/wallet-os-store-actions.d.ts +0 -9
- package/security/wallet-os-store-actions.d.ts.map +1 -1
- package/security/wallet-os-store-actions.js +3 -10
- package/services/account-pool.d.ts +23 -14
- package/services/account-pool.d.ts.map +1 -1
- package/services/account-pool.js +86 -24
- package/services/account-usage.d.ts.map +1 -1
- package/services/account-usage.js +2 -5
- package/services/ambient-audio/consent.d.ts +9 -0
- package/services/ambient-audio/consent.d.ts.map +1 -0
- package/services/ambient-audio/consent.js +28 -0
- package/services/ambient-audio/index.d.ts +7 -0
- package/services/ambient-audio/index.d.ts.map +1 -0
- package/services/ambient-audio/index.js +4 -0
- package/services/ambient-audio/replay-buffer.d.ts +14 -0
- package/services/ambient-audio/replay-buffer.d.ts.map +1 -0
- package/services/ambient-audio/replay-buffer.js +66 -0
- package/services/ambient-audio/response-gate.d.ts +3 -0
- package/services/ambient-audio/response-gate.d.ts.map +1 -0
- package/services/ambient-audio/response-gate.js +33 -0
- package/services/ambient-audio/service.d.ts +22 -0
- package/services/ambient-audio/service.d.ts.map +1 -0
- package/services/ambient-audio/service.js +47 -0
- package/services/ambient-audio/types.d.ts +42 -0
- package/services/ambient-audio/types.d.ts.map +1 -0
- package/services/app-updates/update-policy.d.ts +64 -0
- package/services/app-updates/update-policy.d.ts.map +1 -0
- package/services/app-updates/update-policy.js +228 -0
- package/services/auth-store.d.ts +37 -1
- package/services/auth-store.d.ts.map +1 -1
- package/services/auth-store.js +59 -26
- package/services/cloud-jwks-store.d.ts +3 -3
- package/services/cloud-jwks-store.d.ts.map +1 -1
- package/services/cloud-jwks-store.js +5 -8
- package/services/coding-account-bridge.d.ts +71 -0
- package/services/coding-account-bridge.d.ts.map +1 -0
- package/services/coding-account-bridge.js +267 -0
- package/services/connector-target-catalog.d.ts +10 -3
- package/services/connector-target-catalog.d.ts.map +1 -1
- package/services/connector-target-catalog.js +7 -4
- package/services/credential-tunnel-service.d.ts +66 -0
- package/services/credential-tunnel-service.d.ts.map +1 -0
- package/services/credential-tunnel-service.js +227 -0
- package/services/github-credentials.d.ts +1 -1
- package/services/github-credentials.js +1 -1
- package/services/inference-abort.d.ts +47 -0
- package/services/inference-abort.d.ts.map +1 -0
- package/services/inference-abort.js +76 -0
- package/services/persistence.d.ts +2 -3
- package/services/persistence.d.ts.map +1 -1
- package/services/persistence.js +2 -3
- package/services/phrase-chunked-tts.d.ts +136 -0
- package/services/phrase-chunked-tts.d.ts.map +1 -0
- package/services/phrase-chunked-tts.js +208 -0
- package/services/sandbox-registry.d.ts +78 -0
- package/services/sandbox-registry.d.ts.map +1 -0
- package/services/sandbox-registry.js +323 -0
- package/services/secrets-manager-installer.d.ts +8 -1
- package/services/secrets-manager-installer.d.ts.map +1 -1
- package/services/secrets-manager-installer.js +27 -2
- package/services/sensitive-requests/cloud-link-adapter.d.ts +15 -0
- package/services/sensitive-requests/cloud-link-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/cloud-link-adapter.js +73 -0
- package/services/sensitive-requests/index.d.ts +27 -0
- package/services/sensitive-requests/index.d.ts.map +1 -0
- package/services/sensitive-requests/index.js +51 -0
- package/services/sensitive-requests/instruct-dm-only-adapter.d.ts +14 -0
- package/services/sensitive-requests/instruct-dm-only-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/instruct-dm-only-adapter.js +22 -0
- package/services/sensitive-requests/owner-app-inline-adapter.d.ts +3 -0
- package/services/sensitive-requests/owner-app-inline-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/owner-app-inline-adapter.js +146 -0
- package/services/sensitive-requests/owner-app-oauth-adapter.d.ts +3 -0
- package/services/sensitive-requests/owner-app-oauth-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/owner-app-oauth-adapter.js +156 -0
- package/services/sensitive-requests/public-link-adapter.d.ts +14 -0
- package/services/sensitive-requests/public-link-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/public-link-adapter.js +86 -0
- package/services/sensitive-requests/tunnel-link-adapter.d.ts +17 -0
- package/services/sensitive-requests/tunnel-link-adapter.d.ts.map +1 -0
- package/services/sensitive-requests/tunnel-link-adapter.js +38 -0
- package/services/steward-credentials.d.ts +1 -1
- package/services/steward-credentials.d.ts.map +1 -1
- package/services/steward-credentials.js +10 -6
- package/services/steward-sidecar/health-check.d.ts.map +1 -1
- package/services/steward-sidecar/health-check.js +4 -3
- package/services/steward-sidecar/process-management.d.ts +1 -1
- package/services/steward-sidecar/process-management.d.ts.map +1 -1
- package/services/steward-sidecar/process-management.js +9 -3
- package/services/steward-sidecar/types.d.ts +1 -1
- package/services/steward-sidecar/types.d.ts.map +1 -1
- package/services/steward-sidecar/wallet-setup.d.ts.map +1 -1
- package/services/steward-sidecar/wallet-setup.js +8 -7
- package/services/steward-sidecar.d.ts +2 -2
- package/services/steward-sidecar.d.ts.map +1 -1
- package/services/steward-sidecar.js +27 -19
- package/services/task-host-capabilities.d.ts +60 -0
- package/services/task-host-capabilities.d.ts.map +1 -0
- package/services/task-host-capabilities.js +122 -0
- package/services/tool-call-cache/index.d.ts +2 -2
- package/services/tool-call-cache/index.d.ts.map +1 -1
- package/services/tool-call-cache/index.js +1 -1
- package/services/trigger-event-bridge.js +1 -1
- package/services/tunnel-to-mobile/index.d.ts +2 -0
- package/services/tunnel-to-mobile/index.d.ts.map +1 -0
- package/services/tunnel-to-mobile/index.js +1 -0
- package/services/tunnel-to-mobile/tunnel-to-mobile-client.d.ts +105 -0
- package/services/tunnel-to-mobile/tunnel-to-mobile-client.d.ts.map +1 -0
- package/services/tunnel-to-mobile/tunnel-to-mobile-client.js +190 -0
- package/services/vault-bootstrap.d.ts.map +1 -1
- package/services/vault-bootstrap.js +48 -21
- package/services/vault-mirror.d.ts +1 -1
- package/services/vault-mirror.d.ts.map +1 -1
- package/services/vault-mirror.js +29 -6
- package/services/voice-profiles/diarization-pipeline.d.ts +6 -0
- package/services/voice-profiles/diarization-pipeline.d.ts.map +1 -0
- package/services/voice-profiles/diarization-pipeline.js +20 -0
- package/services/voice-profiles/index.d.ts +12 -0
- package/services/voice-profiles/index.d.ts.map +1 -0
- package/services/voice-profiles/index.js +5 -0
- package/services/voice-profiles/nickname-evaluator.d.ts +14 -0
- package/services/voice-profiles/nickname-evaluator.d.ts.map +1 -0
- package/services/voice-profiles/nickname-evaluator.js +46 -0
- package/services/voice-profiles/owner-confidence.d.ts +10 -0
- package/services/voice-profiles/owner-confidence.d.ts.map +1 -0
- package/services/voice-profiles/owner-confidence.js +38 -0
- package/services/voice-profiles/private-challenge.d.ts +20 -0
- package/services/voice-profiles/private-challenge.d.ts.map +1 -0
- package/services/voice-profiles/private-challenge.js +44 -0
- package/services/voice-profiles/store.d.ts +21 -0
- package/services/voice-profiles/store.d.ts.map +1 -0
- package/services/voice-profiles/store.js +50 -0
- package/services/voice-profiles/types.d.ts +38 -0
- package/services/voice-profiles/types.d.ts.map +1 -0
- package/services/voice-profiles/types.js +1 -0
- package/styles/electrobun-mac-window-drag.css +4 -4
- package/test/helpers/__tests__/live-agent-test.smoke.test.ts +43 -70
- package/test/helpers/browser-mocks.ts +2 -2
- package/test/helpers/conditional-tests.ts +2 -2
- package/test/helpers/i18n.ts +1 -1
- package/test/helpers/live-agent-test.ts +537 -551
- package/test/helpers/live-provider.test.ts +4 -4
- package/test/helpers/live-provider.ts +41 -7
- package/test/helpers/live-runtime-server.ts +4 -4
- package/test/helpers/pglite-runtime.ts +1 -1
- package/test/helpers/real-runtime.ts +54 -15
- package/test/helpers/trajectory-harness.ts +11 -7
- package/test/scripts/start-eliza-live.ts +9 -0
- package/test/scripts/test-parallel.mjs +1 -1
- package/test/scripts/test-root-unit.mjs +6 -7
- package/ui-compat.d.ts +13 -2
- package/ui-compat.d.ts.map +1 -1
- package/ui-compat.js +19 -3
- package/api/auth-pairing-compat-routes.d.ts +0 -17
- package/api/auth-pairing-compat-routes.d.ts.map +0 -1
- package/api/auth-pairing-compat-routes.js +0 -301
- package/api/local-inference-compat-routes.d.ts +0 -16
- package/api/local-inference-compat-routes.d.ts.map +0 -1
- package/api/local-inference-compat-routes.js +0 -617
- package/api/onboarding-compat-routes.d.ts +0 -4
- package/api/onboarding-compat-routes.d.ts.map +0 -1
- package/api/onboarding-compat-routes.js +0 -207
- package/api/plugins-compat-routes.d.ts +0 -103
- package/api/plugins-compat-routes.d.ts.map +0 -1
- package/api/plugins-compat-routes.js +0 -1181
- package/api/server-onboarding-compat.d.ts +0 -31
- package/api/server-onboarding-compat.d.ts.map +0 -1
- package/api/server-onboarding-compat.js +0 -283
- package/benchmark/cua-routes.d.ts +0 -10
- package/benchmark/cua-routes.d.ts.map +0 -1
- package/benchmark/cua-routes.js +0 -179
- package/benchmark/mock-plugin-base.d.ts +0 -9
- package/benchmark/mock-plugin-base.d.ts.map +0 -1
- package/benchmark/mock-plugin-base.js +0 -325
- package/cli/parse-duration.d.ts +0 -5
- package/cli/parse-duration.d.ts.map +0 -1
- package/cli/parse-duration.js +0 -27
- package/patches/llama-cpp-capacitor@0.1.5.patch +0 -2387
- package/platform/agent-browser-stub.d.ts +0 -27
- package/platform/agent-browser-stub.d.ts.map +0 -1
- package/platform/agent-browser-stub.js +0 -16
- package/platforms/android/app/src/androidTest/java/com/getcapacitor/myapp/ExampleInstrumentedTest.java +0 -26
- package/platforms/android/app/src/main/res/drawable/ic_launcher_background.xml +0 -170
- package/platforms/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +0 -34
- package/platforms/android/app/src/test/java/com/getcapacitor/myapp/ExampleUnitTest.java +0 -18
- package/platforms/electrobun/assets/appIcon.iconset/icon_512x512@2x.png +0 -0
- package/platforms/electrobun/assets/appIcon.png +0 -0
- package/platforms/electrobun/scripts/build-whisper-universal.sh +0 -137
- package/platforms/electrobun/scripts/build-whisper.sh +0 -95
- package/platforms/electrobun/src/libMacWindowEffects.dylib +0 -0
- package/platforms/electrobun/src/native/whisper.ts +0 -280
- package/platforms/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-1.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732-2.png +0 -0
- package/platforms/ios/App/App/Assets.xcassets/Splash.imageset/splash-2732x2732.png +0 -0
- package/registry/generate-apps.d.ts +0 -2
- package/registry/generate-apps.d.ts.map +0 -1
- package/registry/generate-apps.js +0 -338
- package/registry/generate.d.ts +0 -2
- package/registry/generate.d.ts.map +0 -1
- package/registry/generate.js +0 -506
- package/runtime/embedding-manager-support.d.ts +0 -77
- package/runtime/embedding-manager-support.d.ts.map +0 -1
- package/runtime/embedding-manager-support.js +0 -309
- package/runtime/embedding-presets.d.ts +0 -5
- package/runtime/embedding-presets.d.ts.map +0 -1
- package/runtime/embedding-presets.js +0 -47
- package/runtime/embedding-warmup-policy.d.ts +0 -13
- package/runtime/embedding-warmup-policy.d.ts.map +0 -1
- package/runtime/embedding-warmup-policy.js +0 -33
- package/runtime/ensure-local-inference-handler.d.ts +0 -25
- package/runtime/ensure-local-inference-handler.d.ts.map +0 -1
- package/runtime/ensure-local-inference-handler.js +0 -389
- package/runtime/mobile-local-inference-gate.d.ts +0 -21
- package/runtime/mobile-local-inference-gate.d.ts.map +0 -1
- package/runtime/mobile-local-inference-gate.js +0 -24
- package/scripts/aosp/avd-test.mjs +0 -403
- package/scripts/aosp/boot-validate.mjs +0 -536
- package/scripts/aosp/build-aosp.mjs +0 -448
- package/scripts/aosp/build-bootanimation.mjs +0 -178
- package/scripts/aosp/capture-screens.mjs +0 -325
- package/scripts/aosp/e2e-validate.mjs +0 -225
- package/scripts/aosp/lint-init-rc.mjs +0 -258
- package/scripts/aosp/llama-shim/eliza_llama_shim.c +0 -276
- package/scripts/aosp/sim.mjs +0 -277
- package/scripts/aosp/sync-to-aosp.mjs +0 -134
- package/scripts/aosp/validate.mjs +0 -1273
- package/scripts/build-llama-cpp-dflash.mjs +0 -1866
- package/scripts/generate-onboarding-voicelines.mjs +0 -194
- package/scripts/generated/static-asset-manifest.json +0 -4
- package/scripts/normalize-parallax-capture.ts +0 -97
- package/scripts/omnivoice-fuse/Makefile +0 -44
- package/scripts/omnivoice-fuse/README.md +0 -266
- package/scripts/omnivoice-fuse/cmake-graft.mjs +0 -180
- package/scripts/omnivoice-fuse/ffi-stub.c +0 -222
- package/scripts/omnivoice-fuse/ffi.h +0 -158
- package/scripts/omnivoice-fuse/libelizainference_stub.dylib +0 -0
- package/scripts/omnivoice-fuse/verify-symbols.mjs +0 -138
- package/security/cloud-secret-store.d.ts +0 -34
- package/security/cloud-secret-store.d.ts.map +0 -1
- package/security/cloud-secret-store.js +0 -65
- package/security/export-guard.d.ts +0 -34
- package/security/export-guard.d.ts.map +0 -1
- package/security/export-guard.js +0 -127
- package/services/local-inference/__stress__/cache-stress-helpers.d.ts +0 -76
- package/services/local-inference/__stress__/cache-stress-helpers.d.ts.map +0 -1
- package/services/local-inference/__stress__/cache-stress-helpers.js +0 -238
- package/services/local-inference/active-model.d.ts +0 -180
- package/services/local-inference/active-model.d.ts.map +0 -1
- package/services/local-inference/active-model.js +0 -362
- package/services/local-inference/assignments.d.ts +0 -58
- package/services/local-inference/assignments.d.ts.map +0 -1
- package/services/local-inference/assignments.js +0 -179
- package/services/local-inference/backend.d.ts +0 -200
- package/services/local-inference/backend.d.ts.map +0 -1
- package/services/local-inference/backend.js +0 -242
- package/services/local-inference/bundled-models.d.ts +0 -34
- package/services/local-inference/bundled-models.d.ts.map +0 -1
- package/services/local-inference/bundled-models.js +0 -104
- package/services/local-inference/cache-bridge.d.ts +0 -184
- package/services/local-inference/cache-bridge.d.ts.map +0 -1
- package/services/local-inference/cache-bridge.js +0 -333
- package/services/local-inference/catalog.d.ts +0 -57
- package/services/local-inference/catalog.d.ts.map +0 -1
- package/services/local-inference/catalog.js +0 -262
- package/services/local-inference/conversation-registry.d.ts +0 -122
- package/services/local-inference/conversation-registry.d.ts.map +0 -1
- package/services/local-inference/conversation-registry.js +0 -182
- package/services/local-inference/device-bridge.d.ts +0 -139
- package/services/local-inference/device-bridge.d.ts.map +0 -1
- package/services/local-inference/device-bridge.js +0 -774
- package/services/local-inference/dflash-doctor.d.ts +0 -27
- package/services/local-inference/dflash-doctor.d.ts.map +0 -1
- package/services/local-inference/dflash-doctor.js +0 -149
- package/services/local-inference/dflash-server.d.ts +0 -248
- package/services/local-inference/dflash-server.d.ts.map +0 -1
- package/services/local-inference/dflash-server.js +0 -1076
- package/services/local-inference/downloader.d.ts +0 -48
- package/services/local-inference/downloader.d.ts.map +0 -1
- package/services/local-inference/downloader.js +0 -688
- package/services/local-inference/engine.d.ts +0 -282
- package/services/local-inference/engine.d.ts.map +0 -1
- package/services/local-inference/engine.js +0 -743
- package/services/local-inference/external-scanner.d.ts +0 -17
- package/services/local-inference/external-scanner.d.ts.map +0 -1
- package/services/local-inference/external-scanner.js +0 -261
- package/services/local-inference/handler-registry.d.ts +0 -72
- package/services/local-inference/handler-registry.d.ts.map +0 -1
- package/services/local-inference/handler-registry.js +0 -159
- package/services/local-inference/hardware.d.ts +0 -26
- package/services/local-inference/hardware.d.ts.map +0 -1
- package/services/local-inference/hardware.js +0 -139
- package/services/local-inference/hf-search.d.ts +0 -19
- package/services/local-inference/hf-search.d.ts.map +0 -1
- package/services/local-inference/hf-search.js +0 -169
- package/services/local-inference/index.d.ts +0 -10
- package/services/local-inference/index.d.ts.map +0 -1
- package/services/local-inference/index.js +0 -7
- package/services/local-inference/llama-server-metrics.d.ts +0 -108
- package/services/local-inference/llama-server-metrics.d.ts.map +0 -1
- package/services/local-inference/llama-server-metrics.js +0 -175
- package/services/local-inference/manifest/index.d.ts +0 -4
- package/services/local-inference/manifest/index.d.ts.map +0 -1
- package/services/local-inference/manifest/index.js +0 -5
- package/services/local-inference/manifest/schema.d.ts +0 -419
- package/services/local-inference/manifest/schema.d.ts.map +0 -1
- package/services/local-inference/manifest/schema.js +0 -227
- package/services/local-inference/manifest/types.d.ts +0 -23
- package/services/local-inference/manifest/types.d.ts.map +0 -1
- package/services/local-inference/manifest/types.js +0 -5
- package/services/local-inference/manifest/validator.d.ts +0 -43
- package/services/local-inference/manifest/validator.d.ts.map +0 -1
- package/services/local-inference/manifest/validator.js +0 -180
- package/services/local-inference/paths.d.ts +0 -8
- package/services/local-inference/paths.d.ts.map +0 -1
- package/services/local-inference/paths.js +0 -7
- package/services/local-inference/providers.d.ts +0 -61
- package/services/local-inference/providers.d.ts.map +0 -1
- package/services/local-inference/providers.js +0 -334
- package/services/local-inference/ram-budget.d.ts +0 -57
- package/services/local-inference/ram-budget.d.ts.map +0 -1
- package/services/local-inference/ram-budget.js +0 -107
- package/services/local-inference/readiness.d.ts +0 -9
- package/services/local-inference/readiness.d.ts.map +0 -1
- package/services/local-inference/readiness.js +0 -153
- package/services/local-inference/recommendation.d.ts +0 -62
- package/services/local-inference/recommendation.d.ts.map +0 -1
- package/services/local-inference/recommendation.js +0 -309
- package/services/local-inference/registry.d.ts +0 -35
- package/services/local-inference/registry.d.ts.map +0 -1
- package/services/local-inference/registry.js +0 -117
- package/services/local-inference/router-handler.d.ts +0 -51
- package/services/local-inference/router-handler.d.ts.map +0 -1
- package/services/local-inference/router-handler.js +0 -165
- package/services/local-inference/routing-policy.d.ts +0 -55
- package/services/local-inference/routing-policy.d.ts.map +0 -1
- package/services/local-inference/routing-policy.js +0 -195
- package/services/local-inference/routing-preferences.d.ts +0 -8
- package/services/local-inference/routing-preferences.d.ts.map +0 -1
- package/services/local-inference/routing-preferences.js +0 -7
- package/services/local-inference/service.d.ts +0 -88
- package/services/local-inference/service.d.ts.map +0 -1
- package/services/local-inference/service.js +0 -210
- package/services/local-inference/session-pool.d.ts +0 -72
- package/services/local-inference/session-pool.d.ts.map +0 -1
- package/services/local-inference/session-pool.js +0 -125
- package/services/local-inference/types.d.ts +0 -309
- package/services/local-inference/types.d.ts.map +0 -1
- package/services/local-inference/types.js +0 -23
- package/services/local-inference/verify.d.ts +0 -8
- package/services/local-inference/verify.d.ts.map +0 -1
- package/services/local-inference/verify.js +0 -7
- package/services/local-inference/voice/barge-in.d.ts +0 -15
- package/services/local-inference/voice/barge-in.d.ts.map +0 -1
- package/services/local-inference/voice/barge-in.js +0 -20
- package/services/local-inference/voice/engine-bridge.d.ts +0 -256
- package/services/local-inference/voice/engine-bridge.d.ts.map +0 -1
- package/services/local-inference/voice/engine-bridge.js +0 -398
- package/services/local-inference/voice/ffi-bindings.d.ts +0 -114
- package/services/local-inference/voice/ffi-bindings.d.ts.map +0 -1
- package/services/local-inference/voice/ffi-bindings.js +0 -281
- package/services/local-inference/voice/index.d.ts +0 -51
- package/services/local-inference/voice/index.d.ts.map +0 -1
- package/services/local-inference/voice/index.js +0 -50
- package/services/local-inference/voice/lifecycle.d.ts +0 -135
- package/services/local-inference/voice/lifecycle.d.ts.map +0 -1
- package/services/local-inference/voice/lifecycle.js +0 -189
- package/services/local-inference/voice/phoneme-tokenizer.d.ts +0 -58
- package/services/local-inference/voice/phoneme-tokenizer.d.ts.map +0 -1
- package/services/local-inference/voice/phoneme-tokenizer.js +0 -53
- package/services/local-inference/voice/phrase-cache.d.ts +0 -24
- package/services/local-inference/voice/phrase-cache.d.ts.map +0 -1
- package/services/local-inference/voice/phrase-cache.js +0 -32
- package/services/local-inference/voice/phrase-chunker.d.ts +0 -20
- package/services/local-inference/voice/phrase-chunker.d.ts.map +0 -1
- package/services/local-inference/voice/phrase-chunker.js +0 -85
- package/services/local-inference/voice/ring-buffer.d.ts +0 -40
- package/services/local-inference/voice/ring-buffer.d.ts.map +0 -1
- package/services/local-inference/voice/ring-buffer.js +0 -85
- package/services/local-inference/voice/rollback-queue.d.ts +0 -24
- package/services/local-inference/voice/rollback-queue.d.ts.map +0 -1
- package/services/local-inference/voice/rollback-queue.js +0 -49
- package/services/local-inference/voice/scheduler.d.ts +0 -47
- package/services/local-inference/voice/scheduler.d.ts.map +0 -1
- package/services/local-inference/voice/scheduler.js +0 -123
- package/services/local-inference/voice/shared-resources.d.ts +0 -119
- package/services/local-inference/voice/shared-resources.d.ts.map +0 -1
- package/services/local-inference/voice/shared-resources.js +0 -83
- package/services/local-inference/voice/speaker-preset-cache.d.ts +0 -28
- package/services/local-inference/voice/speaker-preset-cache.d.ts.map +0 -1
- package/services/local-inference/voice/speaker-preset-cache.js +0 -44
- package/services/local-inference/voice/types.d.ts +0 -80
- package/services/local-inference/voice/types.d.ts.map +0 -1
- package/services/local-inference/voice/voice-preset-format.d.ts +0 -56
- package/services/local-inference/voice/voice-preset-format.d.ts.map +0 -1
- package/services/local-inference/voice/voice-preset-format.js +0 -184
- package/services/plugin-installer.d.ts +0 -22
- package/services/plugin-installer.d.ts.map +0 -1
- package/services/plugin-installer.js +0 -41
- package/test/scripts/task-agent-live-smoke.ts +0 -1335
- /package/services/{local-inference/voice → ambient-audio}/types.js +0 -0
|
@@ -1,2387 +0,0 @@
|
|
|
1
|
-
diff --git a/LlamaCpp.podspec b/LlamaCpp.podspec
|
|
2
|
-
index fc84a44..35d9505 100644
|
|
3
|
-
--- a/LlamaCpp.podspec
|
|
4
|
-
+++ b/LlamaCpp.podspec
|
|
5
|
-
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
|
|
6
|
-
s.swift_version = '5.1'
|
|
7
|
-
|
|
8
|
-
# Include the native llama-cpp framework
|
|
9
|
-
- s.vendored_frameworks = 'ios/Frameworks/llama-cpp.framework'
|
|
10
|
-
+ s.vendored_frameworks = 'ios/Frameworks/LlamaCpp.framework'
|
|
11
|
-
end
|
|
12
|
-
diff --git a/LlamaCppCapacitor.podspec b/LlamaCppCapacitor.podspec
|
|
13
|
-
index 4b8af43..16b7823 100644
|
|
14
|
-
--- a/LlamaCppCapacitor.podspec
|
|
15
|
-
+++ b/LlamaCppCapacitor.podspec
|
|
16
|
-
@@ -16,8 +16,5 @@ Pod::Spec.new do |s|
|
|
17
|
-
s.swift_version = '5.1'
|
|
18
|
-
|
|
19
|
-
# Include the native llama-cpp framework
|
|
20
|
-
- s.vendored_frameworks = 'ios/Frameworks/llama-cpp.framework'
|
|
21
|
-
- s.pod_target_xcconfig = {
|
|
22
|
-
- 'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "$(PODS_TARGET_SRCROOT)/ios/Frameworks"'
|
|
23
|
-
- }
|
|
24
|
-
+ s.vendored_frameworks = 'ios/Frameworks-xcframework/LlamaCpp.xcframework'
|
|
25
|
-
end
|
|
26
|
-
diff --git a/android/build.gradle b/android/build.gradle
|
|
27
|
-
index 772361a..c76814f 100644
|
|
28
|
-
--- a/android/build.gradle
|
|
29
|
-
+++ b/android/build.gradle
|
|
30
|
-
@@ -18,7 +18,7 @@ buildscript {
|
|
31
|
-
apply plugin: 'com.android.library'
|
|
32
|
-
|
|
33
|
-
android {
|
|
34
|
-
- namespace "ai.annadata.plugin.capacitor"
|
|
35
|
-
+ namespace = "ai.annadata.plugin.capacitor"
|
|
36
|
-
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
37
|
-
defaultConfig {
|
|
38
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
39
|
-
@@ -35,21 +35,21 @@ android {
|
|
40
|
-
externalNativeBuild {
|
|
41
|
-
cmake {
|
|
42
|
-
path "src/main/CMakeLists.txt"
|
|
43
|
-
- version "3.22.1"
|
|
44
|
-
+ version = "3.22.1"
|
|
45
|
-
// Explicitly set NDK version to avoid Windows dependencies
|
|
46
|
-
- ndkVersion "29.0.13113456"
|
|
47
|
-
+ ndkVersion = "29.0.13113456"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
buildTypes {
|
|
52
|
-
release {
|
|
53
|
-
minifyEnabled false
|
|
54
|
-
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
55
|
-
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
lintOptions {
|
|
60
|
-
- abortOnError false
|
|
61
|
-
+ abortOnError = false
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
compileOptions {
|
|
65
|
-
diff --git a/android/src/main/jni.cpp b/android/src/main/jni.cpp
|
|
66
|
-
index 6377592..dd412fb 100644
|
|
67
|
-
--- a/android/src/main/jni.cpp
|
|
68
|
-
+++ b/android/src/main/jni.cpp
|
|
69
|
-
@@ -1481,19 +1481,22 @@ Java_ai_annadata_plugin_capacitor_LlamaCpp_embeddingNative(
|
|
70
|
-
if (params != nullptr) {
|
|
71
|
-
jclass jsObjectClass = env->GetObjectClass(params);
|
|
72
|
-
if (jsObjectClass != nullptr && !env->ExceptionCheck()) {
|
|
73
|
-
- // Try to get embd_normalize
|
|
74
|
-
- jmethodID getDoubleMethod = env->GetMethodID(jsObjectClass, "getDouble", "(Ljava/lang/String;)Ljava/lang/Double;");
|
|
75
|
-
- if (getDoubleMethod != nullptr && !env->ExceptionCheck()) {
|
|
76
|
-
+ // Capacitor 8 JSObject extends JSONObject and does not expose
|
|
77
|
-
+ // getDouble(String); use JSONObject's inherited optDouble
|
|
78
|
-
+ // signature so a missing helper cannot leave a pending JNI
|
|
79
|
-
+ // exception and abort the app after embedding completes.
|
|
80
|
-
+ jmethodID optDoubleMethod = env->GetMethodID(jsObjectClass, "optDouble", "(Ljava/lang/String;D)D");
|
|
81
|
-
+ if (env->ExceptionCheck()) {
|
|
82
|
-
+ env->ExceptionClear();
|
|
83
|
-
+ optDoubleMethod = nullptr;
|
|
84
|
-
+ }
|
|
85
|
-
+ if (optDoubleMethod != nullptr) {
|
|
86
|
-
jstring normalizeKey = jni_utils::string_to_jstring(env, "embd_normalize");
|
|
87
|
-
- jobject normalizeObj = env->CallObjectMethod(params, getDoubleMethod, normalizeKey);
|
|
88
|
-
- if (normalizeObj != nullptr && !env->ExceptionCheck()) {
|
|
89
|
-
- embd_normalize = env->CallDoubleMethod(normalizeObj,
|
|
90
|
-
- env->GetMethodID(env->FindClass("java/lang/Double"), "doubleValue", "()D"));
|
|
91
|
-
- env->DeleteLocalRef(normalizeObj);
|
|
92
|
-
- }
|
|
93
|
-
+ embd_normalize = env->CallDoubleMethod(params, optDoubleMethod, normalizeKey, embd_normalize);
|
|
94
|
-
env->DeleteLocalRef(normalizeKey);
|
|
95
|
-
if (env->ExceptionCheck()) {
|
|
96
|
-
env->ExceptionClear();
|
|
97
|
-
+ embd_normalize = 1.0;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
diff --git a/build-native.sh b/build-native.sh
|
|
102
|
-
index 8909b49..b07f9e4 100755
|
|
103
|
-
--- a/build-native.sh
|
|
104
|
-
+++ b/build-native.sh
|
|
105
|
-
@@ -112,15 +112,23 @@ build_ios() {
|
|
106
|
-
|
|
107
|
-
# CMake builds the framework directly (FRAMEWORK TRUE in CMakeLists.txt)
|
|
108
|
-
# Verify the framework was created
|
|
109
|
-
- if [ -d "llama-cpp.framework" ]; then
|
|
110
|
-
- print_success "iOS framework built successfully at: $(pwd)/llama-cpp.framework"
|
|
111
|
-
+ if [ -d "LlamaCpp.framework" ] || [ -d "llama-cpp.framework" ]; then
|
|
112
|
-
+ FRAMEWORK_DIR="LlamaCpp.framework"
|
|
113
|
-
+ if [ ! -d "$FRAMEWORK_DIR" ]; then
|
|
114
|
-
+ FRAMEWORK_DIR="llama-cpp.framework"
|
|
115
|
-
+ fi
|
|
116
|
-
+ print_success "iOS framework built successfully at: $(pwd)/$FRAMEWORK_DIR"
|
|
117
|
-
|
|
118
|
-
# Binary location: CMake may produce flat (llama-cpp) or Versions/A/ layout
|
|
119
|
-
BINARY=""
|
|
120
|
-
- if [ -f "llama-cpp.framework/llama-cpp" ]; then
|
|
121
|
-
- BINARY="llama-cpp.framework/llama-cpp"
|
|
122
|
-
- elif [ -f "llama-cpp.framework/Versions/A/llama-cpp" ]; then
|
|
123
|
-
- BINARY="llama-cpp.framework/Versions/A/llama-cpp"
|
|
124
|
-
+ if [ -f "$FRAMEWORK_DIR/LlamaCpp" ]; then
|
|
125
|
-
+ BINARY="$FRAMEWORK_DIR/LlamaCpp"
|
|
126
|
-
+ elif [ -f "$FRAMEWORK_DIR/Versions/A/LlamaCpp" ]; then
|
|
127
|
-
+ BINARY="$FRAMEWORK_DIR/Versions/A/LlamaCpp"
|
|
128
|
-
+ elif [ -f "$FRAMEWORK_DIR/llama-cpp" ]; then
|
|
129
|
-
+ BINARY="$FRAMEWORK_DIR/llama-cpp"
|
|
130
|
-
+ elif [ -f "$FRAMEWORK_DIR/Versions/A/llama-cpp" ]; then
|
|
131
|
-
+ BINARY="$FRAMEWORK_DIR/Versions/A/llama-cpp"
|
|
132
|
-
fi
|
|
133
|
-
if [ -n "$BINARY" ]; then
|
|
134
|
-
if xcrun strip -x -S "$BINARY" 2>/dev/null; then
|
|
135
|
-
@@ -134,12 +142,28 @@ build_ios() {
|
|
136
|
-
cd ../..
|
|
137
|
-
return 1
|
|
138
|
-
fi
|
|
139
|
-
- rm -rf ../Frameworks/llama-cpp.framework
|
|
140
|
-
- mkdir -p ../Frameworks/llama-cpp.framework/Resources
|
|
141
|
-
- cp "$BINARY" ../Frameworks/llama-cpp.framework/llama-cpp
|
|
142
|
-
- [ -f llama-cpp.framework/Info.plist ] && cp llama-cpp.framework/Info.plist ../Frameworks/llama-cpp.framework/
|
|
143
|
-
- [ -f llama-cpp.framework/Versions/A/Resources/Info.plist ] && cp llama-cpp.framework/Versions/A/Resources/Info.plist ../Frameworks/llama-cpp.framework/Resources/
|
|
144
|
-
- print_success "iOS framework copied to ios/Frameworks/ for npm package (flat, no duplication)"
|
|
145
|
-
+ rm -rf ../Frameworks/LlamaCpp.framework ../Frameworks/llama-cpp.framework
|
|
146
|
-
+ mkdir -p ../Frameworks/LlamaCpp.framework/Headers ../Frameworks/LlamaCpp.framework/Modules
|
|
147
|
-
+ cp "$BINARY" ../Frameworks/LlamaCpp.framework/LlamaCpp
|
|
148
|
-
+ if [ -f "$FRAMEWORK_DIR/Info.plist" ]; then
|
|
149
|
-
+ cp "$FRAMEWORK_DIR/Info.plist" ../Frameworks/LlamaCpp.framework/
|
|
150
|
-
+ elif [ -f "$FRAMEWORK_DIR/Versions/A/Resources/Info.plist" ]; then
|
|
151
|
-
+ cp "$FRAMEWORK_DIR/Versions/A/Resources/Info.plist" ../Frameworks/LlamaCpp.framework/
|
|
152
|
-
+ fi
|
|
153
|
-
+ if command -v plutil >/dev/null 2>&1 && [ -f ../Frameworks/LlamaCpp.framework/Info.plist ]; then
|
|
154
|
-
+ plutil -replace CFBundleExecutable -string LlamaCpp ../Frameworks/LlamaCpp.framework/Info.plist
|
|
155
|
-
+ plutil -replace CFBundleIdentifier -string com.arusatech.LlamaCpp ../Frameworks/LlamaCpp.framework/Info.plist
|
|
156
|
-
+ plutil -replace CFBundleName -string LlamaCpp ../Frameworks/LlamaCpp.framework/Info.plist
|
|
157
|
-
+ fi
|
|
158
|
-
+ printf '' > ../Frameworks/LlamaCpp.framework/Headers/LlamaCpp.h
|
|
159
|
-
+ printf 'framework module LlamaCpp {\n umbrella header "LlamaCpp.h"\n export *\n}\n' > ../Frameworks/LlamaCpp.framework/Modules/module.modulemap
|
|
160
|
-
+ if command -v install_name_tool >/dev/null 2>&1; then
|
|
161
|
-
+ install_name_tool -id @rpath/LlamaCpp.framework/LlamaCpp ../Frameworks/LlamaCpp.framework/LlamaCpp 2>/dev/null || true
|
|
162
|
-
+ fi
|
|
163
|
-
+ if command -v codesign >/dev/null 2>&1; then
|
|
164
|
-
+ codesign --remove-signature ../Frameworks/LlamaCpp.framework/LlamaCpp 2>/dev/null || true
|
|
165
|
-
+ fi
|
|
166
|
-
+ print_success "iOS framework copied to ios/Frameworks/LlamaCpp.framework for npm package (flat, no duplication)"
|
|
167
|
-
else
|
|
168
|
-
print_error "iOS framework not found after build"
|
|
169
|
-
cd ../..
|
|
170
|
-
diff --git a/cpp/cap-bridge.cpp b/cpp/cap-bridge.cpp
|
|
171
|
-
new file mode 100644
|
|
172
|
-
index 0000000..e6bdbd5
|
|
173
|
-
--- /dev/null
|
|
174
|
-
+++ b/cpp/cap-bridge.cpp
|
|
175
|
-
@@ -0,0 +1,383 @@
|
|
176
|
-
+#include "cap-llama.h"
|
|
177
|
-
+#include "cap-completion.h"
|
|
178
|
-
+
|
|
179
|
-
+#include <chrono>
|
|
180
|
-
+#include <cstdlib>
|
|
181
|
-
+#include <cstring>
|
|
182
|
-
+#include <exception>
|
|
183
|
-
+#include <map>
|
|
184
|
-
+#include <memory>
|
|
185
|
-
+#include <mutex>
|
|
186
|
-
+#include <string>
|
|
187
|
-
+#include <vector>
|
|
188
|
-
+
|
|
189
|
-
+using json = nlohmann::ordered_json;
|
|
190
|
-
+
|
|
191
|
-
+namespace capllama {
|
|
192
|
-
+bool capllama_verbose = false;
|
|
193
|
-
+}
|
|
194
|
-
+
|
|
195
|
-
+namespace {
|
|
196
|
-
+
|
|
197
|
-
+std::map<int64_t, std::unique_ptr<capllama::llama_cap_context>> g_contexts;
|
|
198
|
-
+std::mutex g_contexts_mutex;
|
|
199
|
-
+std::string g_last_error;
|
|
200
|
-
+int64_t g_next_context_id = 1;
|
|
201
|
-
+
|
|
202
|
-
+char * copy_string(const std::string & value) {
|
|
203
|
-
+ char * out = static_cast<char *>(std::malloc(value.size() + 1));
|
|
204
|
-
+ if (out == nullptr) {
|
|
205
|
-
+ return nullptr;
|
|
206
|
-
+ }
|
|
207
|
-
+ std::memcpy(out, value.c_str(), value.size() + 1);
|
|
208
|
-
+ return out;
|
|
209
|
-
+}
|
|
210
|
-
+
|
|
211
|
-
+json parse_json(const char * input) {
|
|
212
|
-
+ if (input == nullptr || input[0] == '\0') {
|
|
213
|
-
+ return json::object();
|
|
214
|
-
+ }
|
|
215
|
-
+ try {
|
|
216
|
-
+ const auto parsed = json::parse(input, nullptr, false);
|
|
217
|
-
+ return parsed.is_discarded() || !parsed.is_object() ? json::object() : parsed;
|
|
218
|
-
+ } catch (...) {
|
|
219
|
-
+ return json::object();
|
|
220
|
-
+ }
|
|
221
|
-
+}
|
|
222
|
-
+
|
|
223
|
-
+bool get_bool(const json & value, const char * key, bool fallback) {
|
|
224
|
-
+ if (!value.contains(key) || value[key].is_null()) return fallback;
|
|
225
|
-
+ if (value[key].is_boolean()) return value[key].get<bool>();
|
|
226
|
-
+ if (value[key].is_number_integer()) return value[key].get<int>() != 0;
|
|
227
|
-
+ return fallback;
|
|
228
|
-
+}
|
|
229
|
-
+
|
|
230
|
-
+int get_int(const json & value, const char * key, int fallback) {
|
|
231
|
-
+ if (!value.contains(key) || value[key].is_null()) return fallback;
|
|
232
|
-
+ if (value[key].is_number_integer()) return value[key].get<int>();
|
|
233
|
-
+ if (value[key].is_number_float()) return static_cast<int>(value[key].get<double>());
|
|
234
|
-
+ return fallback;
|
|
235
|
-
+}
|
|
236
|
-
+
|
|
237
|
-
+float get_float(const json & value, const char * key, float fallback) {
|
|
238
|
-
+ if (!value.contains(key) || value[key].is_null()) return fallback;
|
|
239
|
-
+ if (value[key].is_number()) return value[key].get<float>();
|
|
240
|
-
+ return fallback;
|
|
241
|
-
+}
|
|
242
|
-
+
|
|
243
|
-
+std::string get_string(const json & value, const char * key, const std::string & fallback = "") {
|
|
244
|
-
+ if (!value.contains(key) || value[key].is_null()) return fallback;
|
|
245
|
-
+ if (value[key].is_string()) return value[key].get<std::string>();
|
|
246
|
-
+ return fallback;
|
|
247
|
-
+}
|
|
248
|
-
+
|
|
249
|
-
+void apply_context_params(common_params & params, const json & input, const std::string & model_path) {
|
|
250
|
-
+ params.model.path = model_path;
|
|
251
|
-
+ params.n_ctx = get_int(input, "n_ctx", params.n_ctx);
|
|
252
|
-
+ params.n_batch = get_int(input, "n_batch", params.n_batch);
|
|
253
|
-
+ params.n_ubatch = get_int(input, "n_ubatch", params.n_ubatch);
|
|
254
|
-
+ params.n_keep = get_int(input, "n_keep", params.n_keep);
|
|
255
|
-
+ params.n_gpu_layers = get_bool(input, "no_gpu_devices", false)
|
|
256
|
-
+ ? 0
|
|
257
|
-
+ : get_int(input, "n_gpu_layers", params.n_gpu_layers);
|
|
258
|
-
+ params.cpuparams.n_threads = get_int(input, "n_threads", params.cpuparams.n_threads);
|
|
259
|
-
+ params.use_mmap = get_bool(input, "use_mmap", params.use_mmap);
|
|
260
|
-
+ params.use_mlock = get_bool(input, "use_mlock", params.use_mlock);
|
|
261
|
-
+ params.ctx_shift = get_bool(input, "ctx_shift", params.ctx_shift);
|
|
262
|
-
+ params.flash_attn = get_bool(input, "flash_attn", params.flash_attn);
|
|
263
|
-
+ params.embedding = get_bool(input, "embedding", params.embedding);
|
|
264
|
-
+ params.chat_template = get_string(input, "chat_template", params.chat_template);
|
|
265
|
-
+ params.rope_freq_base = get_float(input, "rope_freq_base", params.rope_freq_base);
|
|
266
|
-
+ params.rope_freq_scale = get_float(input, "rope_freq_scale", params.rope_freq_scale);
|
|
267
|
-
+ params.yarn_ext_factor = get_float(input, "yarn_ext_factor", params.yarn_ext_factor);
|
|
268
|
-
+ params.yarn_attn_factor = get_float(input, "yarn_attn_factor", params.yarn_attn_factor);
|
|
269
|
-
+ params.yarn_beta_fast = get_float(input, "yarn_beta_fast", params.yarn_beta_fast);
|
|
270
|
-
+ params.yarn_beta_slow = get_float(input, "yarn_beta_slow", params.yarn_beta_slow);
|
|
271
|
-
+ params.yarn_orig_ctx = get_int(input, "yarn_orig_ctx", params.yarn_orig_ctx);
|
|
272
|
-
+
|
|
273
|
-
+ const std::string cache_type_k = get_string(input, "cache_type_k");
|
|
274
|
-
+ const std::string cache_type_v = get_string(input, "cache_type_v");
|
|
275
|
-
+ if (!cache_type_k.empty()) params.cache_type_k = capllama::kv_cache_type_from_str(cache_type_k);
|
|
276
|
-
+ if (!cache_type_v.empty()) params.cache_type_v = capllama::kv_cache_type_from_str(cache_type_v);
|
|
277
|
-
+
|
|
278
|
-
+ params.speculative.n_max = get_int(input, "speculative_samples", params.speculative.n_max);
|
|
279
|
-
+ params.speculative.n_max = get_int(input, "draft_max", params.speculative.n_max);
|
|
280
|
-
+ params.speculative.n_min = get_int(input, "draft_min", params.speculative.n_min);
|
|
281
|
-
+ params.speculative.model.path = get_string(input, "draft_model", params.speculative.model.path);
|
|
282
|
-
+}
|
|
283
|
-
+
|
|
284
|
-
+void apply_completion_params(common_params & params, const json & input, const char * prompt) {
|
|
285
|
-
+ params.prompt = prompt == nullptr ? "" : std::string(prompt);
|
|
286
|
-
+ params.n_predict = get_int(input, "n_predict", params.n_predict > 0 ? params.n_predict : 256);
|
|
287
|
-
+ params.cpuparams.n_threads = get_int(input, "n_threads", params.cpuparams.n_threads);
|
|
288
|
-
+ params.sampling.temp = get_float(input, "temperature", params.sampling.temp);
|
|
289
|
-
+ params.sampling.top_k = get_int(input, "top_k", params.sampling.top_k);
|
|
290
|
-
+ params.sampling.top_p = get_float(input, "top_p", params.sampling.top_p);
|
|
291
|
-
+ params.sampling.min_p = get_float(input, "min_p", params.sampling.min_p);
|
|
292
|
-
+ params.sampling.typ_p = get_float(input, "typical_p", params.sampling.typ_p);
|
|
293
|
-
+ params.sampling.penalty_repeat = get_float(input, "penalty_repeat", params.sampling.penalty_repeat);
|
|
294
|
-
+ params.sampling.penalty_freq = get_float(input, "penalty_freq", params.sampling.penalty_freq);
|
|
295
|
-
+ params.sampling.penalty_present = get_float(input, "penalty_present", params.sampling.penalty_present);
|
|
296
|
-
+ params.sampling.n_probs = get_int(input, "n_probs", params.sampling.n_probs);
|
|
297
|
-
+ params.sampling.seed = get_int(input, "seed", params.sampling.seed);
|
|
298
|
-
+
|
|
299
|
-
+ params.antiprompt.clear();
|
|
300
|
-
+ if (input.contains("stop") && input["stop"].is_array()) {
|
|
301
|
-
+ for (const auto & stop : input["stop"]) {
|
|
302
|
-
+ if (stop.is_string()) {
|
|
303
|
-
+ params.antiprompt.push_back(stop.get<std::string>());
|
|
304
|
-
+ }
|
|
305
|
-
+ }
|
|
306
|
-
+ }
|
|
307
|
-
+}
|
|
308
|
-
+
|
|
309
|
-
+json model_info_json(const capllama::llama_cap_context & ctx) {
|
|
310
|
-
+ char desc[256] = {0};
|
|
311
|
-
+ if (ctx.model != nullptr) {
|
|
312
|
-
+ llama_model_desc(ctx.model, desc, sizeof(desc));
|
|
313
|
-
+ }
|
|
314
|
-
+ json metadata = json::object();
|
|
315
|
-
+ if (ctx.model != nullptr) {
|
|
316
|
-
+ const int count = llama_model_meta_count(ctx.model);
|
|
317
|
-
+ char key[256] = {0};
|
|
318
|
-
+ char value[2048] = {0};
|
|
319
|
-
+ for (int i = 0; i < count; ++i) {
|
|
320
|
-
+ if (llama_model_meta_key_by_index(ctx.model, i, key, sizeof(key)) >= 0 &&
|
|
321
|
-
+ llama_model_meta_val_str_by_index(ctx.model, i, value, sizeof(value)) >= 0) {
|
|
322
|
-
+ metadata[key] = value;
|
|
323
|
-
+ }
|
|
324
|
-
+ }
|
|
325
|
-
+ }
|
|
326
|
-
+ return {
|
|
327
|
-
+ {"desc", desc[0] == '\0' ? "GGUF model" : desc},
|
|
328
|
-
+ {"size", ctx.model == nullptr ? 0 : llama_model_size(ctx.model)},
|
|
329
|
-
+ {"nEmbd", ctx.model == nullptr ? 0 : llama_model_n_embd(ctx.model)},
|
|
330
|
-
+ {"nParams", ctx.model == nullptr ? 0 : llama_model_n_params(ctx.model)},
|
|
331
|
-
+ {"metadata", metadata},
|
|
332
|
-
+ {"isChatTemplateSupported", true},
|
|
333
|
-
+ {"chatTemplates", {
|
|
334
|
-
+ {"llamaChat", true},
|
|
335
|
-
+ {"minja", {
|
|
336
|
-
+ {"default", true},
|
|
337
|
-
+ {"defaultCaps", {
|
|
338
|
-
+ {"tools", true},
|
|
339
|
-
+ {"toolCalls", true},
|
|
340
|
-
+ {"toolResponses", true},
|
|
341
|
-
+ {"systemRole", true},
|
|
342
|
-
+ {"parallelToolCalls", true},
|
|
343
|
-
+ {"toolCallId", true}
|
|
344
|
-
+ }},
|
|
345
|
-
+ {"toolUse", true},
|
|
346
|
-
+ {"toolUseCaps", {
|
|
347
|
-
+ {"tools", true},
|
|
348
|
-
+ {"toolCalls", true},
|
|
349
|
-
+ {"toolResponses", true},
|
|
350
|
-
+ {"systemRole", true},
|
|
351
|
-
+ {"parallelToolCalls", true},
|
|
352
|
-
+ {"toolCallId", true}
|
|
353
|
-
+ }}
|
|
354
|
-
+ }}
|
|
355
|
-
+ }}
|
|
356
|
-
+ };
|
|
357
|
-
+}
|
|
358
|
-
+
|
|
359
|
-
+json timings_json(const llama_perf_context_data & perf, size_t prompt_tokens, size_t predicted_tokens) {
|
|
360
|
-
+ const double prompt_ms = perf.t_p_eval_ms;
|
|
361
|
-
+ const double predicted_ms = perf.t_eval_ms;
|
|
362
|
-
+ return {
|
|
363
|
-
+ {"prompt_n", static_cast<int>(prompt_tokens)},
|
|
364
|
-
+ {"prompt_ms", prompt_ms},
|
|
365
|
-
+ {"prompt_per_token_ms", prompt_tokens > 0 ? prompt_ms / static_cast<double>(prompt_tokens) : 0.0},
|
|
366
|
-
+ {"prompt_per_second", prompt_ms > 0 ? 1000.0 * static_cast<double>(prompt_tokens) / prompt_ms : 0.0},
|
|
367
|
-
+ {"predicted_n", static_cast<int>(predicted_tokens)},
|
|
368
|
-
+ {"predicted_ms", predicted_ms},
|
|
369
|
-
+ {"predicted_per_token_ms", predicted_tokens > 0 ? predicted_ms / static_cast<double>(predicted_tokens) : 0.0},
|
|
370
|
-
+ {"predicted_per_second", predicted_ms > 0 ? 1000.0 * static_cast<double>(predicted_tokens) / predicted_ms : 0.0}
|
|
371
|
-
+ };
|
|
372
|
-
+}
|
|
373
|
-
+
|
|
374
|
-
+capllama::llama_cap_context * find_context_locked(int64_t context_id) {
|
|
375
|
-
+ const auto it = g_contexts.find(context_id);
|
|
376
|
-
+ if (it == g_contexts.end()) return nullptr;
|
|
377
|
-
+ return it->second.get();
|
|
378
|
-
+}
|
|
379
|
-
+
|
|
380
|
-
+} // namespace
|
|
381
|
-
+
|
|
382
|
-
+extern "C" char * llama_get_last_error(void) {
|
|
383
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
384
|
-
+ return copy_string(g_last_error.empty() ? "No detailed native error captured" : g_last_error);
|
|
385
|
-
+}
|
|
386
|
-
+
|
|
387
|
-
+extern "C" void llama_free_string(char * value) {
|
|
388
|
-
+ if (value != nullptr) {
|
|
389
|
-
+ std::free(value);
|
|
390
|
-
+ }
|
|
391
|
-
+}
|
|
392
|
-
+
|
|
393
|
-
+extern "C" int64_t llama_init_context(const char * model_path, const char * params_json) {
|
|
394
|
-
+ if (model_path == nullptr || model_path[0] == '\0') {
|
|
395
|
-
+ return -1;
|
|
396
|
-
+ }
|
|
397
|
-
+ try {
|
|
398
|
-
+ auto context = std::make_unique<capllama::llama_cap_context>();
|
|
399
|
-
+ common_params params;
|
|
400
|
-
+ apply_context_params(params, parse_json(params_json), model_path);
|
|
401
|
-
+ if (!context->loadModel(params)) {
|
|
402
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
403
|
-
+ g_last_error = std::string("Failed to load model: ") + model_path;
|
|
404
|
-
+ return -1;
|
|
405
|
-
+ }
|
|
406
|
-
+
|
|
407
|
-
+ const auto input = parse_json(params_json);
|
|
408
|
-
+ const std::string draft_model = get_string(input, "draft_model");
|
|
409
|
-
+ if (!draft_model.empty()) {
|
|
410
|
-
+ context->mobile_speculative = get_bool(input, "mobile_speculative", true);
|
|
411
|
-
+ context->speculative_samples = get_int(input, "speculative_samples", context->speculative_samples);
|
|
412
|
-
+ if (!context->loadDraftModel(draft_model)) {
|
|
413
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
414
|
-
+ g_last_error = "DFlash/speculative draft model loading is not available in this mobile framework build.";
|
|
415
|
-
+ return -1;
|
|
416
|
-
+ }
|
|
417
|
-
+ }
|
|
418
|
-
+
|
|
419
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
420
|
-
+ const int64_t context_id = g_next_context_id++;
|
|
421
|
-
+ g_contexts[context_id] = std::move(context);
|
|
422
|
-
+ return context_id;
|
|
423
|
-
+ } catch (const std::exception & e) {
|
|
424
|
-
+ capllama::log("ERROR", __func__, __LINE__, "llama_init_context failed: %s", e.what());
|
|
425
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
426
|
-
+ g_last_error = e.what();
|
|
427
|
-
+ return -1;
|
|
428
|
-
+ } catch (...) {
|
|
429
|
-
+ capllama::log("ERROR", __func__, __LINE__, "llama_init_context failed with unknown exception");
|
|
430
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
431
|
-
+ g_last_error = "llama_init_context failed with unknown exception";
|
|
432
|
-
+ return -1;
|
|
433
|
-
+ }
|
|
434
|
-
+}
|
|
435
|
-
+
|
|
436
|
-
+extern "C" void * llama_get_context_ptr(int64_t context_id) {
|
|
437
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
438
|
-
+ return find_context_locked(context_id);
|
|
439
|
-
+}
|
|
440
|
-
+
|
|
441
|
-
+extern "C" char * llama_get_model_info(int64_t context_id) {
|
|
442
|
-
+ try {
|
|
443
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
444
|
-
+ auto * ctx = find_context_locked(context_id);
|
|
445
|
-
+ if (ctx == nullptr) return nullptr;
|
|
446
|
-
+ return copy_string(model_info_json(*ctx).dump());
|
|
447
|
-
+ } catch (...) {
|
|
448
|
-
+ return nullptr;
|
|
449
|
-
+ }
|
|
450
|
-
+}
|
|
451
|
-
+
|
|
452
|
-
+extern "C" void llama_release_context(int64_t context_id) {
|
|
453
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
454
|
-
+ g_contexts.erase(context_id);
|
|
455
|
-
+}
|
|
456
|
-
+
|
|
457
|
-
+extern "C" char * llama_get_formatted_chat(int64_t context_id, const char * messages, const char * chat_template) {
|
|
458
|
-
+ try {
|
|
459
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
460
|
-
+ auto * ctx = find_context_locked(context_id);
|
|
461
|
-
+ if (ctx == nullptr) return nullptr;
|
|
462
|
-
+ const auto formatted = ctx->getFormattedChat(
|
|
463
|
-
+ messages == nullptr ? "[]" : messages,
|
|
464
|
-
+ chat_template == nullptr ? "" : chat_template
|
|
465
|
-
+ );
|
|
466
|
-
+ return copy_string(json(formatted).dump());
|
|
467
|
-
+ } catch (const std::exception & e) {
|
|
468
|
-
+ return copy_string(std::string("{\"error\":\"") + e.what() + "\"}");
|
|
469
|
-
+ } catch (...) {
|
|
470
|
-
+ return nullptr;
|
|
471
|
-
+ }
|
|
472
|
-
+}
|
|
473
|
-
+
|
|
474
|
-
+extern "C" char * llama_completion(int64_t context_id, const char * prompt, const char * params_json) {
|
|
475
|
-
+ const auto started = std::chrono::steady_clock::now();
|
|
476
|
-
+ try {
|
|
477
|
-
+ capllama::llama_cap_context * ctx = nullptr;
|
|
478
|
-
+ {
|
|
479
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
480
|
-
+ ctx = find_context_locked(context_id);
|
|
481
|
-
+ }
|
|
482
|
-
+ if (ctx == nullptr || ctx->ctx == nullptr || ctx->model == nullptr || ctx->completion == nullptr) {
|
|
483
|
-
+ return copy_string("{\"error\":\"Native context is not loaded\"}");
|
|
484
|
-
+ }
|
|
485
|
-
+
|
|
486
|
-
+ apply_completion_params(ctx->params, parse_json(params_json), prompt);
|
|
487
|
-
+ auto * completion = ctx->completion;
|
|
488
|
-
+ completion->rewind();
|
|
489
|
-
+ if (!completion->initSampling()) {
|
|
490
|
-
+ return copy_string("{\"error\":\"Failed to initialize sampler\"}");
|
|
491
|
-
+ }
|
|
492
|
-
+
|
|
493
|
-
+ completion->loadPrompt({});
|
|
494
|
-
+ completion->beginCompletion();
|
|
495
|
-
+ while (completion->has_next_token && !completion->is_interrupted) {
|
|
496
|
-
+ const size_t before_size = completion->generated_text.size();
|
|
497
|
-
+ if (ctx->isSpectulativeEnabled()) {
|
|
498
|
-
+ completion->nextTokenSpeculative();
|
|
499
|
-
+ } else {
|
|
500
|
-
+ completion->doCompletion();
|
|
501
|
-
+ }
|
|
502
|
-
+ const size_t last_token_size = completion->generated_text.size() - before_size;
|
|
503
|
-
+ const size_t stop_pos = completion->findStoppingStrings(completion->generated_text, last_token_size, capllama::STOP_FULL);
|
|
504
|
-
+ if (stop_pos != std::string::npos) {
|
|
505
|
-
+ completion->generated_text = completion->generated_text.substr(0, stop_pos);
|
|
506
|
-
+ }
|
|
507
|
-
+ }
|
|
508
|
-
+ completion->endCompletion();
|
|
509
|
-
+
|
|
510
|
-
+ std::string generated = completion->generated_text;
|
|
511
|
-
+
|
|
512
|
-
+ const auto perf = llama_perf_context(ctx->ctx);
|
|
513
|
-
+ const auto elapsed = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - started).count();
|
|
514
|
-
+ json result = {
|
|
515
|
-
+ {"text", generated},
|
|
516
|
-
+ {"content", generated},
|
|
517
|
-
+ {"reasoning_content", ""},
|
|
518
|
-
+ {"tool_calls", json::array()},
|
|
519
|
-
+ {"chat_format", completion->current_chat_format},
|
|
520
|
-
+ {"tokens_predicted", static_cast<int>(completion->num_tokens_predicted)},
|
|
521
|
-
+ {"tokens_evaluated", static_cast<int>(completion->num_prompt_tokens)},
|
|
522
|
-
+ {"truncated", completion->truncated},
|
|
523
|
-
+ {"stopped_eos", completion->stopped_eos},
|
|
524
|
-
+ {"stopped_word", completion->stopped_word},
|
|
525
|
-
+ {"stopped_limit", completion->stopped_limit},
|
|
526
|
-
+ {"stopping_word", completion->stopping_word},
|
|
527
|
-
+ {"context_full", completion->context_full},
|
|
528
|
-
+ {"interrupted", completion->is_interrupted},
|
|
529
|
-
+ {"tokens_cached", static_cast<int>(completion->n_past)},
|
|
530
|
-
+ {"timings", timings_json(perf, completion->num_prompt_tokens, completion->num_tokens_predicted)}
|
|
531
|
-
+ };
|
|
532
|
-
+ if (result["timings"]["predicted_ms"].get<double>() <= 0.0) {
|
|
533
|
-
+ result["timings"]["predicted_ms"] = elapsed;
|
|
534
|
-
+ result["timings"]["predicted_per_token_ms"] =
|
|
535
|
-
+ completion->num_tokens_predicted > 0 ? elapsed / static_cast<double>(completion->num_tokens_predicted) : 0.0;
|
|
536
|
-
+ result["timings"]["predicted_per_second"] =
|
|
537
|
-
+ elapsed > 0 ? 1000.0 * static_cast<double>(completion->num_tokens_predicted) / elapsed : 0.0;
|
|
538
|
-
+ }
|
|
539
|
-
+ return copy_string(result.dump());
|
|
540
|
-
+ } catch (const std::exception & e) {
|
|
541
|
-
+ return copy_string((json{{"error", e.what()}}).dump());
|
|
542
|
-
+ } catch (...) {
|
|
543
|
-
+ return copy_string("{\"error\":\"Unknown native completion failure\"}");
|
|
544
|
-
+ }
|
|
545
|
-
+}
|
|
546
|
-
+
|
|
547
|
-
+extern "C" void llama_stop_completion(int64_t context_id) {
|
|
548
|
-
+ std::lock_guard<std::mutex> lock(g_contexts_mutex);
|
|
549
|
-
+ auto * ctx = find_context_locked(context_id);
|
|
550
|
-
+ if (ctx != nullptr && ctx->completion != nullptr) {
|
|
551
|
-
+ ctx->completion->is_interrupted = true;
|
|
552
|
-
+ }
|
|
553
|
-
+}
|
|
554
|
-
+
|
|
555
|
-
+extern "C" bool llama_toggle_native_log(bool enabled) {
|
|
556
|
-
+ capllama::capllama_verbose = enabled;
|
|
557
|
-
+ return true;
|
|
558
|
-
+}
|
|
559
|
-
diff --git a/cpp/cap-embedding.cpp b/cpp/cap-embedding.cpp
|
|
560
|
-
index c6e0f56..968e58e 100644
|
|
561
|
-
--- a/cpp/cap-embedding.cpp
|
|
562
|
-
+++ b/cpp/cap-embedding.cpp
|
|
563
|
-
@@ -98,7 +98,7 @@ extern "C" float* llama_embedding(int64_t contextId, const char* text, const cha
|
|
564
|
-
|
|
565
|
-
// Add tokens to batch with embeddings enabled
|
|
566
|
-
for (size_t i = 0; i < tokens.size(); i++) {
|
|
567
|
-
- llama_batch_add(&batch, tokens[i], i, {0}, true); // logits=true to get embeddings
|
|
568
|
-
+ capllama::llama_batch_add(&batch, tokens[i], i, {0}, true); // logits=true to get embeddings
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// Decode the batch to get embeddings
|
|
572
|
-
diff --git a/cpp/cap-llama.cpp b/cpp/cap-llama.cpp
|
|
573
|
-
index c65af7e..d205c90 100644
|
|
574
|
-
--- a/cpp/cap-llama.cpp
|
|
575
|
-
+++ b/cpp/cap-llama.cpp
|
|
576
|
-
@@ -368,9 +368,7 @@ bool llama_cap_context::loadDraftModel(const std::string &draft_model_path) {
|
|
577
|
-
// draft_model = llama_load_model_from_file(draft_model_path.c_str(), draft_params);
|
|
578
|
-
// draft_ctx = llama_new_context_with_model(draft_model, draft_params);
|
|
579
|
-
|
|
580
|
-
- // For this implementation, we'll disable speculative decoding
|
|
581
|
-
- // until proper model loading is implemented
|
|
582
|
-
- printf("Draft model loading not yet implemented - falling back to regular decoding\n");
|
|
583
|
-
+ printf("DFlash/speculative draft model loading is not available in this mobile framework build\n");
|
|
584
|
-
speculative_enabled = false;
|
|
585
|
-
return false;
|
|
586
|
-
|
|
587
|
-
diff --git a/ios/CMakeLists-arm64.txt b/ios/CMakeLists-arm64.txt
|
|
588
|
-
index c268b43..ba248b4 100644
|
|
589
|
-
--- a/ios/CMakeLists-arm64.txt
|
|
590
|
-
+++ b/ios/CMakeLists-arm64.txt
|
|
591
|
-
@@ -1,5 +1,5 @@
|
|
592
|
-
cmake_minimum_required(VERSION 3.16)
|
|
593
|
-
-project(llama-cpp VERSION 1.0.0 LANGUAGES CXX C)
|
|
594
|
-
+project(LlamaCpp VERSION 1.0.0 LANGUAGES CXX C)
|
|
595
|
-
|
|
596
|
-
set(CMAKE_CXX_STANDARD 17)
|
|
597
|
-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
598
|
-
@@ -36,7 +36,7 @@ set(PUBLIC_HEADERS
|
|
599
|
-
)
|
|
600
|
-
|
|
601
|
-
# Create library target
|
|
602
|
-
-add_library(llama-cpp SHARED
|
|
603
|
-
+add_library(LlamaCpp SHARED
|
|
604
|
-
${SOURCE_DIR}/ggml.c
|
|
605
|
-
${SOURCE_DIR}/ggml-alloc.c
|
|
606
|
-
${SOURCE_DIR}/ggml-backend.cpp
|
|
607
|
-
@@ -98,15 +98,18 @@ add_library(llama-cpp SHARED
|
|
608
|
-
${SOURCE_DIR}/tools/mtmd/clip.cpp
|
|
609
|
-
${SOURCE_DIR}/cap-llama.cpp
|
|
610
|
-
${SOURCE_DIR}/cap-completion.cpp
|
|
611
|
-
+ ${SOURCE_DIR}/cap-bridge.cpp
|
|
612
|
-
${SOURCE_DIR}/cap-tts.cpp
|
|
613
|
-
${SOURCE_FILES_ARCH}
|
|
614
|
-
)
|
|
615
|
-
|
|
616
|
-
+set_source_files_properties(${SOURCE_DIR}/cap-bridge.cpp PROPERTIES COMPILE_OPTIONS "-O0")
|
|
617
|
-
+
|
|
618
|
-
# Set target properties
|
|
619
|
-
-set_target_properties(llama-cpp PROPERTIES
|
|
620
|
-
+set_target_properties(LlamaCpp PROPERTIES
|
|
621
|
-
FRAMEWORK TRUE
|
|
622
|
-
FRAMEWORK_VERSION A
|
|
623
|
-
- MACOSX_FRAMEWORK_IDENTIFIER com.arusatech.llama-cpp
|
|
624
|
-
+ MACOSX_FRAMEWORK_IDENTIFIER com.arusatech.LlamaCpp
|
|
625
|
-
MACOSX_FRAMEWORK_BUNDLE_VERSION 1.0.0
|
|
626
|
-
MACOSX_FRAMEWORK_SHORT_VERSION_STRING 1.0.0
|
|
627
|
-
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
|
|
628
|
-
@@ -116,7 +119,7 @@ set_target_properties(llama-cpp PROPERTIES
|
|
629
|
-
)
|
|
630
|
-
|
|
631
|
-
# Include directories
|
|
632
|
-
-target_include_directories(llama-cpp PRIVATE
|
|
633
|
-
+target_include_directories(LlamaCpp PRIVATE
|
|
634
|
-
${SOURCE_DIR}
|
|
635
|
-
${SOURCE_DIR}/ggml-cpu
|
|
636
|
-
${SOURCE_DIR}/tools/mtmd
|
|
637
|
-
@@ -125,7 +128,7 @@ target_include_directories(llama-cpp PRIVATE
|
|
638
|
-
# ARM64: rely on Clang's default tuning; no x86‑specific -march flags here
|
|
639
|
-
|
|
640
|
-
# Link frameworks via linker flags
|
|
641
|
-
-target_link_options(llama-cpp PRIVATE
|
|
642
|
-
+target_link_options(LlamaCpp PRIVATE
|
|
643
|
-
"-Wl,-framework,Accelerate"
|
|
644
|
-
"-Wl,-framework,Metal"
|
|
645
|
-
"-Wl,-framework,MetalKit"
|
|
646
|
-
@@ -134,16 +137,15 @@ target_link_options(llama-cpp PRIVATE
|
|
647
|
-
)
|
|
648
|
-
|
|
649
|
-
# Public headers
|
|
650
|
-
-set_target_properties(llama-cpp PROPERTIES
|
|
651
|
-
+set_target_properties(LlamaCpp PROPERTIES
|
|
652
|
-
PUBLIC_HEADER "${PUBLIC_HEADERS}"
|
|
653
|
-
)
|
|
654
|
-
|
|
655
|
-
# Install rules
|
|
656
|
-
-install(TARGETS llama-cpp
|
|
657
|
-
+install(TARGETS LlamaCpp
|
|
658
|
-
FRAMEWORK DESTINATION .
|
|
659
|
-
)
|
|
660
|
-
|
|
661
|
-
-message(STATUS "Building llama-cpp for ARM64 (devices)")
|
|
662
|
-
+message(STATUS "Building LlamaCpp for ARM64 (devices)")
|
|
663
|
-
message(STATUS "Source directory: ${SOURCE_DIR}")
|
|
664
|
-
message(STATUS "Architecture: arm64")
|
|
665
|
-
-
|
|
666
|
-
diff --git a/ios/CMakeLists-x86_64.txt b/ios/CMakeLists-x86_64.txt
|
|
667
|
-
index b3652e9..054f5f3 100644
|
|
668
|
-
--- a/ios/CMakeLists-x86_64.txt
|
|
669
|
-
+++ b/ios/CMakeLists-x86_64.txt
|
|
670
|
-
@@ -1,5 +1,5 @@
|
|
671
|
-
cmake_minimum_required(VERSION 3.16)
|
|
672
|
-
-project(llama-cpp VERSION 1.0.0 LANGUAGES CXX C)
|
|
673
|
-
+project(LlamaCpp VERSION 1.0.0 LANGUAGES CXX C)
|
|
674
|
-
|
|
675
|
-
set(CMAKE_CXX_STANDARD 17)
|
|
676
|
-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
677
|
-
@@ -45,7 +45,7 @@ set(PUBLIC_HEADERS
|
|
678
|
-
)
|
|
679
|
-
|
|
680
|
-
# Create library target
|
|
681
|
-
-add_library(llama-cpp SHARED
|
|
682
|
-
+add_library(LlamaCpp SHARED
|
|
683
|
-
${SOURCE_DIR}/ggml.c
|
|
684
|
-
${SOURCE_DIR}/ggml-alloc.c
|
|
685
|
-
${SOURCE_DIR}/ggml-backend.cpp
|
|
686
|
-
@@ -111,15 +111,18 @@ add_library(llama-cpp SHARED
|
|
687
|
-
${SOURCE_DIR}/nlohmann/json_fwd.hpp
|
|
688
|
-
${SOURCE_DIR}/cap-llama.cpp
|
|
689
|
-
${SOURCE_DIR}/cap-completion.cpp
|
|
690
|
-
+ ${SOURCE_DIR}/cap-bridge.cpp
|
|
691
|
-
${SOURCE_DIR}/cap-tts.cpp
|
|
692
|
-
${SOURCE_FILES_ARCH}
|
|
693
|
-
)
|
|
694
|
-
|
|
695
|
-
+set_source_files_properties(${SOURCE_DIR}/cap-bridge.cpp PROPERTIES COMPILE_OPTIONS "-O0")
|
|
696
|
-
+
|
|
697
|
-
# Set target properties
|
|
698
|
-
-set_target_properties(llama-cpp PROPERTIES
|
|
699
|
-
+set_target_properties(LlamaCpp PROPERTIES
|
|
700
|
-
FRAMEWORK TRUE
|
|
701
|
-
FRAMEWORK_VERSION A
|
|
702
|
-
- MACOSX_FRAMEWORK_IDENTIFIER com.arusatech.llama-cpp
|
|
703
|
-
+ MACOSX_FRAMEWORK_IDENTIFIER com.arusatech.LlamaCpp
|
|
704
|
-
MACOSX_FRAMEWORK_BUNDLE_VERSION 1.0.0
|
|
705
|
-
MACOSX_FRAMEWORK_SHORT_VERSION_STRING 1.0.0
|
|
706
|
-
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
|
|
707
|
-
@@ -129,14 +132,14 @@ set_target_properties(llama-cpp PROPERTIES
|
|
708
|
-
)
|
|
709
|
-
|
|
710
|
-
# Set include directories
|
|
711
|
-
-target_include_directories(llama-cpp PRIVATE
|
|
712
|
-
+target_include_directories(LlamaCpp PRIVATE
|
|
713
|
-
${SOURCE_DIR}
|
|
714
|
-
${SOURCE_DIR}/ggml-cpu
|
|
715
|
-
${SOURCE_DIR}/tools/mtmd
|
|
716
|
-
)
|
|
717
|
-
|
|
718
|
-
# Set compile options for x86_64 optimization
|
|
719
|
-
-target_compile_options(llama-cpp PRIVATE
|
|
720
|
-
+target_compile_options(LlamaCpp PRIVATE
|
|
721
|
-
-march=x86-64
|
|
722
|
-
-mtune=generic
|
|
723
|
-
-mavx2
|
|
724
|
-
@@ -151,7 +154,7 @@ target_compile_options(llama-cpp PRIVATE
|
|
725
|
-
# NOTE:
|
|
726
|
-
# Use -Wl,-framework,<Name> so that the compiler driver passes the correct
|
|
727
|
-
# framework flags through to the linker as a single option.
|
|
728
|
-
-target_link_options(llama-cpp PRIVATE
|
|
729
|
-
+target_link_options(LlamaCpp PRIVATE
|
|
730
|
-
"-Wl,-framework,Accelerate"
|
|
731
|
-
"-Wl,-framework,Metal"
|
|
732
|
-
"-Wl,-framework,MetalKit"
|
|
733
|
-
@@ -160,17 +163,17 @@ target_link_options(llama-cpp PRIVATE
|
|
734
|
-
)
|
|
735
|
-
|
|
736
|
-
# Set public headers
|
|
737
|
-
-set_target_properties(llama-cpp PROPERTIES
|
|
738
|
-
+set_target_properties(LlamaCpp PROPERTIES
|
|
739
|
-
PUBLIC_HEADER "${PUBLIC_HEADERS}"
|
|
740
|
-
)
|
|
741
|
-
|
|
742
|
-
# Install rules
|
|
743
|
-
-install(TARGETS llama-cpp
|
|
744
|
-
+install(TARGETS LlamaCpp
|
|
745
|
-
FRAMEWORK DESTINATION .
|
|
746
|
-
)
|
|
747
|
-
|
|
748
|
-
# Print build information
|
|
749
|
-
-message(STATUS "Building llama-cpp for x86_64 (emulator)")
|
|
750
|
-
+message(STATUS "Building LlamaCpp for x86_64 (emulator)")
|
|
751
|
-
message(STATUS "Source directory: ${SOURCE_DIR}")
|
|
752
|
-
message(STATUS "Architecture: x86_64")
|
|
753
|
-
message(STATUS "Optimizations: AVX2, AVX, SSE3, SSE, FMA, F16C")
|
|
754
|
-
diff --git a/ios/CMakeLists.txt b/ios/CMakeLists.txt
|
|
755
|
-
index c268b43..ba248b4 100644
|
|
756
|
-
--- a/ios/CMakeLists.txt
|
|
757
|
-
+++ b/ios/CMakeLists.txt
|
|
758
|
-
@@ -1,5 +1,5 @@
|
|
759
|
-
cmake_minimum_required(VERSION 3.16)
|
|
760
|
-
-project(llama-cpp VERSION 1.0.0 LANGUAGES CXX C)
|
|
761
|
-
+project(LlamaCpp VERSION 1.0.0 LANGUAGES CXX C)
|
|
762
|
-
|
|
763
|
-
set(CMAKE_CXX_STANDARD 17)
|
|
764
|
-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
765
|
-
@@ -36,7 +36,7 @@ set(PUBLIC_HEADERS
|
|
766
|
-
)
|
|
767
|
-
|
|
768
|
-
# Create library target
|
|
769
|
-
-add_library(llama-cpp SHARED
|
|
770
|
-
+add_library(LlamaCpp SHARED
|
|
771
|
-
${SOURCE_DIR}/ggml.c
|
|
772
|
-
${SOURCE_DIR}/ggml-alloc.c
|
|
773
|
-
${SOURCE_DIR}/ggml-backend.cpp
|
|
774
|
-
@@ -98,15 +98,18 @@ add_library(llama-cpp SHARED
|
|
775
|
-
${SOURCE_DIR}/tools/mtmd/clip.cpp
|
|
776
|
-
${SOURCE_DIR}/cap-llama.cpp
|
|
777
|
-
${SOURCE_DIR}/cap-completion.cpp
|
|
778
|
-
+ ${SOURCE_DIR}/cap-bridge.cpp
|
|
779
|
-
${SOURCE_DIR}/cap-tts.cpp
|
|
780
|
-
${SOURCE_FILES_ARCH}
|
|
781
|
-
)
|
|
782
|
-
|
|
783
|
-
+set_source_files_properties(${SOURCE_DIR}/cap-bridge.cpp PROPERTIES COMPILE_OPTIONS "-O0")
|
|
784
|
-
+
|
|
785
|
-
# Set target properties
|
|
786
|
-
-set_target_properties(llama-cpp PROPERTIES
|
|
787
|
-
+set_target_properties(LlamaCpp PROPERTIES
|
|
788
|
-
FRAMEWORK TRUE
|
|
789
|
-
FRAMEWORK_VERSION A
|
|
790
|
-
- MACOSX_FRAMEWORK_IDENTIFIER com.arusatech.llama-cpp
|
|
791
|
-
+ MACOSX_FRAMEWORK_IDENTIFIER com.arusatech.LlamaCpp
|
|
792
|
-
MACOSX_FRAMEWORK_BUNDLE_VERSION 1.0.0
|
|
793
|
-
MACOSX_FRAMEWORK_SHORT_VERSION_STRING 1.0.0
|
|
794
|
-
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
|
|
795
|
-
@@ -116,7 +119,7 @@ set_target_properties(llama-cpp PROPERTIES
|
|
796
|
-
)
|
|
797
|
-
|
|
798
|
-
# Include directories
|
|
799
|
-
-target_include_directories(llama-cpp PRIVATE
|
|
800
|
-
+target_include_directories(LlamaCpp PRIVATE
|
|
801
|
-
${SOURCE_DIR}
|
|
802
|
-
${SOURCE_DIR}/ggml-cpu
|
|
803
|
-
${SOURCE_DIR}/tools/mtmd
|
|
804
|
-
@@ -125,7 +128,7 @@ target_include_directories(llama-cpp PRIVATE
|
|
805
|
-
# ARM64: rely on Clang's default tuning; no x86‑specific -march flags here
|
|
806
|
-
|
|
807
|
-
# Link frameworks via linker flags
|
|
808
|
-
-target_link_options(llama-cpp PRIVATE
|
|
809
|
-
+target_link_options(LlamaCpp PRIVATE
|
|
810
|
-
"-Wl,-framework,Accelerate"
|
|
811
|
-
"-Wl,-framework,Metal"
|
|
812
|
-
"-Wl,-framework,MetalKit"
|
|
813
|
-
@@ -134,16 +137,15 @@ target_link_options(llama-cpp PRIVATE
|
|
814
|
-
)
|
|
815
|
-
|
|
816
|
-
# Public headers
|
|
817
|
-
-set_target_properties(llama-cpp PROPERTIES
|
|
818
|
-
+set_target_properties(LlamaCpp PROPERTIES
|
|
819
|
-
PUBLIC_HEADER "${PUBLIC_HEADERS}"
|
|
820
|
-
)
|
|
821
|
-
|
|
822
|
-
# Install rules
|
|
823
|
-
-install(TARGETS llama-cpp
|
|
824
|
-
+install(TARGETS LlamaCpp
|
|
825
|
-
FRAMEWORK DESTINATION .
|
|
826
|
-
)
|
|
827
|
-
|
|
828
|
-
-message(STATUS "Building llama-cpp for ARM64 (devices)")
|
|
829
|
-
+message(STATUS "Building LlamaCpp for ARM64 (devices)")
|
|
830
|
-
message(STATUS "Source directory: ${SOURCE_DIR}")
|
|
831
|
-
message(STATUS "Architecture: arm64")
|
|
832
|
-
-
|
|
833
|
-
diff --git a/ios/Frameworks-xcframework/LlamaCpp.xcframework/Info.plist b/ios/Frameworks-xcframework/LlamaCpp.xcframework/Info.plist
|
|
834
|
-
new file mode 100644
|
|
835
|
-
index 0000000..ab641ec
|
|
836
|
-
--- /dev/null
|
|
837
|
-
+++ b/ios/Frameworks-xcframework/LlamaCpp.xcframework/Info.plist
|
|
838
|
-
@@ -0,0 +1,43 @@
|
|
839
|
-
+<?xml version="1.0" encoding="UTF-8"?>
|
|
840
|
-
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
841
|
-
+<plist version="1.0">
|
|
842
|
-
+<dict>
|
|
843
|
-
+ <key>AvailableLibraries</key>
|
|
844
|
-
+ <array>
|
|
845
|
-
+ <dict>
|
|
846
|
-
+ <key>BinaryPath</key>
|
|
847
|
-
+ <string>LlamaCpp.framework/LlamaCpp</string>
|
|
848
|
-
+ <key>LibraryIdentifier</key>
|
|
849
|
-
+ <string>ios-arm64</string>
|
|
850
|
-
+ <key>LibraryPath</key>
|
|
851
|
-
+ <string>LlamaCpp.framework</string>
|
|
852
|
-
+ <key>SupportedArchitectures</key>
|
|
853
|
-
+ <array>
|
|
854
|
-
+ <string>arm64</string>
|
|
855
|
-
+ </array>
|
|
856
|
-
+ <key>SupportedPlatform</key>
|
|
857
|
-
+ <string>ios</string>
|
|
858
|
-
+ </dict>
|
|
859
|
-
+ <dict>
|
|
860
|
-
+ <key>BinaryPath</key>
|
|
861
|
-
+ <string>LlamaCpp.framework/LlamaCpp</string>
|
|
862
|
-
+ <key>LibraryIdentifier</key>
|
|
863
|
-
+ <string>ios-arm64-simulator</string>
|
|
864
|
-
+ <key>LibraryPath</key>
|
|
865
|
-
+ <string>LlamaCpp.framework</string>
|
|
866
|
-
+ <key>SupportedArchitectures</key>
|
|
867
|
-
+ <array>
|
|
868
|
-
+ <string>arm64</string>
|
|
869
|
-
+ </array>
|
|
870
|
-
+ <key>SupportedPlatform</key>
|
|
871
|
-
+ <string>ios</string>
|
|
872
|
-
+ <key>SupportedPlatformVariant</key>
|
|
873
|
-
+ <string>simulator</string>
|
|
874
|
-
+ </dict>
|
|
875
|
-
+ </array>
|
|
876
|
-
+ <key>CFBundlePackageType</key>
|
|
877
|
-
+ <string>XFWK</string>
|
|
878
|
-
+ <key>XCFrameworkFormatVersion</key>
|
|
879
|
-
+ <string>1.0</string>
|
|
880
|
-
+</dict>
|
|
881
|
-
+</plist>
|
|
882
|
-
diff --git a/ios/Frameworks/llama-cpp.framework/Info.plist b/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64-simulator/LlamaCpp.framework/Info.plist
|
|
883
|
-
similarity index 91%
|
|
884
|
-
rename from ios/Frameworks/llama-cpp.framework/Info.plist
|
|
885
|
-
rename to ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64-simulator/LlamaCpp.framework/Info.plist
|
|
886
|
-
index 79b6cdc..3740776 100644
|
|
887
|
-
--- a/ios/Frameworks/llama-cpp.framework/Info.plist
|
|
888
|
-
+++ b/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64-simulator/LlamaCpp.framework/Info.plist
|
|
889
|
-
@@ -5,11 +5,11 @@
|
|
890
|
-
<key>CFBundleDevelopmentRegion</key>
|
|
891
|
-
<string>English</string>
|
|
892
|
-
<key>CFBundleExecutable</key>
|
|
893
|
-
- <string>llama-cpp</string>
|
|
894
|
-
+ <string>LlamaCpp</string>
|
|
895
|
-
<key>CFBundleIconFile</key>
|
|
896
|
-
<string></string>
|
|
897
|
-
<key>CFBundleIdentifier</key>
|
|
898
|
-
- <string>com.arusatech.llama-cpp</string>
|
|
899
|
-
+ <string>com.arusatech.LlamaCpp</string>
|
|
900
|
-
<key>CFBundleInfoDictionaryVersion</key>
|
|
901
|
-
<string>6.0</string>
|
|
902
|
-
<key>CFBundleName</key>
|
|
903
|
-
diff --git a/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Headers/LlamaCpp.h b/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Headers/LlamaCpp.h
|
|
904
|
-
new file mode 100644
|
|
905
|
-
index 0000000..e69de29
|
|
906
|
-
diff --git a/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Info.plist b/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Info.plist
|
|
907
|
-
new file mode 100644
|
|
908
|
-
index 0000000..c96f8fe
|
|
909
|
-
--- /dev/null
|
|
910
|
-
+++ b/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Info.plist
|
|
911
|
-
@@ -0,0 +1,28 @@
|
|
912
|
-
+<?xml version="1.0" encoding="UTF-8"?>
|
|
913
|
-
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
914
|
-
+<plist version="1.0">
|
|
915
|
-
+<dict>
|
|
916
|
-
+ <key>CFBundleDevelopmentRegion</key>
|
|
917
|
-
+ <string>English</string>
|
|
918
|
-
+ <key>CFBundleExecutable</key>
|
|
919
|
-
+ <string>LlamaCpp</string>
|
|
920
|
-
+ <key>CFBundleIconFile</key>
|
|
921
|
-
+ <string></string>
|
|
922
|
-
+ <key>CFBundleIdentifier</key>
|
|
923
|
-
+ <string>com.arusatech.LlamaCpp</string>
|
|
924
|
-
+ <key>CFBundleInfoDictionaryVersion</key>
|
|
925
|
-
+ <string>6.0</string>
|
|
926
|
-
+ <key>CFBundleName</key>
|
|
927
|
-
+ <string>LlamaCpp</string>
|
|
928
|
-
+ <key>CFBundlePackageType</key>
|
|
929
|
-
+ <string>FMWK</string>
|
|
930
|
-
+ <key>CFBundleShortVersionString</key>
|
|
931
|
-
+ <string>1.0.0</string>
|
|
932
|
-
+ <key>CFBundleSignature</key>
|
|
933
|
-
+ <string>????</string>
|
|
934
|
-
+ <key>CFBundleVersion</key>
|
|
935
|
-
+ <string>1.0.0</string>
|
|
936
|
-
+ <key>CSResourcesFileMapped</key>
|
|
937
|
-
+ <true/>
|
|
938
|
-
+</dict>
|
|
939
|
-
+</plist>
|
|
940
|
-
diff --git a/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Modules/module.modulemap b/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Modules/module.modulemap
|
|
941
|
-
new file mode 100644
|
|
942
|
-
index 0000000..964fc83
|
|
943
|
-
--- /dev/null
|
|
944
|
-
+++ b/ios/Frameworks-xcframework/LlamaCpp.xcframework/ios-arm64/LlamaCpp.framework/Modules/module.modulemap
|
|
945
|
-
@@ -0,0 +1,4 @@
|
|
946
|
-
+framework module LlamaCpp {
|
|
947
|
-
+ umbrella header "LlamaCpp.h"
|
|
948
|
-
+ export *
|
|
949
|
-
+}
|
|
950
|
-
diff --git a/ios/Sources/LlamaCppPlugin/LlamaCpp.swift b/ios/Sources/LlamaCppPlugin/LlamaCpp.swift
|
|
951
|
-
index 98f0ad0..a20a549 100644
|
|
952
|
-
--- a/ios/Sources/LlamaCppPlugin/LlamaCpp.swift
|
|
953
|
-
+++ b/ios/Sources/LlamaCppPlugin/LlamaCpp.swift
|
|
954
|
-
@@ -1,50 +1,127 @@
|
|
955
|
-
import Foundation
|
|
956
|
-
import Capacitor
|
|
957
|
-
+import Darwin
|
|
958
|
-
|
|
959
|
-
// MARK: - Native Library Integration
|
|
960
|
-
private var contexts: [Int64: UnsafeMutableRawPointer] = [:]
|
|
961
|
-
private var nextContextId: Int64 = 1
|
|
962
|
-
|
|
963
|
-
+private typealias NativeInitContext = @convention(c) (UnsafePointer<CChar>, UnsafePointer<CChar>) -> Int64
|
|
964
|
-
+private typealias NativeReleaseContext = @convention(c) (Int64) -> Void
|
|
965
|
-
+private typealias NativeCompletion = @convention(c) (Int64, UnsafePointer<CChar>, UnsafePointer<CChar>) -> UnsafeMutablePointer<CChar>?
|
|
966
|
-
+private typealias NativeStopCompletion = @convention(c) (Int64) -> Void
|
|
967
|
-
+private typealias NativeGetFormattedChat = @convention(c) (Int64, UnsafePointer<CChar>, UnsafePointer<CChar>) -> UnsafeMutablePointer<CChar>?
|
|
968
|
-
+private typealias NativeToggleLog = @convention(c) (Bool) -> Bool
|
|
969
|
-
+private typealias NativeEmbedding = @convention(c) (Int64, UnsafePointer<CChar>, UnsafePointer<CChar>) -> UnsafePointer<Float>?
|
|
970
|
-
+private typealias NativeRegisterEmbeddingContext = @convention(c) (Int64, UnsafeMutableRawPointer) -> Void
|
|
971
|
-
+private typealias NativeUnregisterEmbeddingContext = @convention(c) (Int64) -> Void
|
|
972
|
-
+private typealias NativeGetModelInfo = @convention(c) (Int64) -> UnsafeMutablePointer<CChar>?
|
|
973
|
-
+private typealias NativeGetContextPtr = @convention(c) (Int64) -> UnsafeMutableRawPointer?
|
|
974
|
-
+private typealias NativeGetLastError = @convention(c) () -> UnsafeMutablePointer<CChar>?
|
|
975
|
-
+private typealias NativeFreeString = @convention(c) (UnsafeMutablePointer<CChar>?) -> Void
|
|
976
|
-
+
|
|
977
|
-
// Load the native library (use enum to avoid lazy-on-global Swift error)
|
|
978
|
-
private enum LibraryLoader {
|
|
979
|
-
static var llamaLibrary: UnsafeMutableRawPointer? = {
|
|
980
|
-
- guard let libraryPath = Bundle.main.path(forResource: "llama-cpp", ofType: "framework") else {
|
|
981
|
-
- print("Error: llama-cpp framework not found")
|
|
982
|
-
- return nil
|
|
983
|
-
+ var candidates: [String] = []
|
|
984
|
-
+ if let frameworkPath = Bundle.main.path(forResource: "LlamaCpp", ofType: "framework") {
|
|
985
|
-
+ candidates.append((frameworkPath as NSString).appendingPathComponent("LlamaCpp"))
|
|
986
|
-
+ candidates.append(frameworkPath)
|
|
987
|
-
+ }
|
|
988
|
-
+ if let privateFrameworkURL = Bundle.main.privateFrameworksURL?.appendingPathComponent("LlamaCpp.framework/LlamaCpp") {
|
|
989
|
-
+ candidates.append(privateFrameworkURL.path)
|
|
990
|
-
+ }
|
|
991
|
-
+ if let frameworkPath = Bundle.main.path(forResource: "llama-cpp", ofType: "framework") {
|
|
992
|
-
+ candidates.append((frameworkPath as NSString).appendingPathComponent("llama-cpp"))
|
|
993
|
-
+ candidates.append(frameworkPath)
|
|
994
|
-
+ }
|
|
995
|
-
+ if let privateFrameworkURL = Bundle.main.privateFrameworksURL?.appendingPathComponent("llama-cpp.framework/llama-cpp") {
|
|
996
|
-
+ candidates.append(privateFrameworkURL.path)
|
|
997
|
-
}
|
|
998
|
-
- guard let handle = dlopen(libraryPath, RTLD_NOW) else {
|
|
999
|
-
- print("Error: Failed to load llama-cpp library: \(String(cString: dlerror()))")
|
|
1000
|
-
- return nil
|
|
1001
|
-
+ for path in candidates where FileManager.default.fileExists(atPath: path) {
|
|
1002
|
-
+ if let handle = dlopen(path, RTLD_NOW | RTLD_GLOBAL) {
|
|
1003
|
-
+ return handle
|
|
1004
|
-
+ }
|
|
1005
|
-
+ if let error = dlerror() {
|
|
1006
|
-
+ print("Error: Failed to load llama-cpp library at \(path): \(String(cString: error))")
|
|
1007
|
-
+ }
|
|
1008
|
-
}
|
|
1009
|
-
- return handle
|
|
1010
|
-
+ print("Error: llama-cpp framework binary not found")
|
|
1011
|
-
+ return nil
|
|
1012
|
-
}()
|
|
1013
|
-
}
|
|
1014
|
-
private var llamaLibrary: UnsafeMutableRawPointer? { LibraryLoader.llamaLibrary }
|
|
1015
|
-
|
|
1016
|
-
// Function pointers for native calls
|
|
1017
|
-
-private var initContextFunc: ((String, UnsafePointer<Int8>) -> Int64)?
|
|
1018
|
-
-private var releaseContextFunc: ((Int64) -> Void)?
|
|
1019
|
-
-private var completionFunc: ((Int64, String, UnsafePointer<Int8>) -> String?)?
|
|
1020
|
-
-private var stopCompletionFunc: ((Int64) -> Void)?
|
|
1021
|
-
-private var getFormattedChatFunc: ((Int64, String, String) -> String?)?
|
|
1022
|
-
-private var toggleNativeLogFunc: ((Bool) -> Bool)?
|
|
1023
|
-
-private var embeddingFunc: ((Int64, String, UnsafePointer<Int8>) -> UnsafePointer<Float>?)?
|
|
1024
|
-
-private var registerEmbeddingContextFunc: ((Int64, UnsafeMutableRawPointer) -> Void)?
|
|
1025
|
-
-private var unregisterEmbeddingContextFunc: ((Int64) -> Void)?
|
|
1026
|
-
+private var initContextFunc: NativeInitContext?
|
|
1027
|
-
+private var releaseContextFunc: NativeReleaseContext?
|
|
1028
|
-
+private var completionFunc: NativeCompletion?
|
|
1029
|
-
+private var stopCompletionFunc: NativeStopCompletion?
|
|
1030
|
-
+private var getFormattedChatFunc: NativeGetFormattedChat?
|
|
1031
|
-
+private var toggleNativeLogFunc: NativeToggleLog?
|
|
1032
|
-
+private var embeddingFunc: NativeEmbedding?
|
|
1033
|
-
+private var registerEmbeddingContextFunc: NativeRegisterEmbeddingContext?
|
|
1034
|
-
+private var unregisterEmbeddingContextFunc: NativeUnregisterEmbeddingContext?
|
|
1035
|
-
+private var getModelInfoFunc: NativeGetModelInfo?
|
|
1036
|
-
+private var getContextPtrFunc: NativeGetContextPtr?
|
|
1037
|
-
+private var getLastErrorFunc: NativeGetLastError?
|
|
1038
|
-
+private var freeStringFunc: NativeFreeString?
|
|
1039
|
-
+
|
|
1040
|
-
+private func loadSymbol<T>(_ name: String, as type: T.Type) -> T? {
|
|
1041
|
-
+ guard let library = llamaLibrary else { return nil }
|
|
1042
|
-
+ guard let symbol = dlsym(library, name) else {
|
|
1043
|
-
+ print("Error: native symbol \(name) not found")
|
|
1044
|
-
+ return nil
|
|
1045
|
-
+ }
|
|
1046
|
-
+ return unsafeBitCast(symbol, to: type)
|
|
1047
|
-
+}
|
|
1048
|
-
|
|
1049
|
-
private func loadFunctionPointers() {
|
|
1050
|
-
- guard let library = llamaLibrary else { return }
|
|
1051
|
-
-
|
|
1052
|
-
- // Load function pointers from the native library
|
|
1053
|
-
- initContextFunc = unsafeBitCast(dlsym(library, "llama_init_context"), to: ((String, UnsafePointer<Int8>) -> Int64).self)
|
|
1054
|
-
- releaseContextFunc = unsafeBitCast(dlsym(library, "llama_release_context"), to: ((Int64) -> Void).self)
|
|
1055
|
-
- completionFunc = unsafeBitCast(dlsym(library, "llama_completion"), to: ((Int64, String, UnsafePointer<Int8>) -> String?).self)
|
|
1056
|
-
- stopCompletionFunc = unsafeBitCast(dlsym(library, "llama_stop_completion"), to: ((Int64) -> Void).self)
|
|
1057
|
-
- getFormattedChatFunc = unsafeBitCast(dlsym(library, "llama_get_formatted_chat"), to: ((Int64, String, String) -> String?).self)
|
|
1058
|
-
- toggleNativeLogFunc = unsafeBitCast(dlsym(library, "llama_toggle_native_log"), to: ((Bool) -> Bool).self)
|
|
1059
|
-
- embeddingFunc = unsafeBitCast(dlsym(library, "llama_embedding"), to: ((Int64, String, UnsafePointer<Int8>) -> UnsafePointer<Float>?).self)
|
|
1060
|
-
- registerEmbeddingContextFunc = unsafeBitCast(dlsym(library, "llama_embedding_register_context"), to: ((Int64, UnsafeMutableRawPointer) -> Void).self)
|
|
1061
|
-
- unregisterEmbeddingContextFunc = unsafeBitCast(dlsym(library, "llama_embedding_unregister_context"), to: ((Int64) -> Void).self)
|
|
1062
|
-
+ initContextFunc = loadSymbol("llama_init_context", as: NativeInitContext.self)
|
|
1063
|
-
+ releaseContextFunc = loadSymbol("llama_release_context", as: NativeReleaseContext.self)
|
|
1064
|
-
+ completionFunc = loadSymbol("llama_completion", as: NativeCompletion.self)
|
|
1065
|
-
+ stopCompletionFunc = loadSymbol("llama_stop_completion", as: NativeStopCompletion.self)
|
|
1066
|
-
+ getFormattedChatFunc = loadSymbol("llama_get_formatted_chat", as: NativeGetFormattedChat.self)
|
|
1067
|
-
+ toggleNativeLogFunc = loadSymbol("llama_toggle_native_log", as: NativeToggleLog.self)
|
|
1068
|
-
+ embeddingFunc = loadSymbol("llama_embedding", as: NativeEmbedding.self)
|
|
1069
|
-
+ registerEmbeddingContextFunc = loadSymbol("llama_embedding_register_context", as: NativeRegisterEmbeddingContext.self)
|
|
1070
|
-
+ unregisterEmbeddingContextFunc = loadSymbol("llama_embedding_unregister_context", as: NativeUnregisterEmbeddingContext.self)
|
|
1071
|
-
+ getModelInfoFunc = loadSymbol("llama_get_model_info", as: NativeGetModelInfo.self)
|
|
1072
|
-
+ getContextPtrFunc = loadSymbol("llama_get_context_ptr", as: NativeGetContextPtr.self)
|
|
1073
|
-
+ getLastErrorFunc = loadSymbol("llama_get_last_error", as: NativeGetLastError.self)
|
|
1074
|
-
+ freeStringFunc = loadSymbol("llama_free_string", as: NativeFreeString.self)
|
|
1075
|
-
+}
|
|
1076
|
-
+
|
|
1077
|
-
+private func nativeLastError() -> String {
|
|
1078
|
-
+ guard let pointer = getLastErrorFunc?() else {
|
|
1079
|
-
+ return "Failed to initialize native context"
|
|
1080
|
-
+ }
|
|
1081
|
-
+ let message = String(cString: pointer)
|
|
1082
|
-
+ freeStringFunc?(pointer)
|
|
1083
|
-
+ return message.isEmpty ? "Failed to initialize native context" : message
|
|
1084
|
-
+}
|
|
1085
|
-
+
|
|
1086
|
-
+private func jsonObjectFromNativeString(_ pointer: UnsafeMutablePointer<CChar>?) throws -> Any {
|
|
1087
|
-
+ guard let pointer else {
|
|
1088
|
-
+ throw LlamaError.operationFailed("Native function returned null")
|
|
1089
|
-
+ }
|
|
1090
|
-
+ let jsonText = String(cString: pointer)
|
|
1091
|
-
+ freeStringFunc?(pointer)
|
|
1092
|
-
+ guard let data = jsonText.data(using: .utf8) else {
|
|
1093
|
-
+ throw LlamaError.operationFailed("Native JSON was not valid UTF-8")
|
|
1094
|
-
+ }
|
|
1095
|
-
+ return try JSONSerialization.jsonObject(with: data)
|
|
1096
|
-
+}
|
|
1097
|
-
+
|
|
1098
|
-
+private func dictionaryFromNativeString(_ pointer: UnsafeMutablePointer<CChar>?) throws -> [String: Any] {
|
|
1099
|
-
+ let object = try jsonObjectFromNativeString(pointer)
|
|
1100
|
-
+ guard let dictionary = object as? [String: Any] else {
|
|
1101
|
-
+ throw LlamaError.operationFailed("Native JSON did not contain an object")
|
|
1102
|
-
+ }
|
|
1103
|
-
+ if let error = dictionary["error"] as? String, !error.isEmpty {
|
|
1104
|
-
+ throw LlamaError.operationFailed(error)
|
|
1105
|
-
+ }
|
|
1106
|
-
+ return dictionary
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
// MARK: - Result Types
|
|
1110
|
-
@@ -56,7 +133,7 @@ enum LlamaError: Error, LocalizedError {
|
|
1111
|
-
case invalidParameters
|
|
1112
|
-
case operationFailed(String)
|
|
1113
|
-
case notImplemented
|
|
1114
|
-
-
|
|
1115
|
-
+
|
|
1116
|
-
var errorDescription: String? {
|
|
1117
|
-
switch self {
|
|
1118
|
-
case .contextNotFound:
|
|
1119
|
-
@@ -79,7 +156,7 @@ class LlamaContext {
|
|
1120
|
-
var model: LlamaModel?
|
|
1121
|
-
var isMultimodalEnabled: Bool = false
|
|
1122
|
-
var isVocoderEnabled: Bool = false
|
|
1123
|
-
-
|
|
1124
|
-
+
|
|
1125
|
-
init(id: Int) {
|
|
1126
|
-
self.id = id
|
|
1127
|
-
}
|
|
1128
|
-
@@ -93,7 +170,7 @@ class LlamaModel {
|
|
1129
|
-
let nParams: Int
|
|
1130
|
-
let chatTemplates: ChatTemplates
|
|
1131
|
-
let metadata: [String: Any]
|
|
1132
|
-
-
|
|
1133
|
-
+
|
|
1134
|
-
init(path: String, desc: String, size: Int, nEmbd: Int, nParams: Int, chatTemplates: ChatTemplates, metadata: [String: Any]) {
|
|
1135
|
-
self.path = path
|
|
1136
|
-
self.desc = desc
|
|
1137
|
-
@@ -108,7 +185,7 @@ class LlamaModel {
|
|
1138
|
-
struct ChatTemplates {
|
|
1139
|
-
let llamaChat: Bool
|
|
1140
|
-
let minja: MinjaTemplates
|
|
1141
|
-
-
|
|
1142
|
-
+
|
|
1143
|
-
init(llamaChat: Bool, minja: MinjaTemplates) {
|
|
1144
|
-
self.llamaChat = llamaChat
|
|
1145
|
-
self.minja = minja
|
|
1146
|
-
@@ -120,7 +197,7 @@ struct MinjaTemplates {
|
|
1147
|
-
let defaultCaps: MinjaCaps
|
|
1148
|
-
let toolUse: Bool
|
|
1149
|
-
let toolUseCaps: MinjaCaps
|
|
1150
|
-
-
|
|
1151
|
-
+
|
|
1152
|
-
init(default: Bool, defaultCaps: MinjaCaps, toolUse: Bool, toolUseCaps: MinjaCaps) {
|
|
1153
|
-
self.default = `default`
|
|
1154
|
-
self.defaultCaps = defaultCaps
|
|
1155
|
-
@@ -136,7 +213,7 @@ struct MinjaCaps {
|
|
1156
|
-
let systemRole: Bool
|
|
1157
|
-
let parallelToolCalls: Bool
|
|
1158
|
-
let toolCallId: Bool
|
|
1159
|
-
-
|
|
1160
|
-
+
|
|
1161
|
-
init(tools: Bool, toolCalls: Bool, toolResponses: Bool, systemRole: Bool, parallelToolCalls: Bool, toolCallId: Bool) {
|
|
1162
|
-
self.tools = tools
|
|
1163
|
-
self.toolCalls = toolCalls
|
|
1164
|
-
@@ -148,18 +225,39 @@ struct MinjaCaps {
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
// MARK: - Main Implementation
|
|
1168
|
-
-@objc public class LlamaCpp: NSObject {
|
|
1169
|
-
+@objc public class LlamaCpp: NSObject, URLSessionDownloadDelegate {
|
|
1170
|
-
private var contexts: [Int: LlamaContext] = [:]
|
|
1171
|
-
private var nativeContexts: [Int64: UnsafeMutableRawPointer] = [:]
|
|
1172
|
-
private var contextIdToNative: [Int: Int64] = [:]
|
|
1173
|
-
private var contextCounter: Int = 0
|
|
1174
|
-
private var contextLimit: Int = 10
|
|
1175
|
-
private var nativeLogEnabled: Bool = false
|
|
1176
|
-
-
|
|
1177
|
-
+ private struct DownloadContext {
|
|
1178
|
-
+ let url: String
|
|
1179
|
-
+ let localURL: URL
|
|
1180
|
-
+ let completion: (LlamaResult<String>) -> Void
|
|
1181
|
-
+ var lastBytes: Int64
|
|
1182
|
-
+ var lastUpdatedAt: Date
|
|
1183
|
-
+ }
|
|
1184
|
-
+ private var downloadProgressByUrl: [String: [String: Any]] = [:]
|
|
1185
|
-
+ private var downloadTasksByUrl: [String: URLSessionDownloadTask] = [:]
|
|
1186
|
-
+ private var downloadContextsByTaskId: [Int: DownloadContext] = [:]
|
|
1187
|
-
+ private lazy var downloadSession: URLSession = {
|
|
1188
|
-
+ let configuration = URLSessionConfiguration.default
|
|
1189
|
-
+ configuration.waitsForConnectivity = true
|
|
1190
|
-
+ configuration.allowsExpensiveNetworkAccess = true
|
|
1191
|
-
+ configuration.allowsConstrainedNetworkAccess = true
|
|
1192
|
-
+ return URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
|
|
1193
|
-
+ }()
|
|
1194
|
-
+
|
|
1195
|
-
// MARK: - Core initialization and management
|
|
1196
|
-
-
|
|
1197
|
-
+
|
|
1198
|
-
func toggleNativeLog(enabled: Bool, completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1199
|
-
nativeLogEnabled = enabled
|
|
1200
|
-
+ if toggleNativeLogFunc == nil {
|
|
1201
|
-
+ loadFunctionPointers()
|
|
1202
|
-
+ }
|
|
1203
|
-
+ _ = toggleNativeLogFunc?(enabled)
|
|
1204
|
-
if enabled {
|
|
1205
|
-
print("[LlamaCpp] Native logging enabled")
|
|
1206
|
-
} else {
|
|
1207
|
-
@@ -167,13 +265,13 @@ struct MinjaCaps {
|
|
1208
|
-
}
|
|
1209
|
-
completion(.success(()))
|
|
1210
|
-
}
|
|
1211
|
-
-
|
|
1212
|
-
+
|
|
1213
|
-
func setContextLimit(limit: Int, completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1214
|
-
contextLimit = limit
|
|
1215
|
-
print("[LlamaCpp] Context limit set to \(limit)")
|
|
1216
|
-
completion(.success(()))
|
|
1217
|
-
}
|
|
1218
|
-
-
|
|
1219
|
-
+
|
|
1220
|
-
func modelInfo(path: String, skip: [String], completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1221
|
-
// This would typically load model info from the GGUF file
|
|
1222
|
-
// For now, return a basic structure
|
|
1223
|
-
@@ -186,23 +284,23 @@ struct MinjaCaps {
|
|
1224
|
-
]
|
|
1225
|
-
completion(.success(modelInfo))
|
|
1226
|
-
}
|
|
1227
|
-
-
|
|
1228
|
-
+
|
|
1229
|
-
func initContext(contextId: Int, params: [String: Any], completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1230
|
-
// Check context limit
|
|
1231
|
-
if contexts.count >= contextLimit {
|
|
1232
|
-
completion(.failure(.operationFailed("Context limit reached")))
|
|
1233
|
-
return
|
|
1234
|
-
}
|
|
1235
|
-
-
|
|
1236
|
-
+
|
|
1237
|
-
// Extract parameters
|
|
1238
|
-
guard let modelPath = params["model"] as? String else {
|
|
1239
|
-
completion(.failure(.invalidParameters))
|
|
1240
|
-
return
|
|
1241
|
-
}
|
|
1242
|
-
-
|
|
1243
|
-
+
|
|
1244
|
-
// Create context
|
|
1245
|
-
let context = LlamaContext(id: contextId)
|
|
1246
|
-
-
|
|
1247
|
-
+
|
|
1248
|
-
// Create model info (this would typically load from GGUF file)
|
|
1249
|
-
let chatTemplates = ChatTemplates(
|
|
1250
|
-
llamaChat: true,
|
|
1251
|
-
@@ -227,8 +325,8 @@ struct MinjaCaps {
|
|
1252
|
-
)
|
|
1253
|
-
)
|
|
1254
|
-
)
|
|
1255
|
-
-
|
|
1256
|
-
- let model = LlamaModel(
|
|
1257
|
-
+
|
|
1258
|
-
+ var model = LlamaModel(
|
|
1259
|
-
path: modelPath,
|
|
1260
|
-
desc: "Sample model",
|
|
1261
|
-
size: 0,
|
|
1262
|
-
@@ -237,9 +335,9 @@ struct MinjaCaps {
|
|
1263
|
-
chatTemplates: chatTemplates,
|
|
1264
|
-
metadata: [:]
|
|
1265
|
-
)
|
|
1266
|
-
-
|
|
1267
|
-
+
|
|
1268
|
-
context.model = model
|
|
1269
|
-
-
|
|
1270
|
-
+
|
|
1271
|
-
// Call native initContext to create the actual C++ context
|
|
1272
|
-
// Convert params to JSON string
|
|
1273
|
-
var paramsJson = "{}"
|
|
1274
|
-
@@ -250,41 +348,64 @@ struct MinjaCaps {
|
|
1275
|
-
completion(.failure(.operationFailed("Failed to serialize params: \(error.localizedDescription)")))
|
|
1276
|
-
return
|
|
1277
|
-
}
|
|
1278
|
-
-
|
|
1279
|
-
+
|
|
1280
|
-
// Ensure function pointers are loaded
|
|
1281
|
-
if initContextFunc == nil {
|
|
1282
|
-
loadFunctionPointers()
|
|
1283
|
-
}
|
|
1284
|
-
-
|
|
1285
|
-
+
|
|
1286
|
-
// Call native function to initialize context
|
|
1287
|
-
guard let initFunc = initContextFunc else {
|
|
1288
|
-
completion(.failure(.operationFailed("Native initContext function not available")))
|
|
1289
|
-
return
|
|
1290
|
-
}
|
|
1291
|
-
-
|
|
1292
|
-
- let nativeContextId = initFunc(modelPath, paramsJson.cString(using: .utf8)!)
|
|
1293
|
-
+
|
|
1294
|
-
+ let nativeContextId = modelPath.withCString { modelCString in
|
|
1295
|
-
+ paramsJson.withCString { paramsCString in
|
|
1296
|
-
+ initFunc(modelCString, paramsCString)
|
|
1297
|
-
+ }
|
|
1298
|
-
+ }
|
|
1299
|
-
if nativeContextId > 0 {
|
|
1300
|
-
+ if let modelInfoPtr = getModelInfoFunc?(nativeContextId),
|
|
1301
|
-
+ let modelInfo = try? dictionaryFromNativeString(modelInfoPtr) {
|
|
1302
|
-
+ let numberSize = modelInfo["size"] as? NSNumber
|
|
1303
|
-
+ let numberEmbd = modelInfo["nEmbd"] as? NSNumber
|
|
1304
|
-
+ let numberParams = modelInfo["nParams"] as? NSNumber
|
|
1305
|
-
+ model = LlamaModel(
|
|
1306
|
-
+ path: modelPath,
|
|
1307
|
-
+ desc: modelInfo["desc"] as? String ?? model.desc,
|
|
1308
|
-
+ size: numberSize?.intValue ?? model.size,
|
|
1309
|
-
+ nEmbd: numberEmbd?.intValue ?? model.nEmbd,
|
|
1310
|
-
+ nParams: numberParams?.intValue ?? model.nParams,
|
|
1311
|
-
+ chatTemplates: chatTemplates,
|
|
1312
|
-
+ metadata: modelInfo["metadata"] as? [String: Any] ?? [:]
|
|
1313
|
-
+ )
|
|
1314
|
-
+ context.model = model
|
|
1315
|
-
+ }
|
|
1316
|
-
// Store the LlamaContext for Swift bookkeeping
|
|
1317
|
-
contexts[contextId] = context
|
|
1318
|
-
// Store the native context pointer and mapping for C layer
|
|
1319
|
-
- let nativePtr = UnsafeMutableRawPointer(bitPattern: Int(nativeContextId))
|
|
1320
|
-
- nativeContexts[nativeContextId] = nativePtr
|
|
1321
|
-
+ let nativePtr = getContextPtrFunc?(nativeContextId)
|
|
1322
|
-
+ if let nativePtr {
|
|
1323
|
-
+ nativeContexts[nativeContextId] = nativePtr
|
|
1324
|
-
+ }
|
|
1325
|
-
contextIdToNative[contextId] = nativeContextId
|
|
1326
|
-
-
|
|
1327
|
-
+
|
|
1328
|
-
// Register with embedding system if available
|
|
1329
|
-
- if let registerFunc = registerEmbeddingContextFunc, let ptr = nativePtr {
|
|
1330
|
-
- registerFunc(nativeContextId, ptr)
|
|
1331
|
-
+ if let registerFunc = registerEmbeddingContextFunc, let nativePtr {
|
|
1332
|
-
+ registerFunc(nativeContextId, nativePtr)
|
|
1333
|
-
}
|
|
1334
|
-
} else {
|
|
1335
|
-
- completion(.failure(.operationFailed("Failed to initialize native context")))
|
|
1336
|
-
+ completion(.failure(.operationFailed(nativeLastError())))
|
|
1337
|
-
return
|
|
1338
|
-
}
|
|
1339
|
-
-
|
|
1340
|
-
+
|
|
1341
|
-
// Return context info
|
|
1342
|
-
+ let gpuRequested = (params["no_gpu_devices"] as? Bool) != true && ((params["n_gpu_layers"] as? Int) ?? 0) != 0
|
|
1343
|
-
let contextInfo: [String: Any] = [
|
|
1344
|
-
"contextId": contextId,
|
|
1345
|
-
- "gpu": false,
|
|
1346
|
-
- "reasonNoGPU": "Not implemented",
|
|
1347
|
-
+ "gpu": gpuRequested,
|
|
1348
|
-
+ "reasonNoGPU": gpuRequested ? "" : "GPU disabled by load options",
|
|
1349
|
-
"model": [
|
|
1350
|
-
"desc": model.desc,
|
|
1351
|
-
"size": model.size,
|
|
1352
|
-
@@ -317,34 +438,34 @@ struct MinjaCaps {
|
|
1353
|
-
"isChatTemplateSupported": true
|
|
1354
|
-
]
|
|
1355
|
-
]
|
|
1356
|
-
-
|
|
1357
|
-
+
|
|
1358
|
-
completion(.success(contextInfo))
|
|
1359
|
-
}
|
|
1360
|
-
-
|
|
1361
|
-
+
|
|
1362
|
-
func releaseContext(contextId: Int, completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1363
|
-
guard contexts[contextId] != nil else {
|
|
1364
|
-
completion(.failure(.contextNotFound))
|
|
1365
|
-
return
|
|
1366
|
-
}
|
|
1367
|
-
-
|
|
1368
|
-
+
|
|
1369
|
-
let nativeId = contextIdToNative[contextId] ?? Int64(contextId)
|
|
1370
|
-
-
|
|
1371
|
-
+
|
|
1372
|
-
// Unregister from embedding system if available
|
|
1373
|
-
if let unregisterFunc = unregisterEmbeddingContextFunc {
|
|
1374
|
-
unregisterFunc(nativeId)
|
|
1375
|
-
}
|
|
1376
|
-
-
|
|
1377
|
-
+
|
|
1378
|
-
// Call native release function
|
|
1379
|
-
if let releaseFunc = releaseContextFunc {
|
|
1380
|
-
releaseFunc(nativeId)
|
|
1381
|
-
}
|
|
1382
|
-
-
|
|
1383
|
-
+
|
|
1384
|
-
contexts.removeValue(forKey: contextId)
|
|
1385
|
-
nativeContexts.removeValue(forKey: nativeId)
|
|
1386
|
-
contextIdToNative.removeValue(forKey: contextId)
|
|
1387
|
-
completion(.success(()))
|
|
1388
|
-
}
|
|
1389
|
-
-
|
|
1390
|
-
+
|
|
1391
|
-
func releaseAllContexts(completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1392
|
-
// Unregister all contexts from embedding system
|
|
1393
|
-
if let unregisterFunc = unregisterEmbeddingContextFunc {
|
|
1394
|
-
@@ -352,95 +473,122 @@ struct MinjaCaps {
|
|
1395
|
-
unregisterFunc(nativeId)
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
-
|
|
1399
|
-
+ if let releaseFunc = releaseContextFunc {
|
|
1400
|
-
+ for (_, nativeId) in contextIdToNative {
|
|
1401
|
-
+ releaseFunc(nativeId)
|
|
1402
|
-
+ }
|
|
1403
|
-
+ }
|
|
1404
|
-
+
|
|
1405
|
-
contexts.removeAll()
|
|
1406
|
-
nativeContexts.removeAll()
|
|
1407
|
-
contextIdToNative.removeAll()
|
|
1408
|
-
completion(.success(()))
|
|
1409
|
-
}
|
|
1410
|
-
-
|
|
1411
|
-
+
|
|
1412
|
-
// MARK: - Chat and completion
|
|
1413
|
-
-
|
|
1414
|
-
+
|
|
1415
|
-
func getFormattedChat(contextId: Int, messages: String, chatTemplate: String?, params: [String: Any]?, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1416
|
-
- guard let context = contexts[contextId] else {
|
|
1417
|
-
+ guard contexts[contextId] != nil else {
|
|
1418
|
-
completion(.failure(.contextNotFound))
|
|
1419
|
-
return
|
|
1420
|
-
}
|
|
1421
|
-
-
|
|
1422
|
-
- // This would typically format the chat using the model's chat templates
|
|
1423
|
-
- // For now, return a basic formatted chat
|
|
1424
|
-
- let formattedChat: [String: Any] = [
|
|
1425
|
-
- "type": "llama-chat",
|
|
1426
|
-
- "prompt": messages,
|
|
1427
|
-
- "has_media": false,
|
|
1428
|
-
- "media_paths": []
|
|
1429
|
-
- ]
|
|
1430
|
-
-
|
|
1431
|
-
- completion(.success(formattedChat))
|
|
1432
|
-
+ if getFormattedChatFunc == nil {
|
|
1433
|
-
+ loadFunctionPointers()
|
|
1434
|
-
+ }
|
|
1435
|
-
+ guard let nativeId = contextIdToNative[contextId],
|
|
1436
|
-
+ let formatFunc = getFormattedChatFunc else {
|
|
1437
|
-
+ completion(.failure(.operationFailed("Native getFormattedChat function not available")))
|
|
1438
|
-
+ return
|
|
1439
|
-
+ }
|
|
1440
|
-
+ let template = chatTemplate ?? ""
|
|
1441
|
-
+ do {
|
|
1442
|
-
+ let formatted = try messages.withCString { messagesCString in
|
|
1443
|
-
+ try template.withCString { templateCString in
|
|
1444
|
-
+ let ptr = formatFunc(nativeId, messagesCString, templateCString)
|
|
1445
|
-
+ let object = try jsonObjectFromNativeString(ptr)
|
|
1446
|
-
+ return object as? String ?? messages
|
|
1447
|
-
+ }
|
|
1448
|
-
+ }
|
|
1449
|
-
+ let formattedChat: [String: Any] = [
|
|
1450
|
-
+ "type": "llama-chat",
|
|
1451
|
-
+ "prompt": formatted,
|
|
1452
|
-
+ "has_media": false,
|
|
1453
|
-
+ "media_paths": []
|
|
1454
|
-
+ ]
|
|
1455
|
-
+ completion(.success(formattedChat))
|
|
1456
|
-
+ } catch let error as LlamaError {
|
|
1457
|
-
+ completion(.failure(error))
|
|
1458
|
-
+ } catch {
|
|
1459
|
-
+ completion(.failure(.operationFailed(error.localizedDescription)))
|
|
1460
|
-
+ }
|
|
1461
|
-
}
|
|
1462
|
-
-
|
|
1463
|
-
+
|
|
1464
|
-
func completion(contextId: Int, params: [String: Any], completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1465
|
-
- guard let context = contexts[contextId] else {
|
|
1466
|
-
+ guard contexts[contextId] != nil else {
|
|
1467
|
-
completion(.failure(.contextNotFound))
|
|
1468
|
-
return
|
|
1469
|
-
}
|
|
1470
|
-
-
|
|
1471
|
-
- // This would typically perform the completion using llama.cpp
|
|
1472
|
-
- // For now, return a basic completion result
|
|
1473
|
-
- let completionResult: [String: Any] = [
|
|
1474
|
-
- "text": "Sample completion text",
|
|
1475
|
-
- "reasoning_content": "",
|
|
1476
|
-
- "tool_calls": [],
|
|
1477
|
-
- "content": "Sample completion text",
|
|
1478
|
-
- "chat_format": 0,
|
|
1479
|
-
- "tokens_predicted": 0,
|
|
1480
|
-
- "tokens_evaluated": 0,
|
|
1481
|
-
- "truncated": false,
|
|
1482
|
-
- "stopped_eos": false,
|
|
1483
|
-
- "stopped_word": "",
|
|
1484
|
-
- "stopped_limit": 0,
|
|
1485
|
-
- "stopping_word": "",
|
|
1486
|
-
- "context_full": false,
|
|
1487
|
-
- "interrupted": false,
|
|
1488
|
-
- "tokens_cached": 0,
|
|
1489
|
-
- "timings": [
|
|
1490
|
-
- "prompt_n": 0,
|
|
1491
|
-
- "prompt_ms": 0,
|
|
1492
|
-
- "prompt_per_token_ms": 0,
|
|
1493
|
-
- "prompt_per_second": 0,
|
|
1494
|
-
- "predicted_n": 0,
|
|
1495
|
-
- "predicted_ms": 0,
|
|
1496
|
-
- "predicted_per_token_ms": 0,
|
|
1497
|
-
- "predicted_per_second": 0
|
|
1498
|
-
- ]
|
|
1499
|
-
- ]
|
|
1500
|
-
-
|
|
1501
|
-
- completion(.success(completionResult))
|
|
1502
|
-
+ if completionFunc == nil {
|
|
1503
|
-
+ loadFunctionPointers()
|
|
1504
|
-
+ }
|
|
1505
|
-
+ guard let nativeId = contextIdToNative[contextId],
|
|
1506
|
-
+ let completionFunc else {
|
|
1507
|
-
+ completion(.failure(.operationFailed("Native completion function not available")))
|
|
1508
|
-
+ return
|
|
1509
|
-
+ }
|
|
1510
|
-
+ guard let prompt = params["prompt"] as? String, !prompt.isEmpty else {
|
|
1511
|
-
+ completion(.failure(.invalidParameters))
|
|
1512
|
-
+ return
|
|
1513
|
-
+ }
|
|
1514
|
-
+ var paramsJson = "{}"
|
|
1515
|
-
+ do {
|
|
1516
|
-
+ let paramsData = try JSONSerialization.data(withJSONObject: params)
|
|
1517
|
-
+ paramsJson = String(data: paramsData, encoding: .utf8) ?? "{}"
|
|
1518
|
-
+ } catch {
|
|
1519
|
-
+ completion(.failure(.operationFailed("Failed to serialize params: \(error.localizedDescription)")))
|
|
1520
|
-
+ return
|
|
1521
|
-
+ }
|
|
1522
|
-
+ do {
|
|
1523
|
-
+ let result = try prompt.withCString { promptCString in
|
|
1524
|
-
+ try paramsJson.withCString { paramsCString in
|
|
1525
|
-
+ try dictionaryFromNativeString(completionFunc(nativeId, promptCString, paramsCString))
|
|
1526
|
-
+ }
|
|
1527
|
-
+ }
|
|
1528
|
-
+ completion(.success(result))
|
|
1529
|
-
+ } catch let error as LlamaError {
|
|
1530
|
-
+ completion(.failure(error))
|
|
1531
|
-
+ } catch {
|
|
1532
|
-
+ completion(.failure(.operationFailed(error.localizedDescription)))
|
|
1533
|
-
+ }
|
|
1534
|
-
}
|
|
1535
|
-
-
|
|
1536
|
-
+
|
|
1537
|
-
func stopCompletion(contextId: Int, completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1538
|
-
guard contexts[contextId] != nil else {
|
|
1539
|
-
completion(.failure(.contextNotFound))
|
|
1540
|
-
return
|
|
1541
|
-
}
|
|
1542
|
-
-
|
|
1543
|
-
- // This would typically stop any ongoing completion
|
|
1544
|
-
+
|
|
1545
|
-
+ if stopCompletionFunc == nil {
|
|
1546
|
-
+ loadFunctionPointers()
|
|
1547
|
-
+ }
|
|
1548
|
-
+ let nativeId = contextIdToNative[contextId] ?? Int64(contextId)
|
|
1549
|
-
+ stopCompletionFunc?(nativeId)
|
|
1550
|
-
completion(.success(()))
|
|
1551
|
-
}
|
|
1552
|
-
-
|
|
1553
|
-
+
|
|
1554
|
-
// MARK: - Chat-first methods (like llama-cli -sys)
|
|
1555
|
-
-
|
|
1556
|
-
+
|
|
1557
|
-
func chat(contextId: Int, messages: [JSObject], system: String?, chatTemplate: String?, params: [String: Any]?, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1558
|
-
guard contexts[contextId] != nil else {
|
|
1559
|
-
completion(.failure(.contextNotFound))
|
|
1560
|
-
return
|
|
1561
|
-
}
|
|
1562
|
-
-
|
|
1563
|
-
+
|
|
1564
|
-
do {
|
|
1565
|
-
// Convert JSObject messages to JSON string
|
|
1566
|
-
let messagesData = try JSONSerialization.data(withJSONObject: messages)
|
|
1567
|
-
let messagesJson = String(data: messagesData, encoding: .utf8) ?? "[]"
|
|
1568
|
-
-
|
|
1569
|
-
+
|
|
1570
|
-
// Add system message if provided
|
|
1571
|
-
var allMessages = messages
|
|
1572
|
-
if let system = system, !system.isEmpty {
|
|
1573
|
-
@@ -451,35 +599,35 @@ struct MinjaCaps {
|
|
1574
|
-
let jsSystem = JSTypes.coerceDictionaryToJSObject(systemMessage) ?? [:]
|
|
1575
|
-
allMessages.insert(jsSystem, at: 0)
|
|
1576
|
-
}
|
|
1577
|
-
-
|
|
1578
|
-
+
|
|
1579
|
-
// Convert to JSON string for getFormattedChat
|
|
1580
|
-
let allMessagesData = try JSONSerialization.data(withJSONObject: allMessages)
|
|
1581
|
-
let allMessagesJson = String(data: allMessagesData, encoding: .utf8) ?? "[]"
|
|
1582
|
-
-
|
|
1583
|
-
+
|
|
1584
|
-
// First, format the chat
|
|
1585
|
-
getFormattedChat(contextId: contextId, messages: allMessagesJson, chatTemplate: chatTemplate, params: nil) { [weak self] result in
|
|
1586
|
-
switch result {
|
|
1587
|
-
case .success(let formattedResult):
|
|
1588
|
-
// Extract the formatted prompt
|
|
1589
|
-
let formattedPrompt = formattedResult["prompt"] as? String ?? ""
|
|
1590
|
-
-
|
|
1591
|
-
+
|
|
1592
|
-
// Create completion parameters
|
|
1593
|
-
var completionParams = params ?? [:]
|
|
1594
|
-
completionParams["prompt"] = formattedPrompt
|
|
1595
|
-
-
|
|
1596
|
-
+
|
|
1597
|
-
// Call completion with formatted prompt
|
|
1598
|
-
self?.completion(contextId: contextId, params: completionParams, completion: completion)
|
|
1599
|
-
-
|
|
1600
|
-
+
|
|
1601
|
-
case .failure(let error):
|
|
1602
|
-
completion(.failure(error))
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
-
|
|
1606
|
-
+
|
|
1607
|
-
} catch {
|
|
1608
|
-
completion(.failure(.contextNotFound)) // Use a more appropriate error
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
-
|
|
1612
|
-
+
|
|
1613
|
-
func chatWithSystem(contextId: Int, system: String, message: String, params: [String: Any]?, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1614
|
-
// Create a simple message array
|
|
1615
|
-
let userMessage: [String: Any] = [
|
|
1616
|
-
@@ -488,60 +636,60 @@ struct MinjaCaps {
|
|
1617
|
-
]
|
|
1618
|
-
let jsUser = JSTypes.coerceDictionaryToJSObject(userMessage) ?? [:]
|
|
1619
|
-
let messages: [JSObject] = [jsUser]
|
|
1620
|
-
-
|
|
1621
|
-
+
|
|
1622
|
-
// Call the main chat method
|
|
1623
|
-
chat(contextId: contextId, messages: messages, system: system, chatTemplate: nil, params: params, completion: completion)
|
|
1624
|
-
}
|
|
1625
|
-
-
|
|
1626
|
-
+
|
|
1627
|
-
func generateText(contextId: Int, prompt: String, params: [String: Any]?, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1628
|
-
guard contexts[contextId] != nil else {
|
|
1629
|
-
completion(.failure(.contextNotFound))
|
|
1630
|
-
return
|
|
1631
|
-
}
|
|
1632
|
-
-
|
|
1633
|
-
+
|
|
1634
|
-
// Create completion parameters
|
|
1635
|
-
var completionParams = params ?? [:]
|
|
1636
|
-
completionParams["prompt"] = prompt
|
|
1637
|
-
-
|
|
1638
|
-
+
|
|
1639
|
-
// Call completion method directly
|
|
1640
|
-
self.completion(contextId: contextId, params: completionParams, completion: completion)
|
|
1641
|
-
}
|
|
1642
|
-
-
|
|
1643
|
-
+
|
|
1644
|
-
// MARK: - Session management
|
|
1645
|
-
-
|
|
1646
|
-
+
|
|
1647
|
-
func loadSession(contextId: Int, filepath: String, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1648
|
-
guard contexts[contextId] != nil else {
|
|
1649
|
-
completion(.failure(.contextNotFound))
|
|
1650
|
-
return
|
|
1651
|
-
}
|
|
1652
|
-
-
|
|
1653
|
-
+
|
|
1654
|
-
// This would typically load session from file
|
|
1655
|
-
let sessionResult: [String: Any] = [
|
|
1656
|
-
"tokens_loaded": 0,
|
|
1657
|
-
"prompt": ""
|
|
1658
|
-
]
|
|
1659
|
-
-
|
|
1660
|
-
+
|
|
1661
|
-
completion(.success(sessionResult))
|
|
1662
|
-
}
|
|
1663
|
-
-
|
|
1664
|
-
+
|
|
1665
|
-
func saveSession(contextId: Int, filepath: String, size: Int, completion: @escaping (LlamaResult<Int>) -> Void) {
|
|
1666
|
-
guard contexts[contextId] != nil else {
|
|
1667
|
-
completion(.failure(.contextNotFound))
|
|
1668
|
-
return
|
|
1669
|
-
}
|
|
1670
|
-
-
|
|
1671
|
-
+
|
|
1672
|
-
// This would typically save session to file
|
|
1673
|
-
completion(.success(0))
|
|
1674
|
-
}
|
|
1675
|
-
-
|
|
1676
|
-
+
|
|
1677
|
-
// MARK: - Tokenization
|
|
1678
|
-
-
|
|
1679
|
-
+
|
|
1680
|
-
func tokenize(contextId: Int, text: String, imagePaths: [String], completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1681
|
-
guard contexts[contextId] != nil else {
|
|
1682
|
-
completion(.failure(.contextNotFound))
|
|
1683
|
-
return
|
|
1684
|
-
}
|
|
1685
|
-
-
|
|
1686
|
-
+
|
|
1687
|
-
// This would typically tokenize the text using the model's tokenizer
|
|
1688
|
-
let tokenizeResult: [String: Any] = [
|
|
1689
|
-
"tokens": [],
|
|
1690
|
-
@@ -550,33 +698,33 @@ struct MinjaCaps {
|
|
1691
|
-
"chunk_pos": [],
|
|
1692
|
-
"chunk_pos_images": []
|
|
1693
|
-
]
|
|
1694
|
-
-
|
|
1695
|
-
+
|
|
1696
|
-
completion(.success(tokenizeResult))
|
|
1697
|
-
}
|
|
1698
|
-
-
|
|
1699
|
-
+
|
|
1700
|
-
func detokenize(contextId: Int, tokens: [Int], completion: @escaping (LlamaResult<String>) -> Void) {
|
|
1701
|
-
guard contexts[contextId] != nil else {
|
|
1702
|
-
completion(.failure(.contextNotFound))
|
|
1703
|
-
return
|
|
1704
|
-
}
|
|
1705
|
-
-
|
|
1706
|
-
+
|
|
1707
|
-
// This would typically detokenize using the model's tokenizer
|
|
1708
|
-
completion(.success(""))
|
|
1709
|
-
}
|
|
1710
|
-
-
|
|
1711
|
-
+
|
|
1712
|
-
// MARK: - Embeddings and reranking
|
|
1713
|
-
-
|
|
1714
|
-
+
|
|
1715
|
-
func embedding(contextId: Int, text: String, params: [String: Any], completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1716
|
-
guard let context = contexts[contextId] else {
|
|
1717
|
-
completion(.failure(.contextNotFound))
|
|
1718
|
-
return
|
|
1719
|
-
}
|
|
1720
|
-
-
|
|
1721
|
-
+
|
|
1722
|
-
// Ensure function pointers are loaded
|
|
1723
|
-
if embeddingFunc == nil {
|
|
1724
|
-
loadFunctionPointers()
|
|
1725
|
-
}
|
|
1726
|
-
-
|
|
1727
|
-
+
|
|
1728
|
-
// Check if native embedding function is available
|
|
1729
|
-
guard let embeddingFunction = embeddingFunc else {
|
|
1730
|
-
// Native function not available - this means the C++ layer needs to implement it
|
|
1731
|
-
@@ -585,13 +733,13 @@ struct MinjaCaps {
|
|
1732
|
-
completion(.failure(.notImplemented))
|
|
1733
|
-
return
|
|
1734
|
-
}
|
|
1735
|
-
-
|
|
1736
|
-
+
|
|
1737
|
-
// Get embedding dimension from model
|
|
1738
|
-
guard let nEmbd = context.model?.nEmbd, nEmbd > 0 else {
|
|
1739
|
-
completion(.failure(.operationFailed("Model embedding dimension (n_embd) not available. Model may not be loaded or may not support embeddings.")))
|
|
1740
|
-
return
|
|
1741
|
-
}
|
|
1742
|
-
-
|
|
1743
|
-
+
|
|
1744
|
-
// Convert params to JSON string for native call
|
|
1745
|
-
var paramsJson = "{}"
|
|
1746
|
-
if !params.isEmpty {
|
|
1747
|
-
@@ -602,249 +750,256 @@ struct MinjaCaps {
|
|
1748
|
-
print("Error serializing params: \(error)")
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
-
|
|
1752
|
-
- // Call native embedding function
|
|
1753
|
-
- let paramsCString = paramsJson.cString(using: .utf8)
|
|
1754
|
-
- guard let baseAddress = paramsCString else {
|
|
1755
|
-
- completion(.failure(.operationFailed("Failed to convert params to C string")))
|
|
1756
|
-
- return
|
|
1757
|
-
+
|
|
1758
|
-
+ let nativeId = contextIdToNative[contextId] ?? Int64(contextId)
|
|
1759
|
-
+ let embeddingPtr = text.withCString { textCString in
|
|
1760
|
-
+ paramsJson.withCString { paramsCString in
|
|
1761
|
-
+ embeddingFunction(nativeId, textCString, paramsCString)
|
|
1762
|
-
+ }
|
|
1763
|
-
}
|
|
1764
|
-
-
|
|
1765
|
-
- // Get embedding vector from native layer
|
|
1766
|
-
- // Note: The native function signature should be:
|
|
1767
|
-
- // UnsafePointer<Float>? llama_embedding(Int64 contextId, String text, UnsafePointer<Int8> params)
|
|
1768
|
-
- // The returned pointer should point to an array of nEmbd floats
|
|
1769
|
-
- if let embeddingPtr = embeddingFunction(Int64(contextId), text, baseAddress) {
|
|
1770
|
-
+ if let embeddingPtr {
|
|
1771
|
-
// Convert C array to Swift array
|
|
1772
|
-
let embeddingArray = Array(UnsafeBufferPointer(start: embeddingPtr, count: nEmbd))
|
|
1773
|
-
-
|
|
1774
|
-
+
|
|
1775
|
-
// Convert Float array to Double array for JSON compatibility
|
|
1776
|
-
let embeddingDoubles = embeddingArray.map { Double($0) }
|
|
1777
|
-
-
|
|
1778
|
-
+
|
|
1779
|
-
let embeddingResult: [String: Any] = [
|
|
1780
|
-
"embedding": embeddingDoubles,
|
|
1781
|
-
"n_embd": nEmbd
|
|
1782
|
-
]
|
|
1783
|
-
-
|
|
1784
|
-
+
|
|
1785
|
-
completion(.success(embeddingResult))
|
|
1786
|
-
} else {
|
|
1787
|
-
completion(.failure(.operationFailed("Native embedding function returned null. Check native C++ implementation.")))
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
-
|
|
1791
|
-
+
|
|
1792
|
-
func rerank(contextId: Int, query: String, documents: [String], params: [String: Any]?, completion: @escaping (LlamaResult<[[String: Any]]>) -> Void) {
|
|
1793
|
-
guard contexts[contextId] != nil else {
|
|
1794
|
-
completion(.failure(.contextNotFound))
|
|
1795
|
-
return
|
|
1796
|
-
}
|
|
1797
|
-
-
|
|
1798
|
-
+
|
|
1799
|
-
// This would typically perform reranking
|
|
1800
|
-
let rerankResults: [[String: Any]] = []
|
|
1801
|
-
completion(.success(rerankResults))
|
|
1802
|
-
}
|
|
1803
|
-
-
|
|
1804
|
-
+
|
|
1805
|
-
// MARK: - Benchmarking
|
|
1806
|
-
-
|
|
1807
|
-
+
|
|
1808
|
-
func bench(contextId: Int, pp: Int, tg: Int, pl: Int, nr: Int, completion: @escaping (LlamaResult<String>) -> Void) {
|
|
1809
|
-
guard contexts[contextId] != nil else {
|
|
1810
|
-
completion(.failure(.contextNotFound))
|
|
1811
|
-
return
|
|
1812
|
-
}
|
|
1813
|
-
-
|
|
1814
|
-
+
|
|
1815
|
-
// This would typically run benchmarks
|
|
1816
|
-
let benchResult = "[]"
|
|
1817
|
-
completion(.success(benchResult))
|
|
1818
|
-
}
|
|
1819
|
-
-
|
|
1820
|
-
+
|
|
1821
|
-
// MARK: - LoRA adapters
|
|
1822
|
-
-
|
|
1823
|
-
+
|
|
1824
|
-
func applyLoraAdapters(contextId: Int, loraAdapters: [[String: Any]], completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1825
|
-
guard contexts[contextId] != nil else {
|
|
1826
|
-
completion(.failure(.contextNotFound))
|
|
1827
|
-
return
|
|
1828
|
-
}
|
|
1829
|
-
-
|
|
1830
|
-
+
|
|
1831
|
-
// This would typically apply LoRA adapters
|
|
1832
|
-
completion(.success(()))
|
|
1833
|
-
}
|
|
1834
|
-
-
|
|
1835
|
-
+
|
|
1836
|
-
func removeLoraAdapters(contextId: Int, completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1837
|
-
guard contexts[contextId] != nil else {
|
|
1838
|
-
completion(.failure(.contextNotFound))
|
|
1839
|
-
return
|
|
1840
|
-
}
|
|
1841
|
-
-
|
|
1842
|
-
+
|
|
1843
|
-
// This would typically remove LoRA adapters
|
|
1844
|
-
completion(.success(()))
|
|
1845
|
-
}
|
|
1846
|
-
-
|
|
1847
|
-
+
|
|
1848
|
-
func getLoadedLoraAdapters(contextId: Int, completion: @escaping (LlamaResult<[[String: Any]]>) -> Void) {
|
|
1849
|
-
guard contexts[contextId] != nil else {
|
|
1850
|
-
completion(.failure(.contextNotFound))
|
|
1851
|
-
return
|
|
1852
|
-
}
|
|
1853
|
-
-
|
|
1854
|
-
+
|
|
1855
|
-
// This would typically return loaded LoRA adapters
|
|
1856
|
-
let adapters: [[String: Any]] = []
|
|
1857
|
-
completion(.success(adapters))
|
|
1858
|
-
}
|
|
1859
|
-
-
|
|
1860
|
-
+
|
|
1861
|
-
// MARK: - Multimodal methods
|
|
1862
|
-
-
|
|
1863
|
-
+
|
|
1864
|
-
func initMultimodal(contextId: Int, path: String, useGpu: Bool, completion: @escaping (LlamaResult<Bool>) -> Void) {
|
|
1865
|
-
guard let context = contexts[contextId] else {
|
|
1866
|
-
completion(.failure(.contextNotFound))
|
|
1867
|
-
return
|
|
1868
|
-
}
|
|
1869
|
-
-
|
|
1870
|
-
+
|
|
1871
|
-
context.isMultimodalEnabled = true
|
|
1872
|
-
completion(.success(true))
|
|
1873
|
-
}
|
|
1874
|
-
-
|
|
1875
|
-
+
|
|
1876
|
-
func isMultimodalEnabled(contextId: Int, completion: @escaping (LlamaResult<Bool>) -> Void) {
|
|
1877
|
-
guard let context = contexts[contextId] else {
|
|
1878
|
-
completion(.failure(.contextNotFound))
|
|
1879
|
-
return
|
|
1880
|
-
}
|
|
1881
|
-
-
|
|
1882
|
-
+
|
|
1883
|
-
completion(.success(context.isMultimodalEnabled))
|
|
1884
|
-
}
|
|
1885
|
-
-
|
|
1886
|
-
+
|
|
1887
|
-
func getMultimodalSupport(contextId: Int, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1888
|
-
guard contexts[contextId] != nil else {
|
|
1889
|
-
completion(.failure(.contextNotFound))
|
|
1890
|
-
return
|
|
1891
|
-
}
|
|
1892
|
-
-
|
|
1893
|
-
+
|
|
1894
|
-
let support: [String: Any] = [
|
|
1895
|
-
"vision": true,
|
|
1896
|
-
"audio": true
|
|
1897
|
-
]
|
|
1898
|
-
-
|
|
1899
|
-
+
|
|
1900
|
-
completion(.success(support))
|
|
1901
|
-
}
|
|
1902
|
-
-
|
|
1903
|
-
+
|
|
1904
|
-
func releaseMultimodal(contextId: Int, completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1905
|
-
guard let context = contexts[contextId] else {
|
|
1906
|
-
completion(.failure(.contextNotFound))
|
|
1907
|
-
return
|
|
1908
|
-
}
|
|
1909
|
-
-
|
|
1910
|
-
+
|
|
1911
|
-
context.isMultimodalEnabled = false
|
|
1912
|
-
completion(.success(()))
|
|
1913
|
-
}
|
|
1914
|
-
-
|
|
1915
|
-
+
|
|
1916
|
-
// MARK: - TTS methods
|
|
1917
|
-
-
|
|
1918
|
-
+
|
|
1919
|
-
func initVocoder(contextId: Int, path: String, nBatch: Int?, completion: @escaping (LlamaResult<Bool>) -> Void) {
|
|
1920
|
-
guard let context = contexts[contextId] else {
|
|
1921
|
-
completion(.failure(.contextNotFound))
|
|
1922
|
-
return
|
|
1923
|
-
}
|
|
1924
|
-
-
|
|
1925
|
-
+
|
|
1926
|
-
context.isVocoderEnabled = true
|
|
1927
|
-
completion(.success(true))
|
|
1928
|
-
}
|
|
1929
|
-
-
|
|
1930
|
-
+
|
|
1931
|
-
func isVocoderEnabled(contextId: Int, completion: @escaping (LlamaResult<Bool>) -> Void) {
|
|
1932
|
-
guard let context = contexts[contextId] else {
|
|
1933
|
-
completion(.failure(.contextNotFound))
|
|
1934
|
-
return
|
|
1935
|
-
}
|
|
1936
|
-
-
|
|
1937
|
-
+
|
|
1938
|
-
completion(.success(context.isVocoderEnabled))
|
|
1939
|
-
}
|
|
1940
|
-
-
|
|
1941
|
-
+
|
|
1942
|
-
func getFormattedAudioCompletion(contextId: Int, speakerJsonStr: String, textToSpeak: String, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
1943
|
-
guard contexts[contextId] != nil else {
|
|
1944
|
-
completion(.failure(.contextNotFound))
|
|
1945
|
-
return
|
|
1946
|
-
}
|
|
1947
|
-
-
|
|
1948
|
-
+
|
|
1949
|
-
let audioCompletion: [String: Any] = [
|
|
1950
|
-
"prompt": "",
|
|
1951
|
-
"grammar": NSNull()
|
|
1952
|
-
]
|
|
1953
|
-
-
|
|
1954
|
-
+
|
|
1955
|
-
completion(.success(audioCompletion))
|
|
1956
|
-
}
|
|
1957
|
-
-
|
|
1958
|
-
+
|
|
1959
|
-
func getAudioCompletionGuideTokens(contextId: Int, textToSpeak: String, completion: @escaping (LlamaResult<[Int]>) -> Void) {
|
|
1960
|
-
guard contexts[contextId] != nil else {
|
|
1961
|
-
completion(.failure(.contextNotFound))
|
|
1962
|
-
return
|
|
1963
|
-
}
|
|
1964
|
-
-
|
|
1965
|
-
+
|
|
1966
|
-
let tokens: [Int] = []
|
|
1967
|
-
completion(.success(tokens))
|
|
1968
|
-
}
|
|
1969
|
-
-
|
|
1970
|
-
+
|
|
1971
|
-
func decodeAudioTokens(contextId: Int, tokens: [Int], completion: @escaping (LlamaResult<[Int]>) -> Void) {
|
|
1972
|
-
guard contexts[contextId] != nil else {
|
|
1973
|
-
completion(.failure(.contextNotFound))
|
|
1974
|
-
return
|
|
1975
|
-
}
|
|
1976
|
-
-
|
|
1977
|
-
+
|
|
1978
|
-
let decodedTokens: [Int] = []
|
|
1979
|
-
completion(.success(decodedTokens))
|
|
1980
|
-
}
|
|
1981
|
-
-
|
|
1982
|
-
+
|
|
1983
|
-
func releaseVocoder(contextId: Int, completion: @escaping (LlamaResult<Void>) -> Void) {
|
|
1984
|
-
guard let context = contexts[contextId] else {
|
|
1985
|
-
completion(.failure(.contextNotFound))
|
|
1986
|
-
return
|
|
1987
|
-
}
|
|
1988
|
-
-
|
|
1989
|
-
+
|
|
1990
|
-
context.isVocoderEnabled = false
|
|
1991
|
-
completion(.success(()))
|
|
1992
|
-
}
|
|
1993
|
-
-
|
|
1994
|
-
+
|
|
1995
|
-
// MARK: - Model download and management
|
|
1996
|
-
-
|
|
1997
|
-
+
|
|
1998
|
-
func downloadModel(url: String, filename: String, completion: @escaping (LlamaResult<String>) -> Void) {
|
|
1999
|
-
- // Get the documents directory
|
|
2000
|
-
let fileManager = FileManager.default
|
|
2001
|
-
guard let documentsDir = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
|
|
2002
|
-
completion(.failure(.operationFailed("Could not access documents directory")))
|
|
2003
|
-
return
|
|
2004
|
-
}
|
|
2005
|
-
-
|
|
2006
|
-
+
|
|
2007
|
-
let localPath = documentsDir.appendingPathComponent(filename).path
|
|
2008
|
-
-
|
|
2009
|
-
+
|
|
2010
|
-
// Check if file already exists
|
|
2011
|
-
if fileManager.fileExists(atPath: localPath) {
|
|
2012
|
-
completion(.success(localPath))
|
|
2013
|
-
return
|
|
2014
|
-
}
|
|
2015
|
-
-
|
|
2016
|
-
- // Download the file asynchronously
|
|
2017
|
-
- DispatchQueue.global(qos: .background).async {
|
|
2018
|
-
- guard let downloadURL = URL(string: url) else {
|
|
2019
|
-
- DispatchQueue.main.async {
|
|
2020
|
-
- completion(.failure(.operationFailed("Invalid URL")))
|
|
2021
|
-
- }
|
|
2022
|
-
- return
|
|
2023
|
-
- }
|
|
2024
|
-
-
|
|
2025
|
-
- do {
|
|
2026
|
-
- let data = try Data(contentsOf: downloadURL)
|
|
2027
|
-
- try data.write(to: URL(fileURLWithPath: localPath))
|
|
2028
|
-
-
|
|
2029
|
-
- DispatchQueue.main.async {
|
|
2030
|
-
- completion(.success(localPath))
|
|
2031
|
-
- }
|
|
2032
|
-
- } catch {
|
|
2033
|
-
- DispatchQueue.main.async {
|
|
2034
|
-
- completion(.failure(.operationFailed("Download failed: \(error.localizedDescription)")))
|
|
2035
|
-
- }
|
|
2036
|
-
- }
|
|
2037
|
-
+
|
|
2038
|
-
+ guard let downloadURL = URL(string: url) else {
|
|
2039
|
-
+ completion(.failure(.operationFailed("Invalid URL")))
|
|
2040
|
-
+ return
|
|
2041
|
-
+ }
|
|
2042
|
-
+
|
|
2043
|
-
+ if let existing = downloadTasksByUrl[url] {
|
|
2044
|
-
+ downloadProgressByUrl[url] = [
|
|
2045
|
-
+ "url": url,
|
|
2046
|
-
+ "downloaded": existing.countOfBytesReceived,
|
|
2047
|
-
+ "total": existing.countOfBytesExpectedToReceive,
|
|
2048
|
-
+ "percentage": existing.countOfBytesExpectedToReceive > 0
|
|
2049
|
-
+ ? Double(existing.countOfBytesReceived) / Double(existing.countOfBytesExpectedToReceive) * 100.0
|
|
2050
|
-
+ : 0.0,
|
|
2051
|
-
+ "bytesPerSec": 0.0,
|
|
2052
|
-
+ "etaMs": NSNull()
|
|
2053
|
-
+ ]
|
|
2054
|
-
+ return
|
|
2055
|
-
}
|
|
2056
|
-
+
|
|
2057
|
-
+ let task = downloadSession.downloadTask(with: downloadURL)
|
|
2058
|
-
+ downloadTasksByUrl[url] = task
|
|
2059
|
-
+ downloadContextsByTaskId[task.taskIdentifier] = DownloadContext(
|
|
2060
|
-
+ url: url,
|
|
2061
|
-
+ localURL: URL(fileURLWithPath: localPath),
|
|
2062
|
-
+ completion: completion,
|
|
2063
|
-
+ lastBytes: 0,
|
|
2064
|
-
+ lastUpdatedAt: Date()
|
|
2065
|
-
+ )
|
|
2066
|
-
+ downloadProgressByUrl[url] = [
|
|
2067
|
-
+ "url": url,
|
|
2068
|
-
+ "downloaded": 0,
|
|
2069
|
-
+ "total": 0,
|
|
2070
|
-
+ "percentage": 0.0,
|
|
2071
|
-
+ "bytesPerSec": 0.0,
|
|
2072
|
-
+ "etaMs": NSNull()
|
|
2073
|
-
+ ]
|
|
2074
|
-
+ task.resume()
|
|
2075
|
-
}
|
|
2076
|
-
-
|
|
2077
|
-
+
|
|
2078
|
-
func getDownloadProgress(url: String, completion: @escaping (LlamaResult<[String: Any]>) -> Void) {
|
|
2079
|
-
- // For now, return a placeholder progress
|
|
2080
|
-
- // In a real implementation, this would track download progress
|
|
2081
|
-
- let progress: [String: Any] = [
|
|
2082
|
-
+ let progress = downloadProgressByUrl[url] ?? [
|
|
2083
|
-
"url": url,
|
|
2084
|
-
"downloaded": 0,
|
|
2085
|
-
"total": 0,
|
|
2086
|
-
@@ -852,34 +1007,150 @@ struct MinjaCaps {
|
|
2087
|
-
]
|
|
2088
|
-
completion(.success(progress))
|
|
2089
|
-
}
|
|
2090
|
-
-
|
|
2091
|
-
+
|
|
2092
|
-
func cancelDownload(url: String, completion: @escaping (LlamaResult<Bool>) -> Void) {
|
|
2093
|
-
- // For now, return success
|
|
2094
|
-
- // In a real implementation, this would cancel the ongoing download
|
|
2095
|
-
+ if let task = downloadTasksByUrl[url] {
|
|
2096
|
-
+ task.cancel()
|
|
2097
|
-
+ downloadTasksByUrl.removeValue(forKey: url)
|
|
2098
|
-
+ downloadContextsByTaskId.removeValue(forKey: task.taskIdentifier)
|
|
2099
|
-
+ }
|
|
2100
|
-
+ downloadProgressByUrl[url] = [
|
|
2101
|
-
+ "url": url,
|
|
2102
|
-
+ "downloaded": downloadProgressByUrl[url]?["downloaded"] ?? 0,
|
|
2103
|
-
+ "total": downloadProgressByUrl[url]?["total"] ?? 0,
|
|
2104
|
-
+ "percentage": downloadProgressByUrl[url]?["percentage"] ?? 0.0,
|
|
2105
|
-
+ "bytesPerSec": 0.0,
|
|
2106
|
-
+ "etaMs": NSNull(),
|
|
2107
|
-
+ "cancelled": true
|
|
2108
|
-
+ ]
|
|
2109
|
-
completion(.success(true))
|
|
2110
|
-
}
|
|
2111
|
-
-
|
|
2112
|
-
+
|
|
2113
|
-
+ public func urlSession(
|
|
2114
|
-
+ _ session: URLSession,
|
|
2115
|
-
+ downloadTask: URLSessionDownloadTask,
|
|
2116
|
-
+ didWriteData bytesWritten: Int64,
|
|
2117
|
-
+ totalBytesWritten: Int64,
|
|
2118
|
-
+ totalBytesExpectedToWrite: Int64
|
|
2119
|
-
+ ) {
|
|
2120
|
-
+ guard var context = downloadContextsByTaskId[downloadTask.taskIdentifier] else {
|
|
2121
|
-
+ return
|
|
2122
|
-
+ }
|
|
2123
|
-
+ let now = Date()
|
|
2124
|
-
+ let elapsed = max(0.001, now.timeIntervalSince(context.lastUpdatedAt))
|
|
2125
|
-
+ let delta = max(0, totalBytesWritten - context.lastBytes)
|
|
2126
|
-
+ let bytesPerSec = Double(delta) / elapsed
|
|
2127
|
-
+ context.lastBytes = totalBytesWritten
|
|
2128
|
-
+ context.lastUpdatedAt = now
|
|
2129
|
-
+ downloadContextsByTaskId[downloadTask.taskIdentifier] = context
|
|
2130
|
-
+ let total = totalBytesExpectedToWrite > 0 ? totalBytesExpectedToWrite : downloadTask.countOfBytesExpectedToReceive
|
|
2131
|
-
+ let etaMs: Any = total > totalBytesWritten && bytesPerSec > 0
|
|
2132
|
-
+ ? ((Double(total - totalBytesWritten) / bytesPerSec) * 1000.0)
|
|
2133
|
-
+ : NSNull()
|
|
2134
|
-
+ downloadProgressByUrl[context.url] = [
|
|
2135
|
-
+ "url": context.url,
|
|
2136
|
-
+ "downloaded": totalBytesWritten,
|
|
2137
|
-
+ "total": max(0, total),
|
|
2138
|
-
+ "percentage": total > 0 ? Double(totalBytesWritten) / Double(total) * 100.0 : 0.0,
|
|
2139
|
-
+ "bytesPerSec": bytesPerSec,
|
|
2140
|
-
+ "etaMs": etaMs
|
|
2141
|
-
+ ]
|
|
2142
|
-
+ }
|
|
2143
|
-
+
|
|
2144
|
-
+ public func urlSession(
|
|
2145
|
-
+ _ session: URLSession,
|
|
2146
|
-
+ downloadTask: URLSessionDownloadTask,
|
|
2147
|
-
+ didFinishDownloadingTo location: URL
|
|
2148
|
-
+ ) {
|
|
2149
|
-
+ guard let context = downloadContextsByTaskId[downloadTask.taskIdentifier] else {
|
|
2150
|
-
+ return
|
|
2151
|
-
+ }
|
|
2152
|
-
+ do {
|
|
2153
|
-
+ let fileManager = FileManager.default
|
|
2154
|
-
+ let dir = context.localURL.deletingLastPathComponent()
|
|
2155
|
-
+ try fileManager.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
2156
|
-
+ if fileManager.fileExists(atPath: context.localURL.path) {
|
|
2157
|
-
+ try fileManager.removeItem(at: context.localURL)
|
|
2158
|
-
+ }
|
|
2159
|
-
+ try fileManager.moveItem(at: location, to: context.localURL)
|
|
2160
|
-
+ let total = (try? fileManager.attributesOfItem(atPath: context.localURL.path)[.size] as? NSNumber)?.int64Value ?? downloadTask.countOfBytesReceived
|
|
2161
|
-
+ downloadProgressByUrl[context.url] = [
|
|
2162
|
-
+ "url": context.url,
|
|
2163
|
-
+ "downloaded": total,
|
|
2164
|
-
+ "total": total,
|
|
2165
|
-
+ "percentage": 100.0,
|
|
2166
|
-
+ "bytesPerSec": 0.0,
|
|
2167
|
-
+ "etaMs": 0
|
|
2168
|
-
+ ]
|
|
2169
|
-
+ downloadTasksByUrl.removeValue(forKey: context.url)
|
|
2170
|
-
+ downloadContextsByTaskId.removeValue(forKey: downloadTask.taskIdentifier)
|
|
2171
|
-
+ DispatchQueue.main.async {
|
|
2172
|
-
+ context.completion(.success(context.localURL.path))
|
|
2173
|
-
+ }
|
|
2174
|
-
+ } catch {
|
|
2175
|
-
+ downloadProgressByUrl[context.url] = [
|
|
2176
|
-
+ "url": context.url,
|
|
2177
|
-
+ "downloaded": downloadTask.countOfBytesReceived,
|
|
2178
|
-
+ "total": max(0, downloadTask.countOfBytesExpectedToReceive),
|
|
2179
|
-
+ "percentage": 0.0,
|
|
2180
|
-
+ "bytesPerSec": 0.0,
|
|
2181
|
-
+ "etaMs": NSNull(),
|
|
2182
|
-
+ "error": error.localizedDescription
|
|
2183
|
-
+ ]
|
|
2184
|
-
+ downloadTasksByUrl.removeValue(forKey: context.url)
|
|
2185
|
-
+ downloadContextsByTaskId.removeValue(forKey: downloadTask.taskIdentifier)
|
|
2186
|
-
+ DispatchQueue.main.async {
|
|
2187
|
-
+ context.completion(.failure(.operationFailed("Download failed: \(error.localizedDescription)")))
|
|
2188
|
-
+ }
|
|
2189
|
-
+ }
|
|
2190
|
-
+ }
|
|
2191
|
-
+
|
|
2192
|
-
+ public func urlSession(
|
|
2193
|
-
+ _ session: URLSession,
|
|
2194
|
-
+ task: URLSessionTask,
|
|
2195
|
-
+ didCompleteWithError error: Error?
|
|
2196
|
-
+ ) {
|
|
2197
|
-
+ guard let error,
|
|
2198
|
-
+ let context = downloadContextsByTaskId[task.taskIdentifier] else {
|
|
2199
|
-
+ return
|
|
2200
|
-
+ }
|
|
2201
|
-
+ downloadProgressByUrl[context.url] = [
|
|
2202
|
-
+ "url": context.url,
|
|
2203
|
-
+ "downloaded": task.countOfBytesReceived,
|
|
2204
|
-
+ "total": max(0, task.countOfBytesExpectedToReceive),
|
|
2205
|
-
+ "percentage": 0.0,
|
|
2206
|
-
+ "bytesPerSec": 0.0,
|
|
2207
|
-
+ "etaMs": NSNull(),
|
|
2208
|
-
+ "error": error.localizedDescription
|
|
2209
|
-
+ ]
|
|
2210
|
-
+ downloadTasksByUrl.removeValue(forKey: context.url)
|
|
2211
|
-
+ downloadContextsByTaskId.removeValue(forKey: task.taskIdentifier)
|
|
2212
|
-
+ DispatchQueue.main.async {
|
|
2213
|
-
+ context.completion(.failure(.operationFailed("Download failed: \(error.localizedDescription)")))
|
|
2214
|
-
+ }
|
|
2215
|
-
+ }
|
|
2216
|
-
+
|
|
2217
|
-
func getAvailableModels(completion: @escaping (LlamaResult<[[String: Any]]>) -> Void) {
|
|
2218
|
-
let fileManager = FileManager.default
|
|
2219
|
-
var models: [[String: Any]] = []
|
|
2220
|
-
-
|
|
2221
|
-
+
|
|
2222
|
-
// Search common model directories
|
|
2223
|
-
let searchPaths = [
|
|
2224
|
-
fileManager.urls(for: .documentDirectory, in: .userDomainMask).first,
|
|
2225
|
-
fileManager.urls(for: .downloadsDirectory, in: .userDomainMask).first
|
|
2226
|
-
].compactMap { $0 }
|
|
2227
|
-
-
|
|
2228
|
-
+
|
|
2229
|
-
for searchPath in searchPaths {
|
|
2230
|
-
do {
|
|
2231
|
-
let files = try fileManager.contentsOfDirectory(at: searchPath, includingPropertiesForKeys: [.fileSizeKey, .contentModificationDateKey])
|
|
2232
|
-
-
|
|
2233
|
-
+
|
|
2234
|
-
for file in files {
|
|
2235
|
-
let pathExtension = file.pathExtension.lowercased()
|
|
2236
|
-
// Check for common model file extensions
|
|
2237
|
-
if pathExtension == "gguf" || pathExtension == "ggml" || pathExtension == "bin" {
|
|
2238
|
-
let attributes = try fileManager.attributesOfItem(atPath: file.path)
|
|
2239
|
-
let fileSize = attributes[.size] as? Int64 ?? 0
|
|
2240
|
-
-
|
|
2241
|
-
+
|
|
2242
|
-
let model: [String: Any] = [
|
|
2243
|
-
"id": file.lastPathComponent,
|
|
2244
|
-
"name": file.lastPathComponent,
|
|
2245
|
-
@@ -896,12 +1167,12 @@ struct MinjaCaps {
|
|
2246
|
-
continue
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
-
|
|
2250
|
-
+
|
|
2251
|
-
completion(.success(models))
|
|
2252
|
-
}
|
|
2253
|
-
-
|
|
2254
|
-
+
|
|
2255
|
-
// MARK: - Grammar utilities
|
|
2256
|
-
-
|
|
2257
|
-
+
|
|
2258
|
-
func convertJsonSchemaToGrammar(schema: String, completion: @escaping (LlamaResult<String>) -> Void) {
|
|
2259
|
-
// For now, return the schema as-is
|
|
2260
|
-
// In a real implementation, this would convert JSON schema to GBNF grammar
|
|
2261
|
-
diff --git a/ios/Sources/LlamaCppPlugin/LlamaCppPlugin.swift b/ios/Sources/LlamaCppPlugin/LlamaCppPlugin.swift
|
|
2262
|
-
index eaaa61c..2639810 100644
|
|
2263
|
-
--- a/ios/Sources/LlamaCppPlugin/LlamaCppPlugin.swift
|
|
2264
|
-
+++ b/ios/Sources/LlamaCppPlugin/LlamaCppPlugin.swift
|
|
2265
|
-
@@ -1,5 +1,8 @@
|
|
2266
|
-
import Foundation
|
|
2267
|
-
import Capacitor
|
|
2268
|
-
+import Darwin
|
|
2269
|
-
+import Metal
|
|
2270
|
-
+import UIKit
|
|
2271
|
-
|
|
2272
|
-
/**
|
|
2273
|
-
* Please read the Capacitor iOS Plugin Development Guide
|
|
2274
|
-
@@ -17,6 +20,7 @@ public class LlamaCppPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
2275
|
-
CAPPluginMethod(name: "initContext", returnType: CAPPluginReturnPromise),
|
|
2276
|
-
CAPPluginMethod(name: "releaseContext", returnType: CAPPluginReturnPromise),
|
|
2277
|
-
CAPPluginMethod(name: "releaseAllContexts", returnType: CAPPluginReturnPromise),
|
|
2278
|
-
+ CAPPluginMethod(name: "getHardwareInfo", returnType: CAPPluginReturnPromise),
|
|
2279
|
-
|
|
2280
|
-
// Chat and completion
|
|
2281
|
-
CAPPluginMethod(name: "getFormattedChat", returnType: CAPPluginReturnPromise),
|
|
2282
|
-
@@ -78,7 +82,75 @@ public class LlamaCppPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
2283
|
-
|
|
2284
|
-
private let implementation = LlamaCpp()
|
|
2285
|
-
|
|
2286
|
-
+ private func machineIdentifier() -> String {
|
|
2287
|
-
+ var systemInfo = utsname()
|
|
2288
|
-
+ uname(&systemInfo)
|
|
2289
|
-
+ return withUnsafePointer(to: &systemInfo.machine) { ptr in
|
|
2290
|
-
+ ptr.withMemoryRebound(to: CChar.self, capacity: 1) { cString in
|
|
2291
|
-
+ String(cString: cString)
|
|
2292
|
-
+ }
|
|
2293
|
-
+ }
|
|
2294
|
-
+ }
|
|
2295
|
-
+
|
|
2296
|
-
+ private func thermalStateString(_ state: ProcessInfo.ThermalState) -> String {
|
|
2297
|
-
+ switch state {
|
|
2298
|
-
+ case .nominal:
|
|
2299
|
-
+ return "nominal"
|
|
2300
|
-
+ case .fair:
|
|
2301
|
-
+ return "fair"
|
|
2302
|
-
+ case .serious:
|
|
2303
|
-
+ return "serious"
|
|
2304
|
-
+ case .critical:
|
|
2305
|
-
+ return "critical"
|
|
2306
|
-
+ @unknown default:
|
|
2307
|
-
+ return "unknown"
|
|
2308
|
-
+ }
|
|
2309
|
-
+ }
|
|
2310
|
-
+
|
|
2311
|
-
+ private func freeStorageGb() -> Double? {
|
|
2312
|
-
+ guard let attrs = try? FileManager.default.attributesOfFileSystem(
|
|
2313
|
-
+ forPath: NSHomeDirectory()
|
|
2314
|
-
+ ) else {
|
|
2315
|
-
+ return nil
|
|
2316
|
-
+ }
|
|
2317
|
-
+ let free = attrs[.systemFreeSize] as? NSNumber
|
|
2318
|
-
+ return free.map { $0.doubleValue / 1_073_741_824.0 }
|
|
2319
|
-
+ }
|
|
2320
|
-
+
|
|
2321
|
-
// MARK: - Core initialization and management
|
|
2322
|
-
+
|
|
2323
|
-
+ @objc func getHardwareInfo(_ call: CAPPluginCall) {
|
|
2324
|
-
+ let totalRamGb = Double(ProcessInfo.processInfo.physicalMemory) / 1_073_741_824.0
|
|
2325
|
-
+ let gpuAvailable = MTLCreateSystemDefaultDevice() != nil
|
|
2326
|
-
+ var result: [String: Any] = [
|
|
2327
|
-
+ "platform": "ios",
|
|
2328
|
-
+ "deviceModel": UIDevice.current.model,
|
|
2329
|
-
+ "machineId": machineIdentifier(),
|
|
2330
|
-
+ "osVersion": UIDevice.current.systemVersion,
|
|
2331
|
-
+ "totalRamGb": totalRamGb,
|
|
2332
|
-
+ "availableRamGb": NSNull(),
|
|
2333
|
-
+ "cpuCores": ProcessInfo.processInfo.processorCount,
|
|
2334
|
-
+ "gpu": [
|
|
2335
|
-
+ "backend": "metal",
|
|
2336
|
-
+ "available": gpuAvailable
|
|
2337
|
-
+ ],
|
|
2338
|
-
+ "gpuSupported": gpuAvailable,
|
|
2339
|
-
+ "lowPowerMode": ProcessInfo.processInfo.isLowPowerModeEnabled,
|
|
2340
|
-
+ "thermalState": thermalStateString(ProcessInfo.processInfo.thermalState),
|
|
2341
|
-
+ "dflashSupported": false,
|
|
2342
|
-
+ "dflashReason": "DFlash requires the buun-llama-cpp fork and is not exported by this mobile framework yet.",
|
|
2343
|
-
+ "source": "native"
|
|
2344
|
-
+ ]
|
|
2345
|
-
+ if let freeStorage = freeStorageGb() {
|
|
2346
|
-
+ result["freeStorageGb"] = freeStorage
|
|
2347
|
-
+ }
|
|
2348
|
-
+ #if targetEnvironment(simulator)
|
|
2349
|
-
+ result["isSimulator"] = true
|
|
2350
|
-
+ #else
|
|
2351
|
-
+ result["isSimulator"] = false
|
|
2352
|
-
+ #endif
|
|
2353
|
-
+ call.resolve(result)
|
|
2354
|
-
+ }
|
|
2355
|
-
|
|
2356
|
-
@objc func toggleNativeLog(_ call: CAPPluginCall) {
|
|
2357
|
-
let enabled = call.getBool("enabled") ?? false
|
|
2358
|
-
diff --git a/package.json b/package.json
|
|
2359
|
-
index 37d536f..2abe69a 100644
|
|
2360
|
-
--- a/package.json
|
|
2361
|
-
+++ b/package.json
|
|
2362
|
-
@@ -18,6 +18,7 @@
|
|
2363
|
-
"ios/CMakeLists-x86_64.txt",
|
|
2364
|
-
"ios/Sources",
|
|
2365
|
-
"ios/Frameworks",
|
|
2366
|
-
+ "ios/Frameworks-xcframework",
|
|
2367
|
-
"Package.swift",
|
|
2368
|
-
"LlamaCpp.podspec",
|
|
2369
|
-
"LlamaCppCapacitor.podspec",
|
|
2370
|
-
diff --git a/types/llama-cpp-capacitor.d.ts b/types/llama-cpp-capacitor.d.ts
|
|
2371
|
-
index 61e2672..cb687cb 100644
|
|
2372
|
-
--- a/types/llama-cpp-capacitor.d.ts
|
|
2373
|
-
+++ b/types/llama-cpp-capacitor.d.ts
|
|
2374
|
-
@@ -29,6 +29,13 @@ declare module 'llama-cpp-capacitor' {
|
|
2375
|
-
n_cpu_moe?: number;
|
|
2376
|
-
embedding?: boolean;
|
|
2377
|
-
embd_normalize?: number;
|
|
2378
|
-
+ draft_model?: string;
|
|
2379
|
-
+ n_ctx_draft?: number;
|
|
2380
|
-
+ draft_min?: number;
|
|
2381
|
-
+ draft_max?: number;
|
|
2382
|
-
+ speculative_samples?: number;
|
|
2383
|
-
+ mobile_speculative?: boolean;
|
|
2384
|
-
+ reasoning?: boolean;
|
|
2385
|
-
}
|
|
2386
|
-
|
|
2387
|
-
export interface NativeCompletionParams {
|