nova-personal-agent-server 0.4.0 → 1.0.2
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/LICENSE +674 -201
- package/README.md +12 -2
- package/bin/nova-space-host.mjs +4 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/cli.js +71 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/client.js +340 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/crypto.js +167 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/live.js +169 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/mailbox.js +217 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/media.js +320 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/pairing.js +13 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/protocol.js +50 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/security.js +305 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/server.js +477 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/source-address.js +58 -0
- package/node_modules/@nova-personal-agent/relay/package.json +1 -0
- package/package.json +13 -6
- package/runtime/dist/src/cascaded-text-provider.js +8 -3
- package/runtime/dist/src/composition/assembly.js +133 -35
- package/runtime/dist/src/composition/cascaded-realtime-assembly.js +114 -59
- package/runtime/dist/src/composition/production-composition.js +57 -21
- package/runtime/dist/src/composition/realtime-assembly.js +160 -52
- package/runtime/dist/src/composition/soul-context.js +22 -0
- package/runtime/dist/src/config/capability-registry.js +48 -3
- package/runtime/dist/src/config/cascaded-realtime-config.js +23 -10
- package/runtime/dist/src/config/config.js +541 -128
- package/runtime/dist/src/config/credential-rotation.js +26 -0
- package/runtime/dist/src/config/data-root.js +764 -0
- package/runtime/dist/src/config/diagnostics.js +3 -1
- package/runtime/dist/src/config/environment-contract.js +190 -188
- package/runtime/dist/src/config/model-routes.js +140 -0
- package/runtime/dist/src/config/voice-credentials.js +55 -0
- package/runtime/dist/src/connectors/composio/index.js +9 -0
- package/runtime/dist/src/connectors/feishu/index.js +258 -44
- package/runtime/dist/src/connectors/macos/mail.js +7 -3
- package/runtime/dist/src/connectors/macos/reader.js +3 -1
- package/runtime/dist/src/conversation-voice-provider.js +5 -2
- package/runtime/dist/src/core/causal-runtime.js +38 -3
- package/runtime/dist/src/core/context-view.js +7 -0
- package/runtime/dist/src/core/guards.js +32 -0
- package/runtime/dist/src/core/runtime.js +3 -0
- package/runtime/dist/src/core/schedule-tools.js +2 -2
- package/runtime/dist/src/core/source-processing-instructions.js +2 -2
- package/runtime/dist/src/core/source-processing-tools.js +3 -1
- package/runtime/dist/src/core/tool-schema.js +42 -7
- package/runtime/dist/src/desktop/desktop-camera.js +3 -5
- package/runtime/dist/src/desktop/desktop-control.js +41 -8
- package/runtime/dist/src/desktop/desktop-session.js +90 -19
- package/runtime/dist/src/desktop/desktop-wire.js +5 -7
- package/runtime/dist/src/desktop/startup-error.js +18 -16
- package/runtime/dist/src/desktop/workbench-acceptance.js +52 -14
- package/runtime/dist/src/desktop-entry.js +6 -2
- package/runtime/dist/src/desktop.js +5 -1
- package/runtime/dist/src/device/attempt.js +65 -0
- package/runtime/dist/src/device/authority.js +159 -0
- package/runtime/dist/src/device/gateway.js +87 -0
- package/runtime/dist/src/device/ledger.js +91 -0
- package/runtime/dist/src/device/ownership.js +92 -0
- package/runtime/dist/src/device/port.js +2 -0
- package/runtime/dist/src/device/schedule-ownership.js +103 -0
- package/runtime/dist/src/executors/acp/transport.js +2 -0
- package/runtime/dist/src/executors/browser.js +4 -3
- package/runtime/dist/src/executors/codex/adapter-project.js +58 -12
- package/runtime/dist/src/executors/codex/app-server-schema.js +12 -21
- package/runtime/dist/src/executors/codex/app-server-transport.js +32 -18
- package/runtime/dist/src/executors/codex/common.js +1 -1
- package/runtime/dist/src/executors/codex/contract.js +12 -16
- package/runtime/dist/src/executors/codex/credential-snapshot.js +1 -9
- package/runtime/dist/src/executors/codex/factory.js +54 -32
- package/runtime/dist/src/executors/codex/host-config.js +69 -20
- package/runtime/dist/src/executors/codex/launch-profile.js +3 -2
- package/runtime/dist/src/executors/codex/local-provider-credential.js +39 -0
- package/runtime/dist/src/executors/codex/process-owner.js +4 -6
- package/runtime/dist/src/executors/codex/production-host.js +33 -34
- package/runtime/dist/src/executors/codex/protocol.js +9 -14
- package/runtime/dist/src/executors/codex/session-title.js +6 -8
- package/runtime/dist/src/executors/codex/spawn-env.js +27 -6
- package/runtime/dist/src/executors/codex/turn-projection.js +12 -17
- package/runtime/dist/src/executors/codex/windows-guardian.js +4 -6
- package/runtime/dist/src/executors/coding/intake.js +12 -7
- package/runtime/dist/src/executors/computer-backend.js +18 -10
- package/runtime/dist/src/executors/computer-config.js +32 -0
- package/runtime/dist/src/executors/computer-device.js +68 -16
- package/runtime/dist/src/executors/computer-worker.js +18 -6
- package/runtime/dist/src/executors/computer.js +29 -56
- package/runtime/dist/src/executors/device-lock.js +14 -5
- package/runtime/dist/src/executors/gui-execution.js +2 -0
- package/runtime/dist/src/executors/index.js +0 -1
- package/runtime/dist/src/executors/mobile.js +9 -8
- package/runtime/dist/src/executors/native-process.js +4 -0
- package/runtime/dist/src/executors/search.js +3 -5
- package/runtime/dist/src/executors/task-resources.js +21 -0
- package/runtime/dist/src/executors/watcher.js +2 -4
- package/runtime/dist/src/experience/host.js +179 -0
- package/runtime/dist/src/index.js +2 -0
- package/runtime/dist/src/knowledge/assembly.js +3 -4
- package/runtime/dist/src/knowledge/embeddings.js +50 -34
- package/runtime/dist/src/knowledge/service.js +1 -0
- package/runtime/dist/src/knowledge/store-client.js +1 -6
- package/runtime/dist/src/knowledge/store-worker.js +1 -3
- package/runtime/dist/src/mem0/resource.js +25 -0
- package/runtime/dist/src/mem0/store-worker.js +234 -21
- package/runtime/dist/src/memory/consumer.js +31 -0
- package/runtime/dist/src/memory/engine-worker.js +210 -0
- package/runtime/dist/src/memory/entry.js +8 -1
- package/runtime/dist/src/memory/explicit-memory.js +20 -0
- package/runtime/dist/src/memory/factory.js +30 -15
- package/runtime/dist/src/memory/grounded-voicemem.js +10 -0
- package/runtime/dist/src/memory/ledger-recall-engine.js +86 -0
- package/runtime/dist/src/memory/prerecall-port.js +27 -0
- package/runtime/dist/src/memory/prerecall.js +1 -1
- package/runtime/dist/src/memory/production-engine.js +151 -0
- package/runtime/dist/src/memory/provenance.js +1 -0
- package/runtime/dist/src/memory/remote-personal-memory.js +3 -1
- package/runtime/dist/src/memory/retrieval.js +107 -22
- package/runtime/dist/src/memory/sensitivity.js +6 -2
- package/runtime/dist/src/memory/source-retrieval.js +11 -0
- package/runtime/dist/src/memory/tool-capabilities.js +46 -0
- package/runtime/dist/src/memory/voicemem-sdk/LICENSE +202 -0
- package/runtime/dist/src/memory/voicemem-sdk/NOTICE.md +97 -0
- package/runtime/dist/src/memory/voicemem-sdk/PATCH-NOTICE.md +23 -0
- package/runtime/dist/src/memory/voicemem-sdk/archive.js +12 -0
- package/runtime/dist/src/memory/voicemem-sdk/audio.js +111 -0
- package/runtime/dist/src/memory/voicemem-sdk/barge-in.js +59 -0
- package/runtime/dist/src/memory/voicemem-sdk/checkpoint.js +56 -0
- package/runtime/dist/src/memory/voicemem-sdk/cleanup.js +139 -0
- package/runtime/dist/src/memory/voicemem-sdk/dashscope-asr.js +254 -0
- package/runtime/dist/src/memory/voicemem-sdk/dashscope-tts.js +247 -0
- package/runtime/dist/src/memory/voicemem-sdk/evaluation.js +330 -0
- package/runtime/dist/src/memory/voicemem-sdk/extraction.js +220 -0
- package/runtime/dist/src/memory/voicemem-sdk/finetune-data.js +115 -0
- package/runtime/dist/src/memory/voicemem-sdk/finetune.js +170 -0
- package/runtime/dist/src/memory/voicemem-sdk/grounded-reply-preferences.js +81 -0
- package/runtime/dist/src/memory/voicemem-sdk/index.js +22 -0
- package/runtime/dist/src/memory/voicemem-sdk/local-embedding.js +164 -0
- package/runtime/dist/src/memory/voicemem-sdk/local-runtime.js +53 -0
- package/runtime/dist/src/memory/voicemem-sdk/local-speaker.js +240 -0
- package/runtime/dist/src/memory/voicemem-sdk/memory.js +767 -0
- package/runtime/dist/src/memory/voicemem-sdk/model-json.js +14 -0
- package/runtime/dist/src/memory/voicemem-sdk/personamem.js +209 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/addenda.js +215 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/additive-extraction.js +478 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/index.js +32 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/update-memory.js +152 -0
- package/runtime/dist/src/memory/voicemem-sdk/providers.js +325 -0
- package/runtime/dist/src/memory/voicemem-sdk/ranking.js +65 -0
- package/runtime/dist/src/memory/voicemem-sdk/reaction.js +33 -0
- package/runtime/dist/src/memory/voicemem-sdk/realtime.js +215 -0
- package/runtime/dist/src/memory/voicemem-sdk/reply.js +68 -0
- package/runtime/dist/src/memory/voicemem-sdk/routing.js +209 -0
- package/runtime/dist/src/memory/voicemem-sdk/slots.js +61 -0
- package/runtime/dist/src/memory/voicemem-sdk/speaker-bindings.js +120 -0
- package/runtime/dist/src/memory/voicemem-sdk/speaker-profiles.js +327 -0
- package/runtime/dist/src/memory/voicemem-sdk/store.js +577 -0
- package/runtime/dist/src/memory/voicemem-sdk/stream.js +317 -0
- package/runtime/dist/src/memory/voicemem-sdk/subgraph.js +113 -0
- package/runtime/dist/src/memory/voicemem-sdk/summaries.js +56 -0
- package/runtime/dist/src/memory/voicemem-sdk/time.js +157 -0
- package/runtime/dist/src/memory/voicemem-sdk/types.js +2 -0
- package/runtime/dist/src/memory-ledger/store-client.js +235 -37
- package/runtime/dist/src/memory-ledger/store-worker.js +8 -5
- package/runtime/dist/src/memory-ledger/store.js +91 -1
- package/runtime/dist/src/memory-substrate/consolidation.js +23 -7
- package/runtime/dist/src/memory-substrate/diary.js +27 -0
- package/runtime/dist/src/memory-substrate/engine-outbox.js +107 -0
- package/runtime/dist/src/memory-substrate/explicit-memory.js +112 -0
- package/runtime/dist/src/memory-substrate/fact-fidelity.js +68 -0
- package/runtime/dist/src/memory-substrate/feishu-consent.js +41 -0
- package/runtime/dist/src/memory-substrate/file-authority.js +29 -6
- package/runtime/dist/src/memory-substrate/life-operations.js +35 -9
- package/runtime/dist/src/memory-substrate/markdown-repository.js +271 -65
- package/runtime/dist/src/memory-substrate/memory-documents.js +96 -0
- package/runtime/dist/src/memory-substrate/migration.js +2 -0
- package/runtime/dist/src/memory-substrate/purge.js +12 -2
- package/runtime/dist/src/memory-substrate/resource.js +514 -129
- package/runtime/dist/src/memory-substrate/retrieval.js +8 -5
- package/runtime/dist/src/memory-substrate/source-operations.js +9 -1
- package/runtime/dist/src/memory-substrate/source-processing.js +436 -40
- package/runtime/dist/src/memory-substrate/source-retrieval.js +28 -0
- package/runtime/dist/src/memory-substrate/source-state.js +8 -0
- package/runtime/dist/src/memory-substrate/space-source-input.js +90 -0
- package/runtime/dist/src/memory-substrate/store.js +125 -23
- package/runtime/dist/src/model/goal-checkin-writer.js +72 -0
- package/runtime/dist/src/model/goal-writer.js +80 -0
- package/runtime/dist/src/model/jev-client.js +24 -13
- package/runtime/dist/src/model/model-adapters.js +2 -3
- package/runtime/dist/src/model/model-catalog.js +80 -0
- package/runtime/dist/src/model/model-gateway.js +47 -18
- package/runtime/dist/src/model/model-purpose.js +3 -4
- package/runtime/dist/src/model/personal-writer.js +536 -44
- package/runtime/dist/src/model/proactivity.js +50 -6
- package/runtime/dist/src/model/responses-model-gateway.js +59 -0
- package/runtime/dist/src/model/task-verifier.js +3 -3
- package/runtime/dist/src/model/timeline-anchors.js +77 -0
- package/runtime/dist/src/model/timeline-perspective.js +13 -0
- package/runtime/dist/src/model/timeline-selection.js +182 -0
- package/runtime/dist/src/model/understanding-writer.js +27 -0
- package/runtime/dist/src/model/vision-capability.js +3 -1
- package/runtime/dist/src/model/workbench-writer.js +96 -0
- package/runtime/dist/src/news/feeds.js +6 -10
- package/runtime/dist/src/news/interests.js +23 -0
- package/runtime/dist/src/news/service.js +87 -31
- package/runtime/dist/src/news/sources.json +116 -0
- package/runtime/dist/src/notifications/adapters/space-relay.js +4 -0
- package/runtime/dist/src/notifications/content.js +41 -0
- package/runtime/dist/src/notifications/contracts.js +4 -2
- package/runtime/dist/src/notifications/feed.js +6 -2
- package/runtime/dist/src/notifications/service.js +27 -14
- package/runtime/dist/src/notifications/store.js +3 -1
- package/runtime/dist/src/personal-agent/app-context.js +39 -4
- package/runtime/dist/src/personal-agent/chat-failure.js +37 -0
- package/runtime/dist/src/personal-agent/computer-use/contract.js +42 -0
- package/runtime/dist/src/personal-agent/computer-use/session.js +280 -0
- package/runtime/dist/src/personal-agent/computer-use/skill.js +18 -0
- package/runtime/dist/src/personal-agent/computer-use/tools.js +15 -0
- package/runtime/dist/src/personal-agent/context-candidates.js +9 -13
- package/runtime/dist/src/personal-agent/context-dependencies.js +28 -0
- package/runtime/dist/src/personal-agent/contracts.js +24 -4
- package/runtime/dist/src/personal-agent/conversation-runtime.js +440 -42
- package/runtime/dist/src/personal-agent/conversation-tool-bridge.js +97 -0
- package/runtime/dist/src/personal-agent/conversation-tool-policy.js +22 -0
- package/runtime/dist/src/personal-agent/conversations.js +71 -15
- package/runtime/dist/src/personal-agent/daily-brief.js +5 -0
- package/runtime/dist/src/personal-agent/daily-workbench.js +558 -0
- package/runtime/dist/src/personal-agent/discovery-window.js +36 -0
- package/runtime/dist/src/personal-agent/goal-checkin.js +53 -0
- package/runtime/dist/src/personal-agent/host.js +2379 -223
- package/runtime/dist/src/personal-agent/identity-context.js +33 -0
- package/runtime/dist/src/personal-agent/life.js +129 -11
- package/runtime/dist/src/personal-agent/local-shell.js +181 -0
- package/runtime/dist/src/personal-agent/local-tools.js +234 -0
- package/runtime/dist/src/personal-agent/preferred-name-sync.js +35 -0
- package/runtime/dist/src/personal-agent/profile-warmup.js +100 -39
- package/runtime/dist/src/personal-agent/project-digests.js +7 -3
- package/runtime/dist/src/personal-agent/project-history.js +36 -0
- package/runtime/dist/src/personal-agent/reading-copies.js +183 -0
- package/runtime/dist/src/personal-agent/scheduled-tasks.js +50 -13
- package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +26 -10
- package/runtime/dist/src/personal-agent/source-processing-agent.js +239 -17
- package/runtime/dist/src/personal-agent/sources.js +9 -1
- package/runtime/dist/src/personal-agent/store.js +124 -14
- package/runtime/dist/src/personal-agent/task-loop.js +3 -0
- package/runtime/dist/src/personal-agent/tasks.js +16 -4
- package/runtime/dist/src/personal-agent/timeline-brief.js +462 -0
- package/runtime/dist/src/personal-agent/timeline-cache.js +191 -0
- package/runtime/dist/src/personal-agent/timeline-cluster.js +30 -0
- package/runtime/dist/src/personal-agent/timeline-inputs.js +47 -0
- package/runtime/dist/src/personal-agent/timeline-time.js +60 -0
- package/runtime/dist/src/personal-agent/understanding-products.js +49 -0
- package/runtime/dist/src/personal-agent/understanding.js +7 -22
- package/runtime/dist/src/personal-agent/workbench-context.js +17 -21
- package/runtime/dist/src/personal-agent/workbench-copy.js +124 -0
- package/runtime/dist/src/personal-agent/workbench-evidence.js +77 -0
- package/runtime/dist/src/personal-agent/workbench-instructions.js +21 -0
- package/runtime/dist/src/personal-agent/workbench-runtime.js +1006 -0
- package/runtime/dist/src/personal-agent/workbench-shell-class.js +304 -0
- package/runtime/dist/src/personal-agent/workbench-store.js +292 -0
- package/runtime/dist/src/personal-agent/workbench-temporal.js +66 -0
- package/runtime/dist/src/projects/project-native-resource.js +10 -8
- package/runtime/dist/src/projects/project-store.js +36 -4
- package/runtime/dist/src/realtime/bridge.js +77 -8
- package/runtime/dist/src/realtime/capabilities.js +19 -0
- package/runtime/dist/src/realtime/cascaded/adapter.js +180 -40
- package/runtime/dist/src/realtime/cascaded/ark-llm.js +150 -24
- package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +243 -83
- package/runtime/dist/src/realtime/cascaded/llm-stream-limits.js +18 -0
- package/runtime/dist/src/realtime/cascaded/llm.js +96 -0
- package/runtime/dist/src/realtime/cascaded/openai-compatible-speech.js +251 -0
- package/runtime/dist/src/realtime/cascaded/provider.js +8 -0
- package/runtime/dist/src/realtime/evidence.js +1 -1
- package/runtime/dist/src/realtime/frontend-instructions.js +76 -55
- package/runtime/dist/src/realtime/gemini.js +14 -3
- package/runtime/dist/src/realtime/host-delivery.js +37 -4
- package/runtime/dist/src/realtime/protocol.js +18 -3
- package/runtime/dist/src/realtime/provider-projection.js +4 -1
- package/runtime/dist/src/realtime/provider-session.js +73 -16
- package/runtime/dist/src/realtime/qwen-transport.js +35 -4
- package/runtime/dist/src/realtime/qwen.js +144 -9
- package/runtime/dist/src/realtime/service-state.js +0 -1
- package/runtime/dist/src/realtime/service.js +93 -7
- package/runtime/dist/src/realtime/session.js +39 -32
- package/runtime/dist/src/realtime/sglang-native.js +214 -0
- package/runtime/dist/src/realtime/system-prompts.en.js +14 -2
- package/runtime/dist/src/realtime/telemetry.js +6 -3
- package/runtime/dist/src/realtime/tool-continuations.js +84 -7
- package/runtime/dist/src/realtime/transport.js +17 -0
- package/runtime/dist/src/realtime/usage.js +33 -17
- package/runtime/dist/src/realtime/volcengine/ark.js +40 -15
- package/runtime/dist/src/realtime/volcengine/asr.js +2 -1
- package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +1 -7
- package/runtime/dist/src/realtime/volcengine/tts.js +2 -1
- package/runtime/dist/src/server/aoq-chat-server.js +1 -1
- package/runtime/dist/src/server/client-server.js +21 -0
- package/runtime/dist/src/server-entry.js +3 -0
- package/runtime/dist/src/space-host/admin-socket.js +115 -0
- package/runtime/dist/src/space-host/audio-owner.js +44 -0
- package/runtime/dist/src/space-host/cli.js +195 -0
- package/runtime/dist/src/space-host/config.js +247 -0
- package/runtime/dist/src/space-host/context-input.js +12 -0
- package/runtime/dist/src/space-host/contracts.js +10 -0
- package/runtime/dist/src/space-host/host-admin.js +114 -0
- package/runtime/dist/src/space-host/key-delivery.js +28 -0
- package/runtime/dist/src/space-host/mobile-tools.js +9 -0
- package/runtime/dist/src/space-host/model-settings.js +213 -0
- package/runtime/dist/src/space-host/projection.js +37 -0
- package/runtime/dist/src/space-host/push.js +137 -0
- package/runtime/dist/src/space-host/relay-transport.js +55 -0
- package/runtime/dist/src/space-host/service.js +841 -0
- package/runtime/dist/src/space-host/voice-crypto.js +240 -0
- package/runtime/dist/src/space-host/voice.js +600 -0
- package/runtime/dist/src/space-host/windows-secret-key.js +82 -0
- package/runtime/dist/src/storage/private-database.js +7 -10
- package/runtime/dist/src/text/unicode-normalize.js +5 -1
- package/runtime/dist/src/understanding/candidates.js +8 -10
- package/runtime/dist/src/understanding/fixture.js +1 -1
- package/runtime/dist/src/understanding/pipeline.js +4 -4
- package/runtime/dist/src/usage/context.js +23 -0
- package/runtime/dist/src/usage/index.js +4 -0
- package/runtime/dist/src/usage/ledger-worker.js +90 -0
- package/runtime/dist/src/usage/ledger.js +74 -0
- package/runtime/dist/src/usage/model-call.js +63 -0
- package/runtime/dist/src/usage/pricing.js +68 -0
- package/runtime/dist/src/usage/summary.js +69 -0
- package/runtime/dist/src/voicemem/store-client.js +104 -21
- package/runtime/dist/src/voicemem/store-worker.js +5 -8
- package/runtime/dist/src/voicemem/versioned-memory.js +1 -1
- package/src/command.mjs +8 -1
- package/runtime/dist/src/executors/autoglm.js +0 -376
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { describeMissingBlockingEnvironment } from '../config/config.js';
|
|
6
|
+
import { BoundedJsonStore } from '../storage/bounded-json.js';
|
|
7
|
+
import { overlaySpaceModelRoutes } from './model-settings.js';
|
|
8
|
+
/** Phone-editable, non-secret Host settings. Each entry reuses the Host's own command handler and validation; build, plan, local-approval and notification-binding commands stay desktop-only. */
|
|
9
|
+
export const SPACE_SETTINGS_METHODS = ['identity.configure', 'soul.set', 'discovery.configure', 'news.configure', 'models.configure'];
|
|
10
|
+
export const settingsPatchSchema = z.object({ method: z.enum(SPACE_SETTINGS_METHODS), params: z.record(z.string(), z.unknown()) }).strict();
|
|
11
|
+
/** Model-provider API keys a phone may store. The list is explicit on purpose: a new secret variable is not phone-writable until it is reviewed and added here. App-connection, executor, search, token and file secrets stay Host-only. */
|
|
12
|
+
export const SPACE_SECRET_NAMES = Object.freeze(['ARK_API_KEY', 'CODEX_API_KEY', 'COMPATIBLE_ASR_API_KEY', 'COMPATIBLE_TTS_API_KEY', 'DASHSCOPE_API_KEY', 'DEEPSEEK_API_KEY', 'DOUBAO_BIGMODEL_API_KEY', 'EMBEDDING_API_KEY', 'GEMINI_API_KEY', 'OPENAI_API_KEY', 'OPENAI_COMPATIBLE_API_KEY', 'OPENROUTER_API_KEY', 'SELF_HOSTED_ASR_API_KEY', 'SELF_HOSTED_LLM_API_KEY', 'SELF_HOSTED_TTS_API_KEY', 'STEPFUN_API_KEY']);
|
|
13
|
+
const secretName = z.string().refine(name => SPACE_SECRET_NAMES.includes(name), 'secret_not_allowed');
|
|
14
|
+
export const secretPutSchema = z.object({ name: secretName, value: z.string().min(1).max(4096).refine(value => !/[\0\r\n]/u.test(value), 'invalid_secret') }).strict();
|
|
15
|
+
export const secretClearSchema = z.object({ name: secretName }).strict();
|
|
16
|
+
const feishuActions = { 'app.start': 'feishu.app.start', 'app.status': 'feishu.app.status', 'app.cancel': 'feishu.app.cancel', login: 'feishu.login', complete: 'feishu.complete', logout: 'feishu.disconnect', status: 'feishu.status' };
|
|
17
|
+
export const connectorFeishuSchema = z.object({ action: z.enum(Object.keys(feishuActions)) }).strict();
|
|
18
|
+
export const feishuMethod = (action) => feishuActions[action];
|
|
19
|
+
export const secretFingerprint = (value) => createHash('sha256').update(value).digest('hex').slice(0, 8);
|
|
20
|
+
const fileSchema = z.object({ v: z.literal(1), secrets: z.record(z.string(), z.string()) });
|
|
21
|
+
/** Credentials a Space owner sent from a phone. Operator environment always wins; changes apply on the next Host start. A damaged file is dropped rather than blocking startup, and the owner projection asks the phone to enter the keys again. */
|
|
22
|
+
export class HostSecretStore {
|
|
23
|
+
path;
|
|
24
|
+
#store;
|
|
25
|
+
#state = { v: 1, secrets: {} };
|
|
26
|
+
#tail = Promise.resolve();
|
|
27
|
+
#damaged = false;
|
|
28
|
+
constructor(path) {
|
|
29
|
+
this.path = path;
|
|
30
|
+
this.#store = new BoundedJsonStore(path, fileSchema, 1024 * 1024);
|
|
31
|
+
}
|
|
32
|
+
get damaged() { return this.#damaged; }
|
|
33
|
+
async open() { try {
|
|
34
|
+
this.#state = await this.#store.read(this.#state);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error.code === 'ENOENT')
|
|
38
|
+
return;
|
|
39
|
+
this.#damaged = true;
|
|
40
|
+
} }
|
|
41
|
+
#serial(work) { const run = this.#tail.then(work); this.#tail = run.catch(() => { }); return run; }
|
|
42
|
+
put(name, value) { return this.#serial(async () => { const next = { v: 1, secrets: { ...this.#state.secrets, [name]: value } }; await this.#store.write(next); this.#state = next; this.#damaged = false; }); }
|
|
43
|
+
clear(name) { return this.#serial(async () => { const { [name]: _removed, ...rest } = this.#state.secrets; const next = { v: 1, secrets: rest }; await this.#store.write(next); this.#state = next; this.#damaged = false; }); }
|
|
44
|
+
value(name) { return this.#state.secrets[name]; }
|
|
45
|
+
}
|
|
46
|
+
export const spaceSecretsPath = (configPath) => configPath + '.secrets.json';
|
|
47
|
+
/** Synchronous startup overlay: stored Space credentials fill only variables the operator left unset. A damaged file is ignored, keeps its bytes for the operator and never blocks the Host. */
|
|
48
|
+
export function overlaySpaceSecrets(environment, configPath, onDiagnostic) {
|
|
49
|
+
if (!configPath)
|
|
50
|
+
return environment;
|
|
51
|
+
let text;
|
|
52
|
+
try {
|
|
53
|
+
text = readFileSync(spaceSecretsPath(configPath), 'utf8');
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code === 'ENOENT')
|
|
57
|
+
return environment;
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
// BoundedJsonStore leaves an empty private file until the first write.
|
|
61
|
+
if (!text)
|
|
62
|
+
return environment;
|
|
63
|
+
let parsed;
|
|
64
|
+
try {
|
|
65
|
+
parsed = fileSchema.parse(JSON.parse(text));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
onDiagnostic?.('space_secrets_invalid_dropped');
|
|
69
|
+
return environment;
|
|
70
|
+
}
|
|
71
|
+
const next = { ...environment };
|
|
72
|
+
for (const [name, value] of Object.entries(parsed.secrets))
|
|
73
|
+
if (SPACE_SECRET_NAMES.includes(name) && !environment[name]?.trim())
|
|
74
|
+
next[name] = value;
|
|
75
|
+
return next;
|
|
76
|
+
}
|
|
77
|
+
/** Desktop preflight must see the same stored credentials as the runtime, without changing their source. */
|
|
78
|
+
export function describeHostBlockingEnvironment(environment, textConversations = false) {
|
|
79
|
+
const configPath = environment.NOVA_SPACE_HOST_CONFIG ? resolve(environment.NOVA_SPACE_HOST_CONFIG) : undefined;
|
|
80
|
+
return describeMissingBlockingEnvironment(overlaySpaceModelRoutes(overlaySpaceSecrets(environment, configPath), configPath), textConversations);
|
|
81
|
+
}
|
|
82
|
+
/** Never projects values. `damaged` tells the phone that a stored file was ignored, so it can prompt for the keys again. */
|
|
83
|
+
export function credentialsView(store, environment) {
|
|
84
|
+
return { damaged: store?.damaged === true, credentials: SPACE_SECRET_NAMES.map(name => { const operator = environment[name]?.trim() ? environment[name] : undefined, stored = store?.value(name), value = operator ?? stored; return { name, configured: value !== undefined, source: operator !== undefined ? 'environment' : stored !== undefined ? 'space' : null, ...(value !== undefined ? { fingerprint: secretFingerprint(value) } : {}) }; }) };
|
|
85
|
+
}
|
|
86
|
+
export function settingsView(host) {
|
|
87
|
+
const state = host.snapshot(), s = state.settings, soul = state.soul, news = state.news;
|
|
88
|
+
const pick = ['discovery_enabled', 'discovery_interval_minutes', 'timezone', 'briefing_outlook_enabled', 'briefing_review_enabled', 'briefing_outlook_time', 'briefing_review_time', 'briefing_weekdays', 'quiet_start', 'quiet_end', 'proactive_daily_cap', 'news_rank_fallback', 'diary_enabled'];
|
|
89
|
+
return { identity: host.identity(), soul: { available: soul.available, role: soul.role, version: soul.version }, discovery: Object.fromEntries(pick.filter(key => s[key] !== undefined).map(key => [key, s[key]])), news: { enabled: news.enabled, explore: news.explore, interests: news.interests.map(row => row.text), profile_version: news.profile_version } };
|
|
90
|
+
}
|
|
91
|
+
function safeUrl(value, setup) {
|
|
92
|
+
if (typeof value !== 'string' || value.length > 4096)
|
|
93
|
+
return undefined;
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(value);
|
|
96
|
+
if (url.protocol !== 'https:' || url.username || url.password)
|
|
97
|
+
return undefined;
|
|
98
|
+
if (setup)
|
|
99
|
+
return url.origin === 'https://open.feishu.cn' && url.pathname === '/page/cli' ? url.href : undefined;
|
|
100
|
+
return ['feishu.cn', 'larksuite.com'].some(domain => url.hostname === domain || url.hostname.endsWith('.' + domain)) ? url.href : undefined;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Connection state only: no tokens, account or tenant identifiers, chats, or app secrets. */
|
|
107
|
+
export function feishuView(raw) {
|
|
108
|
+
const view = (typeof raw === 'object' && raw !== null ? raw : {}), setup = (typeof view.app_setup === 'object' && view.app_setup !== null ? view.app_setup : undefined);
|
|
109
|
+
const login = safeUrl(view.verification_url, false), setupUrl = safeUrl(setup?.verification_url, true);
|
|
110
|
+
// beginLogin pauses the connector, and logout keeps the account id: only the connector's signed_in flag means signed in.
|
|
111
|
+
return { available: view.available === true, configured: view.configured === true, connected: !login && view.unverified !== true && view.signed_in === true && view.auth_issue === undefined, ...(login ? { login_pending: true } : {}), state: typeof view.state === 'string' ? view.state : 'unauthorized', ...(typeof view.auth_issue === 'string' ? { auth_issue: view.auth_issue } : {}), ...(view.unverified === true ? { unverified: true, ...(typeof view.error === 'string' ? { error: view.error.slice(0, 200) } : {}) } : {}),
|
|
112
|
+
...(setup && typeof setup.state === 'string' ? { app_setup: { state: setup.state, ...(setupUrl ? { verification_url: setupUrl } : {}), ...(typeof setup.error === 'string' ? { error: setup.error.slice(0, 200) } : {}) } } : {}), ...(login ? { verification_url: login } : {}) };
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=host-admin.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BoundedJsonStore } from '../storage/bounded-json.js';
|
|
3
|
+
const schema = z.record(z.string(), z.object({ envelope: z.record(z.string(), z.unknown()), sent: z.boolean() }));
|
|
4
|
+
/** Save randomized wrapping/signature before network send; retries never mint new deliveries. */
|
|
5
|
+
export class DurableKeyDelivery {
|
|
6
|
+
options;
|
|
7
|
+
#store;
|
|
8
|
+
#state = {};
|
|
9
|
+
#tail = Promise.resolve();
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.#store = new BoundedJsonStore(options.path, schema, 4 * 1024 * 1024);
|
|
13
|
+
}
|
|
14
|
+
async open() { try {
|
|
15
|
+
this.#state = await this.#store.read({});
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code !== 'ENOENT')
|
|
19
|
+
throw error;
|
|
20
|
+
} }
|
|
21
|
+
deliver(epoch, device) { const run = this.#tail.then(async () => { const key = JSON.stringify([epoch, device]); let entry = this.#state[key]; if (entry?.sent)
|
|
22
|
+
return; if (!entry) {
|
|
23
|
+
entry = { envelope: await this.options.create(epoch, device), sent: false };
|
|
24
|
+
this.#state[key] = entry;
|
|
25
|
+
await this.#store.write(this.#state);
|
|
26
|
+
} await this.options.send(entry.envelope); entry.sent = true; await this.#store.write(this.#state); }); this.#tail = run.catch(() => { }); return run; }
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=key-delivery.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { mobileActionSchema } from './contracts.js';
|
|
3
|
+
export const spaceMobileArguments = z.discriminatedUnion('operation', [
|
|
4
|
+
z.object({ operation: z.literal('list') }).strict(),
|
|
5
|
+
z.object({ operation: z.literal('action'), device: z.string().min(1).max(128), action: mobileActionSchema }).strict(),
|
|
6
|
+
z.object({ operation: z.literal('result'), action_id: z.string().min(1).max(128) }).strict(),
|
|
7
|
+
]);
|
|
8
|
+
export const SPACE_MOBILE_TOOL_SPEC = { name: 'mobile__action', description: 'Execute one explicit system action on a paired phone: read a specified calendar interval, create one reminder with title and due time, or ask the user to capture one photo. Host plans; phone only checks permissions and executes the exact action. Never send a goal, instruction to an agent, script or multi-step plan. list returns paired device IDs; action returns action_id with pending status. Only result=completed proves execution; denied/failed/unknown must not be retried automatically. Call result with the same action_id to inspect progress.', inject_origin_ref: true, params: { type: 'object', properties: { operation: { type: 'string', enum: ['list', 'action', 'result'] }, device: { type: 'string' }, action: z.toJSONSchema(mobileActionSchema), action_id: { type: 'string' } }, oneOf: spaceMobileArguments.options.map(value => z.toJSONSchema(value)) } };
|
|
9
|
+
//# sourceMappingURL=mobile-tools.js.map
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { link, mkdir, open, unlink } from 'node:fs/promises';
|
|
5
|
+
import { dirname } from 'node:path';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { MODEL_ROUTE_LANE_IDS, MODEL_ROUTE_LANE_PROVIDERS, MODEL_ROUTE_PROVIDER_METADATA, modelRoutesSchema, parseModelRoutes } from '../config/model-routes.js';
|
|
8
|
+
import { MODEL_CATALOG_MODELS, MODEL_CATALOG_PROVIDERS } from '../model/model-catalog.js';
|
|
9
|
+
import { BoundedJsonStore } from '../storage/bounded-json.js';
|
|
10
|
+
import { canonicalJson } from '../text/canonical-json.js';
|
|
11
|
+
export const modelRoutesPatchSchema = z.object({
|
|
12
|
+
expected_version: z.number().int().nonnegative(),
|
|
13
|
+
routes: modelRoutesSchema.removeDefault(),
|
|
14
|
+
}).strict();
|
|
15
|
+
const fileSchema = z.object({
|
|
16
|
+
v: z.literal(1),
|
|
17
|
+
version: z.number().int().nonnegative(),
|
|
18
|
+
routes: modelRoutesSchema.removeDefault(),
|
|
19
|
+
applied_ops: z.array(z.object({
|
|
20
|
+
opId: z.string().min(1).max(256),
|
|
21
|
+
payloadHash: z.string().regex(/^[a-f0-9]{64}$/u),
|
|
22
|
+
resultVersion: z.number().int().positive(),
|
|
23
|
+
}).strict()).max(64),
|
|
24
|
+
}).strict().superRefine((state, context) => {
|
|
25
|
+
if (new Set(state.applied_ops.map(op => op.opId)).size !== state.applied_ops.length
|
|
26
|
+
|| state.applied_ops.some(op => op.resultVersion > state.version))
|
|
27
|
+
context.addIssue({ code: 'custom', message: 'invalid_model_receipts' });
|
|
28
|
+
});
|
|
29
|
+
const CAPACITY = 128 * 1024;
|
|
30
|
+
const changes = new EventEmitter();
|
|
31
|
+
/** Signals carry no settings or credentials. The runtime owns the single writer. */
|
|
32
|
+
export function subscribeHostModelRoutesChanges(listener) {
|
|
33
|
+
changes.on('changed', listener);
|
|
34
|
+
return () => { changes.off('changed', listener); };
|
|
35
|
+
}
|
|
36
|
+
export const hostModelRoutesPath = (configPath) => configPath + '.models.json';
|
|
37
|
+
function readFile(configPath) {
|
|
38
|
+
let fd;
|
|
39
|
+
const path = hostModelRoutesPath(configPath);
|
|
40
|
+
try {
|
|
41
|
+
if (lstatSync(path).isSymbolicLink())
|
|
42
|
+
throw Error('space_models_invalid');
|
|
43
|
+
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code === 'ENOENT')
|
|
47
|
+
return null;
|
|
48
|
+
throw Error('space_models_invalid');
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const stat = fstatSync(fd);
|
|
52
|
+
const entry = lstatSync(path);
|
|
53
|
+
if (!entry.isFile() || entry.dev !== stat.dev || entry.ino !== stat.ino)
|
|
54
|
+
throw Error('space_models_invalid');
|
|
55
|
+
if (!stat.isFile() || stat.size > CAPACITY || process.platform !== 'win32' && ((stat.mode & 0o077) !== 0 || typeof process.getuid === 'function' && stat.uid !== process.getuid()))
|
|
56
|
+
throw Error('space_models_invalid');
|
|
57
|
+
const text = readFileSync(fd, 'utf8');
|
|
58
|
+
// Existing empty files are damaged documents too; preserve them instead of silently resetting state.
|
|
59
|
+
if (!text)
|
|
60
|
+
throw Error('space_models_invalid');
|
|
61
|
+
return fileSchema.parse(JSON.parse(text));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
throw Error('space_models_invalid');
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
closeSync(fd);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function readHostModelRoutes(configPath) {
|
|
71
|
+
const state = readFile(configPath);
|
|
72
|
+
return state === null ? null : { version: state.version, routes: parseModelRoutes(JSON.stringify(state.routes)) };
|
|
73
|
+
}
|
|
74
|
+
/** Publish a complete initial document without replacing any existing file, including a damaged one. */
|
|
75
|
+
export async function seedHostModelRoutes(configPath, routes) {
|
|
76
|
+
const state = fileSchema.parse({ v: 1, version: 0, routes, applied_ops: [] });
|
|
77
|
+
const path = hostModelRoutesPath(configPath), temp = path + '.' + randomUUID() + '.tmp';
|
|
78
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
79
|
+
try {
|
|
80
|
+
const file = await open(temp, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
81
|
+
try {
|
|
82
|
+
await file.writeFile(JSON.stringify(state));
|
|
83
|
+
await file.sync();
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
await file.close();
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
await link(temp, path);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (error.code !== 'EEXIST')
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
if (process.platform !== 'win32') {
|
|
96
|
+
const dir = await open(dirname(path), constants.O_RDONLY);
|
|
97
|
+
try {
|
|
98
|
+
await dir.sync();
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
await dir.close();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
await unlink(temp).catch(() => { });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function overlaySpaceModelRoutes(environment, configPath) {
|
|
110
|
+
if (!configPath || environment.MODEL_ROUTES?.trim())
|
|
111
|
+
return environment;
|
|
112
|
+
const state = readHostModelRoutes(configPath);
|
|
113
|
+
return state === null ? environment : { ...environment, MODEL_ROUTES: JSON.stringify(state.routes) };
|
|
114
|
+
}
|
|
115
|
+
function endpointConfigured(value) {
|
|
116
|
+
if (!value?.trim())
|
|
117
|
+
return false;
|
|
118
|
+
try {
|
|
119
|
+
const url = new URL(value);
|
|
120
|
+
return ['https:', 'http:'].includes(url.protocol) && !!url.hostname && !url.username && !url.password;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Single controller-owned writer; the PersonalAgentHost process lock excludes other runtimes. */
|
|
127
|
+
export class HostModelRoutesStore {
|
|
128
|
+
configPath;
|
|
129
|
+
options;
|
|
130
|
+
#store;
|
|
131
|
+
#state;
|
|
132
|
+
#appliedVersion;
|
|
133
|
+
#environment;
|
|
134
|
+
#tail = Promise.resolve();
|
|
135
|
+
constructor(configPath, environment = process.env, options = {}) {
|
|
136
|
+
this.configPath = configPath;
|
|
137
|
+
this.options = options;
|
|
138
|
+
this.#environment = { ...environment };
|
|
139
|
+
const initial = { v: 1, version: 0, routes: {}, applied_ops: [] };
|
|
140
|
+
try {
|
|
141
|
+
this.#state = readFile(configPath) ?? initial;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
// Explicit operator routes stay authoritative; the damaged file remains untouched and locked.
|
|
145
|
+
if (!environment.MODEL_ROUTES?.trim())
|
|
146
|
+
throw error;
|
|
147
|
+
this.#state = initial;
|
|
148
|
+
}
|
|
149
|
+
this.#appliedVersion = this.#state.version;
|
|
150
|
+
this.#store = new BoundedJsonStore(hostModelRoutesPath(configPath), fileSchema, CAPACITY);
|
|
151
|
+
}
|
|
152
|
+
#providers() {
|
|
153
|
+
return MODEL_CATALOG_PROVIDERS.map(provider => {
|
|
154
|
+
const metadata = MODEL_ROUTE_PROVIDER_METADATA[provider.id];
|
|
155
|
+
const configured = !!this.#environment[metadata.keyName]?.trim() || this.options.credentialConfigured?.(metadata.keyName) === true;
|
|
156
|
+
const endpoint = provider.id === 'self-hosted' ? endpointConfigured(this.#environment.SELF_HOSTED_LLM_BASE_URL)
|
|
157
|
+
: provider.id === 'openai-compatible' ? endpointConfigured(this.#environment.OPENAI_COMPATIBLE_BASE_URL) : true;
|
|
158
|
+
return { id: provider.id, label: provider.label, keyName: metadata.keyName, keyOptional: metadata.keyOptional, configured, usable: endpoint && (configured || metadata.keyOptional) };
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
view() {
|
|
162
|
+
const locked = !!this.#environment.MODEL_ROUTES?.trim();
|
|
163
|
+
return { version: this.#state.version, applied_version: this.#appliedVersion,
|
|
164
|
+
routes: locked ? parseModelRoutes(this.#environment.MODEL_ROUTES) : parseModelRoutes(JSON.stringify(this.#state.routes)),
|
|
165
|
+
locked, source: locked ? 'environment' : 'space',
|
|
166
|
+
providers: this.#providers(), lanes: MODEL_ROUTE_LANE_PROVIDERS, models: MODEL_CATALOG_MODELS };
|
|
167
|
+
}
|
|
168
|
+
configure(params, opId) {
|
|
169
|
+
const run = this.#tail.then(async () => {
|
|
170
|
+
const patch = modelRoutesPatchSchema.parse(params);
|
|
171
|
+
z.string().min(1).max(256).parse(opId);
|
|
172
|
+
const payloadHash = createHash('sha256').update(canonicalJson(params)).digest('hex');
|
|
173
|
+
const prior = this.#state.applied_ops.find(op => op.opId === opId);
|
|
174
|
+
if (prior) {
|
|
175
|
+
if (prior.payloadHash !== payloadHash)
|
|
176
|
+
throw Error('op_id_conflict');
|
|
177
|
+
return { version: prior.resultVersion, applies: 'restart' };
|
|
178
|
+
}
|
|
179
|
+
if (this.#environment.MODEL_ROUTES?.trim())
|
|
180
|
+
throw Error('models_locked_by_environment');
|
|
181
|
+
if (patch.expected_version !== this.#state.version)
|
|
182
|
+
throw Error('version_conflict');
|
|
183
|
+
const routes = { ...this.#state.routes };
|
|
184
|
+
const providers = this.#providers();
|
|
185
|
+
for (const lane of MODEL_ROUTE_LANE_IDS) {
|
|
186
|
+
if (!Object.hasOwn(patch.routes, lane))
|
|
187
|
+
continue;
|
|
188
|
+
const route = patch.routes[lane];
|
|
189
|
+
if (route == null)
|
|
190
|
+
delete routes[lane];
|
|
191
|
+
else {
|
|
192
|
+
if (!providers.find(provider => provider.id === route.provider)?.usable)
|
|
193
|
+
throw Error('model_provider_unconfigured');
|
|
194
|
+
routes[lane] = route;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const version = this.#state.version + 1;
|
|
198
|
+
const next = { v: 1, version, routes, applied_ops: [...this.#state.applied_ops, { opId, payloadHash, resultVersion: version }].slice(-64) };
|
|
199
|
+
// Validate the existing bytes before replacement, so a damaged document is preserved even after startup.
|
|
200
|
+
readFile(this.configPath);
|
|
201
|
+
await this.#store.write(next);
|
|
202
|
+
this.#state = next;
|
|
203
|
+
try {
|
|
204
|
+
changes.emit('changed');
|
|
205
|
+
}
|
|
206
|
+
catch { /* Observers cannot roll back a durable edit. */ }
|
|
207
|
+
return { version, applies: 'restart' };
|
|
208
|
+
});
|
|
209
|
+
this.#tail = run.catch(() => { });
|
|
210
|
+
return run;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=model-settings.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { effectiveTimelineAnchor, resolvedTimeSchema } from '../personal-agent/timeline-time.js';
|
|
2
|
+
export function displayText(value, fallback = '') { return typeof value === 'string' ? value : typeof value === 'number' || typeof value === 'boolean' ? String(value) : fallback; }
|
|
3
|
+
const fields = ['id', 'kind', 'title', 'note', 'status', 'importance', 'version', 'created_at', 'updated_at', 'due', 'goal_id', 'idea_id', 'success_criteria', 'progress'];
|
|
4
|
+
const pick = (row, keys) => Object.fromEntries(keys.filter(key => row[key] !== undefined).map(key => [key, row[key]]));
|
|
5
|
+
function timelineTime(value) {
|
|
6
|
+
const raw = value && typeof value === 'object' ? value : {}, parsed = resolvedTimeSchema.safeParse(value);
|
|
7
|
+
return { ...pick(raw, ['kind', 'anchor_date', 'anchor_basis', 'occurred_on', 'started_on', 'due_on', 'scheduled_on', 'last_reported_on', 'evidence_from', 'evidence_to', 'as_of']), ...(parsed.success ? effectiveTimelineAnchor(parsed.data) : {}) };
|
|
8
|
+
}
|
|
9
|
+
function card(row) { const time = timelineTime(row.time); return { id: displayText(row.id), kind: displayText(row.kind, 'text'), title: displayText(row.title), body: displayText(row.body ?? row.why_now).slice(0, 6000), version: typeof row.version === 'number' || typeof row.version === 'string' ? row.version : displayText(row.updated_at), ...(typeof row.created_at === 'string' ? { created_at: row.created_at } : {}), ...(typeof time.anchor_date === 'string' ? { date: time.anchor_date } : {}), dismissed: row.user_state === 'dismissed' }; }
|
|
10
|
+
/** The chat rows a snapshot shows, each with the request id of the user turn it belongs to. */
|
|
11
|
+
function chatWindow(host) { const rows = host.spaceChatMessages(); return rows.slice(-128).map(row => ({ row, request: (row.request_id ? row : rows.find(user => user.id === row.reply_to))?.request_id })); }
|
|
12
|
+
/** Request ids whose turn ids the snapshot chat window can still show; the Space journal keeps their chat receipts. */
|
|
13
|
+
export function visibleChatRequests(host) { return new Set(chatWindow(host).flatMap(({ request }) => request ? [request] : [])); }
|
|
14
|
+
/** The executor approvals a Space client can resolve: owned by a conversation, not yet past their wall-clock deadline. */
|
|
15
|
+
export function pendingApprovals(host, deadline, now) {
|
|
16
|
+
const rows = (host.snapshot().pending_approvals ?? []);
|
|
17
|
+
return rows.flatMap(row => { if (!row.conversation_id)
|
|
18
|
+
return []; const expires = deadline(row.approval_id, typeof row.expires_at === 'number' && Number.isFinite(row.expires_at) ? row.expires_at : null); if (expires !== null && expires <= now)
|
|
19
|
+
return []; return [{ id: row.approval_id, conversation_id: row.conversation_id, summary: displayText(row.summary).slice(0, 500), kind: row.kind ?? null, allowed_decisions: [...(row.allowed_decisions ?? ['accept', 'decline'])], expires_at: expires }]; }).slice(0, 32);
|
|
20
|
+
}
|
|
21
|
+
export function displaySnapshot(host, turns = new Map(), approvals) {
|
|
22
|
+
const llm = host.options.memory()?.sourceProcessingLlm?.();
|
|
23
|
+
const state = host.snapshot(), life = host.life.snapshot(), timeline = state.timeline;
|
|
24
|
+
const preparation = state.profile_preparation, rawStatus = preparation.status, status = rawStatus === 'working' || rawStatus === 'ready' || rawStatus === 'failed' ? rawStatus : 'idle';
|
|
25
|
+
const manual = life.profile.version > 0, saved = 'last_success' in preparation ? preparation.last_success : undefined, draft = manual ? undefined : preparation.draft ?? saved?.draft;
|
|
26
|
+
const profilePresentation = { about: displayText(manual ? life.profile.about : life.profile.about || draft?.about?.text).slice(0, 5000), work: (draft?.work ?? []).slice(0, 6).map(item => ({ title: displayText(item.title).slice(0, 80), text: displayText(item.text).slice(0, 500) })), interests: (draft?.interests ?? []).filter(item => typeof item.text === 'string' && item.text.trim()).slice(0, 8).map(item => item.text.slice(0, 100)), source: manual ? 'manual' : preparation.draft ? 'current' : saved?.draft ? 'last_success' : 'empty' };
|
|
27
|
+
const timelineEntries = (timeline.cards ?? []).filter(row => row.user_state !== 'dismissed').flatMap(row => {
|
|
28
|
+
const time = timelineTime(row.time), observedAt = displayText(timeline.updated_at ?? timeline.checkpoint?.last_success_at ?? time?.as_of ?? time?.anchor_date);
|
|
29
|
+
if (!Number.isFinite(Date.parse(observedAt)))
|
|
30
|
+
return [];
|
|
31
|
+
const facts = Array.isArray(row.facts) ? row.facts : [], steps = Array.isArray(row.next_steps) ? row.next_steps : [];
|
|
32
|
+
return [{ key: displayText(row.id), kind: 'timeline', text: displayText(row.title), observed_at: observedAt, time, evidence_ids: [], brief: { title: displayText(row.title), category: displayText(row.category), status_label: displayText(row.status_label), facts: facts.slice(0, 3).map(fact => pick(fact, ['label', 'tone', 'text'])), why_now: displayText(row.why_now), next_steps: steps.slice(0, 3).map(step => pick(step, ['title', 'detail'])), actions: (Array.isArray(row.actions) ? row.actions : []).slice(0, 2).flatMap(action => { const a = action; return (a.kind === 'discuss' || a.kind === 'draft') && displayText(a.label) ? [{ label: displayText(a.label).slice(0, 40), kind: a.kind }] : []; }), uncertainty: displayText(row.uncertainty) } }];
|
|
33
|
+
});
|
|
34
|
+
const conversations = (state.conversations?.items ?? []).slice(-128).map(row => ({ ...pick(row, ['id', 'kind', 'title', 'created_at', 'updated_at', 'generation_status', 'mode']), preview: displayText(row.last_message), ...(row.build ? { build_status: row.build.status } : {}) }));
|
|
35
|
+
return { schema_version: 1, pending_approvals: approvals ?? pendingApprovals(host, () => null, Date.now()), timeline_entries: timelineEntries, timeline_available_evidence_ids: [], conversations, processing_provider: llm ? { id: llm.baseUrl + '|' + llm.model, label: llm.model } : null, source_processing: { status, needs_update: 'needs_update' in preparation && preparation.needs_update === true }, revision: state.revision, goals: life.goals.map(row => pick(row, fields)), todos: life.todos.map(row => pick(row, fields)), ideas: life.ideas.map(row => pick(row, fields)), profile: life.profile, profile_presentation: profilePresentation, timeline: (timeline.cards ?? []).map(card), feed: state.feed.slice(-200).map(row => card({ ...row, body: row.prepared?.text ?? row.why_now })), notifications: host.notifications.display().map(card), chat: chatWindow(host).map(({ row, request }) => { const turn = request ? turns.get(request) : undefined; return { ...pick(row, ['id', 'conversation_id', 'role', 'text', 'created_at', 'turn_id', 'status', 'failure_reason']), ...(turn ? { turn_id: turn, ...(row.role === 'user' ? { id: 'user_' + turn } : {}) } : {}) }; }) };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { CompactEncrypt } from 'jose';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { BoundedJsonStore } from '../storage/bounded-json.js';
|
|
5
|
+
const statusSchema = z.enum(['accepted', 'invalid_token', 'quota_exceeded', 'rejected', 'unknown']);
|
|
6
|
+
const registrationSchema = z.object({ handle: z.string(), credential: z.string(), key: z.string() });
|
|
7
|
+
const stateSchema = z.object({ v: z.literal(1), registrations: z.record(z.string(), registrationSchema), receipts: z.record(z.string(), z.object({ status: statusSchema, digest: z.string(), handle: z.string().optional() })) });
|
|
8
|
+
const inputSchema = z.object({ handle: z.string().min(1).max(128), credential: z.string().min(1).max(256), gateway_url: z.string().optional() }).strict();
|
|
9
|
+
const fingerprint = (v) => createHash('sha256').update(JSON.stringify(v)).digest('hex');
|
|
10
|
+
function normalizeGateway(value) {
|
|
11
|
+
const url = new URL(value);
|
|
12
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash || url.pathname !== '/')
|
|
13
|
+
throw Error('invalid_push_gateway');
|
|
14
|
+
return url.origin;
|
|
15
|
+
}
|
|
16
|
+
/** Host process lock and one owner per journal are required, as for the SpaceHost journal. */
|
|
17
|
+
export class SpacePushDelivery {
|
|
18
|
+
options;
|
|
19
|
+
#store;
|
|
20
|
+
#gateway;
|
|
21
|
+
#request;
|
|
22
|
+
#state = { v: 1, registrations: {}, receipts: {} };
|
|
23
|
+
#opened = false;
|
|
24
|
+
#tail = Promise.resolve();
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.#gateway = normalizeGateway(options.gatewayUrl);
|
|
28
|
+
this.#request = options.request ?? fetch;
|
|
29
|
+
this.#store = new BoundedJsonStore(options.path, stateSchema, 16 * 1024 * 1024);
|
|
30
|
+
}
|
|
31
|
+
#serial(work) { const run = this.#tail.then(work); this.#tail = run.catch(() => { }); return run; }
|
|
32
|
+
async open() { if (this.#opened)
|
|
33
|
+
return; try {
|
|
34
|
+
this.#state = await this.#store.read(this.#state);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error.code !== 'ENOENT')
|
|
38
|
+
throw error;
|
|
39
|
+
} this.#opened = true; await this.#store.write(this.#state); }
|
|
40
|
+
// Only tagged receipts for handles no longer used by this Host can be reclaimed.
|
|
41
|
+
// Legacy unclassified receipts are preserved rather than guessing their replay scope.
|
|
42
|
+
#pruneReceipts() { const active = new Set(Object.values(this.#state.registrations).map(value => value.handle)); for (const [id, receipt] of Object.entries(this.#state.receipts))
|
|
43
|
+
if (receipt.handle !== undefined && !active.has(receipt.handle))
|
|
44
|
+
delete this.#state.receipts[id]; }
|
|
45
|
+
async register(device, input) {
|
|
46
|
+
return this.#serial(async () => {
|
|
47
|
+
if (!this.#opened)
|
|
48
|
+
throw Error('push_closed');
|
|
49
|
+
const parsed = inputSchema.parse(input);
|
|
50
|
+
if (parsed.gateway_url !== undefined && normalizeGateway(parsed.gateway_url) !== this.#gateway)
|
|
51
|
+
throw Error('gateway_not_allowed');
|
|
52
|
+
const current = this.#state.registrations[device];
|
|
53
|
+
if (current?.handle === parsed.handle && current.credential !== parsed.credential)
|
|
54
|
+
throw Error('push_credential_conflict');
|
|
55
|
+
const registration = current?.handle === parsed.handle ? current : { handle: parsed.handle, credential: parsed.credential, key: randomBytes(32).toString('base64url') };
|
|
56
|
+
this.#state.registrations[device] = registration;
|
|
57
|
+
this.#pruneReceipts();
|
|
58
|
+
await this.#store.write(this.#state);
|
|
59
|
+
// Mailbox delivery of this message is E2E; only the destination Client receives the key.
|
|
60
|
+
return { v: 1, type: 'push.key', handle: registration.handle, notification_key: registration.key };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async revoke(device) {
|
|
64
|
+
await this.#serial(async () => {
|
|
65
|
+
const registration = this.#state.registrations[device];
|
|
66
|
+
if (!registration)
|
|
67
|
+
return;
|
|
68
|
+
delete this.#state.registrations[device];
|
|
69
|
+
this.#pruneReceipts();
|
|
70
|
+
await this.#store.write(this.#state);
|
|
71
|
+
try {
|
|
72
|
+
await this.#request(`${this.#gateway}/v1/registrations/${encodeURIComponent(registration.handle)}`, { method: 'DELETE', headers: { authorization: `Bearer ${registration.credential}` }, redirect: 'error', signal: AbortSignal.timeout(10_000) });
|
|
73
|
+
}
|
|
74
|
+
catch { /* Local revocation takes effect even while gateway is unavailable. */ }
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async prune(devices) { for (const device of Object.keys(this.#state.registrations))
|
|
78
|
+
if (!devices.includes(device))
|
|
79
|
+
await this.revoke(device); }
|
|
80
|
+
async send(device, notification) {
|
|
81
|
+
return this.#serial(async () => {
|
|
82
|
+
if (!this.#opened)
|
|
83
|
+
throw Error('push_closed');
|
|
84
|
+
const registration = this.#state.registrations[device];
|
|
85
|
+
if (!registration)
|
|
86
|
+
return { status: 'rejected', retryable: false };
|
|
87
|
+
if (!notification.id || notification.id.length > 128)
|
|
88
|
+
throw Error('invalid_notification_id');
|
|
89
|
+
const receiptId = fingerprint([device, registration.handle, notification.id]), digest = fingerprint(notification), old = this.#state.receipts[receiptId];
|
|
90
|
+
if (old) {
|
|
91
|
+
if (old.digest !== digest)
|
|
92
|
+
throw Error('notification_conflict');
|
|
93
|
+
return { status: old.status, retryable: false };
|
|
94
|
+
}
|
|
95
|
+
const now = this.options.now?.() ?? Date.now(), expiresAt = Math.min(notification.expires_at ?? now + 86400000, now + 86400000);
|
|
96
|
+
if (!Number.isSafeInteger(expiresAt) || expiresAt <= now)
|
|
97
|
+
return { status: 'rejected', retryable: false };
|
|
98
|
+
// Persist reservation before provider I/O. Process death or lost response can never cause an automatic second send.
|
|
99
|
+
this.#state.receipts[receiptId] = { status: 'unknown', digest, handle: registration.handle };
|
|
100
|
+
await this.#store.write(this.#state);
|
|
101
|
+
let status = 'unknown';
|
|
102
|
+
try {
|
|
103
|
+
let title = notification.title.slice(0, 120), body = notification.body.slice(0, 1024);
|
|
104
|
+
let ciphertext = await new CompactEncrypt(Buffer.from(JSON.stringify({ title, body }))).setProtectedHeader({ alg: 'dir', enc: 'A256GCM' }).encrypt(Buffer.from(registration.key, 'base64url'));
|
|
105
|
+
// Unicode can exceed the provider's byte limit: preserve a generic, encrypted fallback.
|
|
106
|
+
if (Buffer.byteLength(ciphertext) > 3000) {
|
|
107
|
+
title = 'Nova';
|
|
108
|
+
body = 'Open Nova to view new updates.';
|
|
109
|
+
ciphertext = await new CompactEncrypt(Buffer.from(JSON.stringify({ title, body }))).setProtectedHeader({ alg: 'dir', enc: 'A256GCM' }).encrypt(Buffer.from(registration.key, 'base64url'));
|
|
110
|
+
}
|
|
111
|
+
const response = await this.#request(`${this.#gateway}/v1/push`, { method: 'POST', headers: { authorization: `Bearer ${registration.credential}`, 'content-type': 'application/json' }, body: JSON.stringify({ handle: registration.handle, notificationId: notification.id, ciphertext, expiresAt }), redirect: 'error', signal: AbortSignal.timeout(10_000) });
|
|
112
|
+
if (response.ok) {
|
|
113
|
+
const parsed = z.object({ status: statusSchema }).safeParse(await response.json());
|
|
114
|
+
if (parsed.success)
|
|
115
|
+
status = parsed.data.status;
|
|
116
|
+
}
|
|
117
|
+
else if (response.status === 401) {
|
|
118
|
+
status = 'invalid_token';
|
|
119
|
+
}
|
|
120
|
+
else if (response.status === 429) {
|
|
121
|
+
status = 'quota_exceeded';
|
|
122
|
+
}
|
|
123
|
+
else if (response.status >= 400 && response.status < 500) {
|
|
124
|
+
status = 'rejected';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch { /* Ambiguous transport/provider errors are deliberately unknown. */ }
|
|
128
|
+
if (status === 'invalid_token')
|
|
129
|
+
delete this.#state.registrations[device];
|
|
130
|
+
this.#state.receipts[receiptId] = { status, digest, handle: registration.handle };
|
|
131
|
+
this.#pruneReceipts();
|
|
132
|
+
await this.#store.write(this.#state);
|
|
133
|
+
return { status, retryable: false };
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=push.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { BoundedJsonStore } from '../storage/bounded-json.js';
|
|
4
|
+
const envelopeSchema = z.object({ v: z.literal(1), space: z.string(), id: z.string(), from: z.string(), to: z.string(), chan: z.enum(['mailbox', 'stream']), epoch: z.number(), expiresAt: z.number().nullable(), body: z.string(), sig: z.string() });
|
|
5
|
+
const cacheSchema = z.object({ space: z.string(), epoch: z.number(), entries: z.record(z.string(), z.object({ hash: z.string(), envelope: envelopeSchema.optional(), accepted: z.boolean().default(false) })) });
|
|
6
|
+
/** All sockets are outbound. Durable encrypted envelope cache makes ambiguous HTTP retry byte-identical. */
|
|
7
|
+
export async function createRelaySpaceTransport(options) {
|
|
8
|
+
const store = new BoundedJsonStore(options.path, cacheSchema, 32 * 1024 * 1024);
|
|
9
|
+
let cache = { space: options.space, epoch: options.epoch, entries: {} };
|
|
10
|
+
try {
|
|
11
|
+
cache = await store.read(cache);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code !== 'ENOENT')
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
if (cache.space !== options.space || cache.epoch !== options.epoch)
|
|
18
|
+
throw Error('space_transport_epoch_mismatch');
|
|
19
|
+
let tail = Promise.resolve();
|
|
20
|
+
const seal = (to, body, id, chan) => { const run = tail.then(async () => { if (!Object.hasOwn(options.members, to))
|
|
21
|
+
throw Error('client_not_paired'); const hash = createHash('sha256').update(JSON.stringify({ to, body, chan })).digest('hex'), old = cache.entries[id]; if (old) {
|
|
22
|
+
if (old.hash !== hash)
|
|
23
|
+
throw Error('outbound_id_conflict');
|
|
24
|
+
if (old.accepted)
|
|
25
|
+
return undefined;
|
|
26
|
+
if (!old.envelope)
|
|
27
|
+
throw Error('invalid_outbound_cache');
|
|
28
|
+
return old.envelope;
|
|
29
|
+
} const envelope = await options.crypto.signEnvelope({ v: 1, space: options.space, id: 'e' + options.epoch + '-' + id + '-' + randomUUID(), from: options.identity.device, to, chan, epoch: options.epoch, expiresAt: chan === 'stream' ? Date.now() + 30000 : null, body: await options.crypto.encryptBody(body, options.contentKey) }, options.identity.signingPrivateKey); if (chan === 'mailbox') {
|
|
30
|
+
if (Object.keys(cache.entries).length >= 10000)
|
|
31
|
+
throw Error('space_transport_capacity');
|
|
32
|
+
cache.entries[id] = { hash, envelope, accepted: false };
|
|
33
|
+
await store.write(cache);
|
|
34
|
+
} return envelope; }); tail = run.catch(() => { }); return run; };
|
|
35
|
+
const decode = async (envelope) => { if (envelope.space !== options.space || envelope.to !== options.identity.device || envelope.epoch > options.epoch || envelope.from === options.identity.device)
|
|
36
|
+
throw Error('envelope_scope_mismatch'); const key = Object.hasOwn(options.members, envelope.from) ? options.members[envelope.from] : envelope.epoch < options.epoch && options.historicalMembers && Object.hasOwn(options.historicalMembers, envelope.from) ? options.historicalMembers[envelope.from] : undefined; if (!key)
|
|
37
|
+
throw Error('sender_not_paired'); options.crypto.verifyEnvelope(envelope, key); if (envelope.epoch < options.epoch || envelope.expiresAt !== null && envelope.expiresAt <= Date.now())
|
|
38
|
+
return undefined; return options.crypto.decryptBody(envelope.body, options.contentKey); };
|
|
39
|
+
return { settle: async (id) => { const run = tail.then(async () => { delete cache.entries[id]; await store.write(cache); }); tail = run.catch(() => { }); await run; }, recoverPending: async (ids) => { const run = tail.then(async () => { for (const [id, entry] of Object.entries(cache.entries))
|
|
40
|
+
if ((entry.accepted || id.startsWith('snapshot-')) && !ids.includes(id))
|
|
41
|
+
delete cache.entries[id]; await store.write(cache); }); tail = run.catch(() => { }); await run; }, clients: () => Object.keys(options.members).filter(device => device !== options.identity.device), send: async (to, body, id) => { await options.beforeSend?.(to); const envelope = await seal(to, body, id, 'mailbox'); if (!envelope)
|
|
42
|
+
return; await options.client.send(envelope); const run = tail.then(async () => { const entry = cache.entries[id]; if (entry) {
|
|
43
|
+
cache.entries[id] = { hash: entry.hash, accepted: true };
|
|
44
|
+
await store.write(cache);
|
|
45
|
+
} }); tail = run.catch(() => { }); await run; }, stream: async (to, body, id) => { await options.beforeSend?.(to); const envelope = await seal(to, body, id, 'stream'); if (envelope)
|
|
46
|
+
await options.client.stream(envelope); }, start: (receive, cursor) => {
|
|
47
|
+
let ordered = Promise.resolve();
|
|
48
|
+
const handle = (envelope) => { const run = ordered.then(async () => { const body = await decode(envelope); if (body === undefined)
|
|
49
|
+
return; if (envelope.chan !== 'stream' && typeof body === 'object' && body !== null && 'kind' in body && (body.kind === 'chat.send' || body.kind === 'voice.start'))
|
|
50
|
+
return; await receive(envelope.from, body); }); ordered = run.catch(() => { }); return run; };
|
|
51
|
+
return Promise.resolve(options.client.start({ onMailbox: async (envelope) => { await handle(envelope); }, onStream: envelope => { void handle(envelope).catch(error => options.onError?.(error)); }, loadCursor: () => Promise.resolve(cursor.load()), saveCursor: cursor.save, onConnection: () => { }, onError: error => options.onError?.(error) }));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=relay-transport.js.map
|