nova-personal-agent-server 0.4.1 → 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 +10 -0
- 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 +11 -4
- 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,191 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BoundedJsonStore } from '../storage/bounded-json.js';
|
|
3
|
+
const HOUR = 60 * 60 * 1000;
|
|
4
|
+
/** Positive and negative screening indexes age out with the timeline's own two-week window. */
|
|
5
|
+
const INDEX_TTL = 72 * HOUR;
|
|
6
|
+
/** Cached stage replies only describe one model/system/prompt triple; a day is long enough to absorb repeated runs. */
|
|
7
|
+
const STAGE_TTL = 24 * HOUR;
|
|
8
|
+
const MAX_TOPICS = 256;
|
|
9
|
+
const MAX_SCREENED = 4096;
|
|
10
|
+
const MAX_STAGES = 128;
|
|
11
|
+
/** Leave headroom below BoundedJsonStore's 4MB limit; a write that cannot fit is skipped instead of failing the run. */
|
|
12
|
+
const MAX_WRITE_BYTES = 3 * 1024 * 1024;
|
|
13
|
+
const WRITE_DEBOUNCE_MS = 1000;
|
|
14
|
+
const memberSchema = z.object({ id: z.string(), version: z.string() });
|
|
15
|
+
const topicSchema = z.object({ scope: z.string(), title: z.string(), at: z.number(), members: z.array(memberSchema) });
|
|
16
|
+
const screenedSchema = z.object({ scope: z.string(), id: z.string(), version: z.string(), at: z.number() });
|
|
17
|
+
export const timelineCacheStageKindSchema = z.enum(['select', 'reconcile', 'batch']);
|
|
18
|
+
const stageSchema = z.object({ key: z.string(), kind: timelineCacheStageKindSchema, at: z.number(), payload: z.unknown() });
|
|
19
|
+
const documentSchema = z.object({ version: z.literal(1), topics: z.array(topicSchema), screened: z.array(screenedSchema), stages: z.array(stageSchema) });
|
|
20
|
+
const emptyDocument = () => ({ version: 1, topics: [], screened: [], stages: [] });
|
|
21
|
+
const topicKey = (topic) => topic.scope + '\0' + topic.title + '\0' + topic.members.map(member => member.id + '\u0001' + member.version).join('\u0002');
|
|
22
|
+
const clone = (value) => { try {
|
|
23
|
+
return structuredClone(value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
} };
|
|
28
|
+
/**
|
|
29
|
+
* Durable incremental index for PC Timeline generation.
|
|
30
|
+
*
|
|
31
|
+
* Every operation is fail-open: a corrupt file, a schema change or a full disk only loses the
|
|
32
|
+
* cache, never a briefing. Writes are serialized and debounced, and a write that cannot be
|
|
33
|
+
* bounded to `MAX_WRITE_BYTES` is skipped rather than reported.
|
|
34
|
+
*/
|
|
35
|
+
export class TimelineCache {
|
|
36
|
+
path;
|
|
37
|
+
#store;
|
|
38
|
+
#now;
|
|
39
|
+
#document = emptyDocument();
|
|
40
|
+
#epoch = 0;
|
|
41
|
+
#tail = Promise.resolve();
|
|
42
|
+
#timer;
|
|
43
|
+
#dirty = false;
|
|
44
|
+
constructor(path, options = {}) {
|
|
45
|
+
this.path = path;
|
|
46
|
+
this.#store = new BoundedJsonStore(path, documentSchema);
|
|
47
|
+
this.#now = options.now ?? Date.now;
|
|
48
|
+
}
|
|
49
|
+
/** Opening never throws: an unreadable cache is treated as empty. */
|
|
50
|
+
async open() {
|
|
51
|
+
try {
|
|
52
|
+
this.#document = this.#prune(await this.#store.read(emptyDocument()));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
this.#document = emptyDocument();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
beginRun(scope) {
|
|
59
|
+
const epoch = this.#epoch;
|
|
60
|
+
const current = () => epoch === this.#epoch;
|
|
61
|
+
return {
|
|
62
|
+
getTopics: () => current() ? this.#topics(scope) : [],
|
|
63
|
+
getScreened: () => current() ? this.#screened(scope) : [],
|
|
64
|
+
appendBatchResult: result => { if (current())
|
|
65
|
+
this.#append(scope, result); },
|
|
66
|
+
getStage: key => current() ? this.#stage(key) : undefined,
|
|
67
|
+
putStage: (key, kind, payload) => { if (current())
|
|
68
|
+
this.#put(key, kind, payload); },
|
|
69
|
+
deleteStage: key => { if (current())
|
|
70
|
+
this.#delete(key); },
|
|
71
|
+
commit: () => current() ? this.#flush() : Promise.resolve(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Discards both indexes and every stage; an in-flight run's later writes are dropped by the epoch bump. */
|
|
75
|
+
async clear() {
|
|
76
|
+
this.#epoch++;
|
|
77
|
+
if (this.#timer !== undefined) {
|
|
78
|
+
clearTimeout(this.#timer);
|
|
79
|
+
this.#timer = undefined;
|
|
80
|
+
}
|
|
81
|
+
this.#document = emptyDocument();
|
|
82
|
+
this.#dirty = true;
|
|
83
|
+
await this.#enqueue();
|
|
84
|
+
}
|
|
85
|
+
/** Settles the debounced write queue without discarding the cache. */
|
|
86
|
+
async flush() {
|
|
87
|
+
await this.#flush();
|
|
88
|
+
}
|
|
89
|
+
#topics(scope) {
|
|
90
|
+
const now = this.#now();
|
|
91
|
+
return this.#document.topics.filter(topic => topic.scope === scope && now - topic.at <= INDEX_TTL).map(topic => ({ scope: topic.scope, title: topic.title, at: topic.at, members: topic.members.map(member => ({ ...member })) }));
|
|
92
|
+
}
|
|
93
|
+
#screened(scope) {
|
|
94
|
+
const now = this.#now(), seen = new Map();
|
|
95
|
+
for (const entry of this.#document.screened)
|
|
96
|
+
if (entry.scope === scope && now - entry.at <= INDEX_TTL)
|
|
97
|
+
seen.set(entry.id, { id: entry.id, version: entry.version });
|
|
98
|
+
return [...seen.values()];
|
|
99
|
+
}
|
|
100
|
+
#append(scope, result) {
|
|
101
|
+
const now = this.#now();
|
|
102
|
+
const topics = new Map(this.#document.topics.map(topic => [topicKey(topic), topic]));
|
|
103
|
+
for (const topic of result.topics) {
|
|
104
|
+
const members = [...new Map(topic.members.map(member => [member.id, { id: member.id, version: member.version }])).values()];
|
|
105
|
+
if (!members.length)
|
|
106
|
+
continue;
|
|
107
|
+
const entry = { scope, title: topic.title, at: now, members };
|
|
108
|
+
topics.set(topicKey(entry), entry);
|
|
109
|
+
}
|
|
110
|
+
const screened = new Map(this.#document.screened.map(entry => [entry.scope + '\0' + entry.id, entry]));
|
|
111
|
+
for (const entry of result.screened)
|
|
112
|
+
screened.set(scope + '\0' + entry.id, { scope, id: entry.id, version: entry.version, at: now });
|
|
113
|
+
this.#document = { ...this.#document,
|
|
114
|
+
topics: [...topics.values()].sort((a, b) => a.at - b.at),
|
|
115
|
+
screened: [...screened.values()].sort((a, b) => a.at - b.at) };
|
|
116
|
+
this.#document = this.#prune(this.#document);
|
|
117
|
+
this.#touch();
|
|
118
|
+
}
|
|
119
|
+
#stage(key) {
|
|
120
|
+
const now = this.#now(), entry = this.#document.stages.find(stage => stage.key === key);
|
|
121
|
+
if (!entry || now - entry.at > STAGE_TTL)
|
|
122
|
+
return undefined;
|
|
123
|
+
const payload = clone(entry.payload);
|
|
124
|
+
return payload === undefined ? undefined : { kind: entry.kind, payload };
|
|
125
|
+
}
|
|
126
|
+
#put(key, kind, payload) {
|
|
127
|
+
const stored = clone(payload);
|
|
128
|
+
if (stored === undefined)
|
|
129
|
+
return;
|
|
130
|
+
const entry = { key, kind, at: this.#now(), payload: stored };
|
|
131
|
+
this.#document = { ...this.#document, stages: [...this.#document.stages.filter(stage => stage.key !== key), entry] };
|
|
132
|
+
this.#document = this.#prune(this.#document);
|
|
133
|
+
this.#touch();
|
|
134
|
+
}
|
|
135
|
+
#delete(key) {
|
|
136
|
+
const stages = this.#document.stages.filter(stage => stage.key !== key);
|
|
137
|
+
if (stages.length === this.#document.stages.length)
|
|
138
|
+
return;
|
|
139
|
+
this.#document = { ...this.#document, stages };
|
|
140
|
+
this.#touch();
|
|
141
|
+
}
|
|
142
|
+
#prune(document) {
|
|
143
|
+
const now = this.#now();
|
|
144
|
+
const topics = document.topics.filter(topic => now - topic.at <= INDEX_TTL).sort((a, b) => a.at - b.at).slice(-MAX_TOPICS);
|
|
145
|
+
const screened = document.screened.filter(entry => now - entry.at <= INDEX_TTL).sort((a, b) => a.at - b.at).slice(-MAX_SCREENED);
|
|
146
|
+
const stages = document.stages.filter(stage => now - stage.at <= STAGE_TTL).sort((a, b) => a.at - b.at).slice(-MAX_STAGES);
|
|
147
|
+
return { version: 1, topics, screened, stages };
|
|
148
|
+
}
|
|
149
|
+
#touch() {
|
|
150
|
+
this.#dirty = true;
|
|
151
|
+
if (this.#timer !== undefined)
|
|
152
|
+
return;
|
|
153
|
+
this.#timer = setTimeout(() => { this.#timer = undefined; void this.#enqueue(); }, WRITE_DEBOUNCE_MS);
|
|
154
|
+
this.#timer.unref?.();
|
|
155
|
+
}
|
|
156
|
+
#flush() {
|
|
157
|
+
if (this.#timer !== undefined) {
|
|
158
|
+
clearTimeout(this.#timer);
|
|
159
|
+
this.#timer = undefined;
|
|
160
|
+
}
|
|
161
|
+
if (!this.#dirty)
|
|
162
|
+
return this.#tail;
|
|
163
|
+
return this.#enqueue();
|
|
164
|
+
}
|
|
165
|
+
#enqueue() {
|
|
166
|
+
const run = this.#tail.then(() => this.#write());
|
|
167
|
+
this.#tail = run.catch(() => undefined);
|
|
168
|
+
return run.catch(() => undefined);
|
|
169
|
+
}
|
|
170
|
+
async #write() {
|
|
171
|
+
if (!this.#dirty)
|
|
172
|
+
return;
|
|
173
|
+
this.#dirty = false;
|
|
174
|
+
try {
|
|
175
|
+
const document = this.#prune(this.#document);
|
|
176
|
+
const stages = [...document.stages];
|
|
177
|
+
// Byte eviction is by oldest stage first: the index keeps every reusable topic, while a
|
|
178
|
+
// day-old model reply is the cheapest thing to lose.
|
|
179
|
+
let text = JSON.stringify({ ...document, stages });
|
|
180
|
+
while (Buffer.byteLength(text) > MAX_WRITE_BYTES && stages.length) {
|
|
181
|
+
stages.shift();
|
|
182
|
+
text = JSON.stringify({ ...document, stages });
|
|
183
|
+
}
|
|
184
|
+
if (Buffer.byteLength(text) > MAX_WRITE_BYTES)
|
|
185
|
+
return;
|
|
186
|
+
await this.#store.write({ ...document, stages });
|
|
187
|
+
}
|
|
188
|
+
catch { /* the cache is optional; generation must not fail because the index could not be persisted */ }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=timeline-cache.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const TIMELINE_DUPLICATE_THRESHOLD = 0.35;
|
|
2
|
+
const normalized = (title) => title.replace(/[\s,。、::;()()“”"'·\-—]+/gu, '');
|
|
3
|
+
const grams = (title) => { const text = normalized(title), out = new Set(); for (let i = 0; i < text.length - 1; i++)
|
|
4
|
+
out.add(text.slice(i, i + 2)); return out; };
|
|
5
|
+
export function titleSimilarity(a, b) {
|
|
6
|
+
const left = grams(a), right = grams(b);
|
|
7
|
+
if (!left.size || !right.size)
|
|
8
|
+
return normalized(a) === normalized(b) && normalized(a) !== '' ? 1 : 0;
|
|
9
|
+
let shared = 0;
|
|
10
|
+
for (const gram of left)
|
|
11
|
+
if (right.has(gram))
|
|
12
|
+
shared++;
|
|
13
|
+
return shared / (left.size + right.size - shared);
|
|
14
|
+
}
|
|
15
|
+
/** Greedy leader clustering: the strongest card leads, later cards join the first leader they duplicate. Output keeps input order of the leaders. */
|
|
16
|
+
export function clusterCards(cards, threshold = TIMELINE_DUPLICATE_THRESHOLD) {
|
|
17
|
+
const rank = cards.map((card, index) => ({ card, index })).sort((a, b) => Number(!!b.card.prior_id) - Number(!!a.card.prior_id)
|
|
18
|
+
|| (b.card.time?.as_of ?? '').localeCompare(a.card.time?.as_of ?? '')
|
|
19
|
+
|| b.card.facts.length - a.card.facts.length || b.card.refs.length - a.card.refs.length || a.index - b.index);
|
|
20
|
+
const clusters = [];
|
|
21
|
+
for (const { card, index } of rank) {
|
|
22
|
+
const home = card.prior_id ? undefined : clusters.find(cluster => card.refs.some(ref => cluster.refs.has(ref)) && titleSimilarity(card.title, cluster.leader.title) >= threshold);
|
|
23
|
+
if (home)
|
|
24
|
+
home.members.push(card);
|
|
25
|
+
else
|
|
26
|
+
clusters.push({ leader: card, index, members: [], refs: new Set(card.refs) });
|
|
27
|
+
}
|
|
28
|
+
return clusters.sort((a, b) => a.index - b.index).map(cluster => ({ leader: cluster.leader, members: cluster.members }));
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=timeline-cluster.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { interleave } from './sampling.js';
|
|
3
|
+
import { digestEligible } from './context-candidates.js';
|
|
4
|
+
/** Use Profile's authorized document pool and stated memories; retain original dates. */
|
|
5
|
+
export function timelineContextInputs(files, memories, retainedIds = []) {
|
|
6
|
+
const groups = new Map();
|
|
7
|
+
for (const entry of [...files].sort((a, b) => ('mtime_ms' in b ? b.mtime_ms : 0) - ('mtime_ms' in a ? a.mtime_ms : 0))) {
|
|
8
|
+
if (!('kind' in entry) || entry.kind !== 'file' || !digestEligible(entry))
|
|
9
|
+
continue;
|
|
10
|
+
const group = 'project:' + createHash('sha256').update(entry.root).digest('hex'), rows = groups.get(group) ?? [];
|
|
11
|
+
rows.push({ id: entry.id, version: String(entry.version), kind: 'file', group, text: entry.content, observed_at: new Date(entry.mtime_ms).toISOString(), source: { evidence_id: entry.id, type: 'file', label: entry.rel_path.split(/[\\/]/u).at(-1).slice(0, 120), observed_at: new Date(entry.mtime_ms).toISOString() } });
|
|
12
|
+
groups.set(group, rows);
|
|
13
|
+
}
|
|
14
|
+
const selected = interleave(groups.values(), 128), ids = new Set(selected.map(input => input.id)), retained = new Set(retainedIds), historical = [...groups.values()].flat().filter(input => retained.has(input.id) && !ids.has(input.id)).map(input => ({ ...input, history_only: true }));
|
|
15
|
+
return [...memories.map(entry => ({ id: 'memory:' + entry.id, version: String(entry.version), kind: 'memory', text: entry.content, observed_at: entry.observed_at, evidence_refs: entry.evidence_refs ?? [], ...(entry.sources?.[0] ? { source: entry.sources[0] } : {}) })), ...selected, ...historical];
|
|
16
|
+
}
|
|
17
|
+
/** Keep the two-week message pool intact; model requests are bounded in the writer. */
|
|
18
|
+
export function selectTimelineInputs(inputs) {
|
|
19
|
+
const groups = new Map(), seen = new Set();
|
|
20
|
+
for (const input of inputs) {
|
|
21
|
+
if (seen.has(input.id))
|
|
22
|
+
continue;
|
|
23
|
+
seen.add(input.id);
|
|
24
|
+
const key = input.group ?? input.kind, rows = groups.get(key) ?? [];
|
|
25
|
+
rows.push({ ...input, text: input.text.slice(0, 4000) });
|
|
26
|
+
groups.set(key, rows);
|
|
27
|
+
}
|
|
28
|
+
return interleave(groups.values(), 5200);
|
|
29
|
+
}
|
|
30
|
+
/** Each input is inspected in exactly one bounded screening request. */
|
|
31
|
+
export function timelineBatches(inputs) {
|
|
32
|
+
const batches = [];
|
|
33
|
+
let batch = [], size = 0;
|
|
34
|
+
for (const input of inputs) {
|
|
35
|
+
if (batch.length && (size + input.text.length > 60000 || batch.length >= 200)) {
|
|
36
|
+
batches.push(batch);
|
|
37
|
+
batch = [];
|
|
38
|
+
size = 0;
|
|
39
|
+
}
|
|
40
|
+
batch.push(input);
|
|
41
|
+
size += input.text.length;
|
|
42
|
+
}
|
|
43
|
+
if (batch.length)
|
|
44
|
+
batches.push(batch);
|
|
45
|
+
return batches;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=timeline-inputs.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const date = z.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
3
|
+
export const temporalSchema = z.object({ kind: z.enum(['event', 'ongoing', 'deadline', 'scheduled', 'synthesis', 'background', 'unknown']), dates: z.array(z.object({ role: z.enum(['occurred', 'started', 'deadline', 'scheduled']), date, ref: z.string().min(1).max(600), quote: z.string().min(1).max(600) }).strict()).max(3) }).strict();
|
|
4
|
+
export const resolvedTimeSchema = z.object({ kind: temporalSchema.shape.kind, anchor_date: date.nullable(), anchor_basis: z.enum(['occurred', 'deadline', 'scheduled', 'reported', 'unknown']), occurred_on: date.nullable(), started_on: date.nullable(), due_on: date.nullable(), scheduled_on: date.nullable(), last_reported_on: date.nullable(), evidence_from: date.nullable(), evidence_to: date.nullable(), as_of: date });
|
|
5
|
+
/** Use the saved as-of day so persisted cards keep stable placement. */
|
|
6
|
+
export function effectiveTimelineAnchor(time) {
|
|
7
|
+
const planned = time.anchor_basis === 'deadline' ? time.due_on : time.anchor_basis === 'scheduled' ? time.scheduled_on : null;
|
|
8
|
+
if (planned && planned > time.as_of)
|
|
9
|
+
return { anchor_date: time.last_reported_on ?? time.as_of, anchor_basis: 'reported' };
|
|
10
|
+
return { anchor_date: time.anchor_date, anchor_basis: time.anchor_basis };
|
|
11
|
+
}
|
|
12
|
+
const validDate = (value) => /^\d{4}-\d{2}-\d{2}$/u.test(value) && Number.isFinite(Date.parse(value)) && new Date(value + 'T00:00:00Z').toISOString().slice(0, 10) === value;
|
|
13
|
+
const reportedDate = (input, timezone) => ['im', 'mail'].includes(input.kind) && Number.isFinite(Date.parse(input.observed_at)) ? new Date(input.observed_at).toLocaleDateString('en-CA', { timeZone: timezone }) : null;
|
|
14
|
+
const shift = (day, offset) => new Date(Date.parse(day + 'T00:00:00Z') + offset * 86400000).toISOString().slice(0, 10);
|
|
15
|
+
// Extract only calendar expressions actually present in the exact cited span.
|
|
16
|
+
// File modification/collection timestamps never resolve relative dates.
|
|
17
|
+
function supportsDate(claim, input, timezone) {
|
|
18
|
+
if (!input.text.includes(claim.quote) || !validDate(claim.date))
|
|
19
|
+
return false;
|
|
20
|
+
const reported = reportedDate(input, timezone), dates = new Set();
|
|
21
|
+
for (const match of claim.quote.matchAll(/(?<!\d)(?:(\d{4})[-/年])?(\d{1,2})[-/月](\d{1,2})(?:日)?(?!\d)/gu)) {
|
|
22
|
+
const year = match[1] ?? reported?.slice(0, 4);
|
|
23
|
+
if (year)
|
|
24
|
+
dates.add(`${year}-${match[2].padStart(2, '0')}-${match[3].padStart(2, '0')}`);
|
|
25
|
+
}
|
|
26
|
+
if (reported)
|
|
27
|
+
for (const [word, offset] of [['前天', -2], ['昨天', -1], ['今天', 0], ['今日', 0], ['明天', 1], ['后天', 2]])
|
|
28
|
+
if (claim.quote.includes(word))
|
|
29
|
+
dates.add(shift(reported, offset));
|
|
30
|
+
return dates.has(claim.date);
|
|
31
|
+
}
|
|
32
|
+
export function resolveTimelineTime(temporal, inputs, context) {
|
|
33
|
+
if (temporal.kind === 'background')
|
|
34
|
+
return null;
|
|
35
|
+
const roles = new Map();
|
|
36
|
+
for (const claim of temporal.dates) {
|
|
37
|
+
const input = inputs.find(input => input.id === claim.ref);
|
|
38
|
+
if (!input)
|
|
39
|
+
return null;
|
|
40
|
+
// A message's own date can ground a report, but cannot prove when its subject occurred.
|
|
41
|
+
// Keep grounded content when the model redundantly copies that metadata into occurred.
|
|
42
|
+
if (claim.role === 'occurred' && claim.date === reportedDate(input, context.timezone) && input.text.includes(claim.quote) && !/(?:\d{1,4}[-/年月]\d{1,2}|前天|昨天|今天|今日|明天|后天)/u.test(claim.quote))
|
|
43
|
+
continue;
|
|
44
|
+
if (roles.has(claim.role) || !supportsDate(claim, input, context.timezone) || ['occurred', 'started'].includes(claim.role) && claim.date > context.local_date)
|
|
45
|
+
return null;
|
|
46
|
+
roles.set(claim.role, claim.date);
|
|
47
|
+
}
|
|
48
|
+
const occurred_on = roles.get('occurred') ?? null, started_on = roles.get('started') ?? null, due_on = roles.get('deadline') ?? null, scheduled_on = roles.get('scheduled') ?? null;
|
|
49
|
+
const observed = inputs.flatMap(input => { const day = reportedDate(input, context.timezone); return day && day <= context.local_date ? [day] : []; }).sort();
|
|
50
|
+
const evidence_from = observed[0] ?? null, last_reported_on = observed.at(-1) ?? null;
|
|
51
|
+
if (started_on && (occurred_on && started_on > occurred_on || last_reported_on && started_on > last_reported_on))
|
|
52
|
+
return null;
|
|
53
|
+
if (temporal.kind === 'deadline' && !due_on || temporal.kind === 'scheduled' && !scheduled_on)
|
|
54
|
+
return null;
|
|
55
|
+
const anchor_basis = temporal.kind === 'unknown' ? 'unknown' : temporal.kind === 'deadline' ? 'deadline' : temporal.kind === 'scheduled' ? 'scheduled' : temporal.kind === 'event' && occurred_on ? 'occurred' : last_reported_on ? 'reported' : occurred_on ? 'occurred' : 'unknown';
|
|
56
|
+
const anchor_date = anchor_basis === 'deadline' ? due_on : anchor_basis === 'scheduled' ? scheduled_on : anchor_basis === 'occurred' ? occurred_on : anchor_basis === 'reported' ? last_reported_on : null;
|
|
57
|
+
const time = { kind: temporal.kind, anchor_date, anchor_basis, occurred_on, started_on, due_on, scheduled_on, last_reported_on, evidence_from, evidence_to: last_reported_on, as_of: context.local_date };
|
|
58
|
+
return { ...time, ...effectiveTimelineAnchor(time) };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=timeline-time.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { profileDraftSchema } from './profile-warmup.js';
|
|
4
|
+
const ref = profileDraftSchema.shape.work.unwrap().element.shape.refs;
|
|
5
|
+
export const projectUnderstandingSchema = z.object({ id: z.string().max(128), name: z.string().min(1).max(120), relation: z.enum(['participating', 'reference', 'uncertain']), status: z.enum(['current', 'historical', 'uncertain']), summary: z.string().max(500), as_of: z.string().nullable(), refs: ref }).strict();
|
|
6
|
+
export const actionSuggestionSchema = z.object({ id: z.string().max(128), kind: z.enum(['action', 'progress', 'idea', 'goal']), title: z.string().min(1).max(200), body: z.string().max(1000), project_id: z.string().nullable(), source_key: z.string().optional(), todo_id: z.string().nullable(), due: z.string().date().nullable(), date_evidence: z.object({ entry_id: z.string(), quote: z.string().max(80) }).nullable().optional(), anchor: z.object({ entry_id: z.string(), quote: z.string().max(160) }).nullable().optional(), refs: ref }).strict();
|
|
7
|
+
export const understandingProductsSchema = z.object({ projects: z.array(projectUnderstandingSchema).max(24), suggestions: z.array(actionSuggestionSchema).max(24) }).strict();
|
|
8
|
+
export const projectCorrectionSchema = z.enum(['participating', 'historical', 'reference', 'automatic']);
|
|
9
|
+
export const emptyUnderstanding = () => ({ revision: 0, draft: null, generated_at: null, projects: [], suggestions: [], sources: [], corrections: {} });
|
|
10
|
+
const eventTime = (entry) => entry && (!entry.source || entry.source.kind || entry.source.project === 'Conversation') ? entry.observed_at : undefined;
|
|
11
|
+
const identity = (text) => createHash('sha256').update(text).digest('hex').slice(0, 32);
|
|
12
|
+
function evidenceDate(quote, at, timezone) {
|
|
13
|
+
if (/^\d{4}-\d{2}-\d{2}$/u.test(quote))
|
|
14
|
+
return z.string().date().safeParse(quote).success ? quote : null;
|
|
15
|
+
if (!at || !Number.isFinite(Date.parse(at)))
|
|
16
|
+
return null;
|
|
17
|
+
const date = new Intl.DateTimeFormat('en-CA', { timeZone: timezone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date(at)), base = new Date(date + 'T12:00:00Z');
|
|
18
|
+
const offset = { '今天': 0, '明天': 1, '后天': 2, today: 0, tomorrow: 1 };
|
|
19
|
+
let days = Object.hasOwn(offset, quote.toLowerCase()) ? offset[quote.toLowerCase()] : undefined;
|
|
20
|
+
const week = /^下周([一二三四五六日天])$/u.exec(quote);
|
|
21
|
+
if (week)
|
|
22
|
+
days = 7 - ((base.getUTCDay() + 6) % 7) + '一二三四五六日'.indexOf(week[1] === '天' ? '日' : week[1]);
|
|
23
|
+
if (days === undefined)
|
|
24
|
+
return null;
|
|
25
|
+
base.setUTCDate(base.getUTCDate() + days);
|
|
26
|
+
return base.toISOString().slice(0, 10);
|
|
27
|
+
}
|
|
28
|
+
/** Validate model references and dates; words alone never authorize a Life mutation. */
|
|
29
|
+
export function validateProducts(raw, entries, projectIds, corrections, timezone, previous = { projects: [], suggestions: [] }, identities = [], todos = []) {
|
|
30
|
+
const value = understandingProductsSchema.parse(raw), valid = (refs) => refs.every(r => entries.some(e => e.id === r.entry_id && e.version === r.version));
|
|
31
|
+
const nonGit = (p) => p.refs.every(r => entries.find(e => e.id === r.entry_id)?.source?.project === 'Conversation' || entries.find(e => e.id === r.entry_id)?.source?.kind) && p.refs.some(r => entries.find(e => e.id === r.entry_id)?.content.normalize('NFKC').toLowerCase().includes(p.name.normalize('NFKC').toLowerCase()));
|
|
32
|
+
const canonical = (p) => !projectIds.includes(p.id) && nonGit(p) ? identity('project:' + p.name.normalize('NFKC').trim().toLowerCase()) : p.id;
|
|
33
|
+
const proposals = value.projects.map(p => ({ ...p, id: canonical(p) })), allowedIds = value.projects.filter(nonGit).map(canonical), aliases = new Map(value.projects.filter(p => p.id !== '' || value.projects.length === 1).map(p => [p.id, canonical(p)]));
|
|
34
|
+
const projects = proposals.filter(p => (projectIds.includes(p.id) || allowedIds.includes(p.id)) && valid(p.refs)).map(p => ({ ...p, id: p.id || identity('project:' + p.name.normalize('NFKC').trim().toLowerCase()), ...(corrections[p.id] === 'reference' ? { relation: 'reference' } : corrections[p.id] === 'historical' ? { status: 'historical' } : corrections[p.id] === 'participating' ? { relation: 'participating', status: 'current' } : {}), as_of: p.refs.map(r => eventTime(entries.find(e => e.id === r.entry_id))).filter((at) => !!at).sort().at(-1) ?? null }));
|
|
35
|
+
const quotedAnchor = (item) => item.anchor?.quote.trim() ? entries.find(entry => entry.id === item.anchor.entry_id && item.refs.some(ref => ref.entry_id === entry.id && ref.version === entry.version) && entry.content.includes(item.anchor.quote)) : undefined;
|
|
36
|
+
const suggestions = value.suggestions.map(item => ({ ...item, project_id: item.project_id === null ? null : aliases.get(item.project_id) ?? item.project_id })).filter(item => (!item.todo_id || todos.some(todo => todo.id === item.todo_id)) && (item.kind !== 'progress' || !!item.todo_id) && valid(item.refs) && (!['action', 'progress'].includes(item.kind) || !!quotedAnchor(item)) && (!item.project_id || projects.some(p => p.id === item.project_id && p.relation === 'participating' && p.status === 'current'))).map(item => {
|
|
37
|
+
const first = entries.find(e => e.id === item.refs[0]?.entry_id), date = item.date_evidence, source = date && entries.find(e => e.id === date.entry_id && item.refs.some(r => r.entry_id === e.id)), anchor = quotedAnchor(item), identitySource = anchor ?? first, sourceKey = identitySource.identity_key ?? JSON.stringify(identitySource.source ?? identitySource.id);
|
|
38
|
+
const prior = [...previous.suggestions, ...identities].find(p => p.id === item.id && p.kind === item.kind && p.project_id === item.project_id && (p.source_key === sourceKey || ('refs' in p && p.refs.some(r => entries.some(e => e.id === r.entry_id && item.refs.some(n => n.entry_id === e.id))))));
|
|
39
|
+
const stable = identity(JSON.stringify([item.project_id ?? sourceKey, item.kind, anchor ? item.anchor.quote.normalize('NFKC').trim() : first.source?.document ?? first.id]));
|
|
40
|
+
return { ...item, source_key: sourceKey, id: prior?.id ?? stable, due: date && source?.content.includes(date.quote) ? evidenceDate(date.quote, eventTime(source), timezone) : null };
|
|
41
|
+
});
|
|
42
|
+
return { projects: [...new Map(projects.map(p => [p.id, p])).values()], suggestions: [...new Map(suggestions.map(item => [item.id, item])).values()] };
|
|
43
|
+
}
|
|
44
|
+
/** Carry host-derived channel metadata through presentation and confirmed adoption. */
|
|
45
|
+
export function understandingSourceTags(refs, sources) {
|
|
46
|
+
return refs.flatMap(ref => { const source = sources.find(item => item.id === ref.entry_id); if (!source?.type)
|
|
47
|
+
return []; return [{ evidence_id: ref.entry_id, type: source.type, label: source.label.slice(0, 120), observed_at: source.observed_at, ...(source.provider ? { provider: source.provider } : {}), ...(source.url ? { url: source.url } : {}) }]; });
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=understanding-products.js.map
|
|
@@ -12,11 +12,9 @@ export class PersonalUnderstanding {
|
|
|
12
12
|
#seen = new Set();
|
|
13
13
|
#accepted = new Set();
|
|
14
14
|
#dismissed = new Set();
|
|
15
|
-
#recorded = [];
|
|
16
15
|
constructor(options) {
|
|
17
16
|
this.options = options;
|
|
18
17
|
}
|
|
19
|
-
#scope() { return this.options.scope?.() ?? this.options.source()?.id ?? null; }
|
|
20
18
|
#current(source) { return JSON.stringify(source) === JSON.stringify(this.options.source()); }
|
|
21
19
|
async #resolve(row, signal, guard) {
|
|
22
20
|
guard();
|
|
@@ -31,9 +29,9 @@ export class PersonalUnderstanding {
|
|
|
31
29
|
const text = row.candidate.text;
|
|
32
30
|
if (row.candidate.kind === 'profile')
|
|
33
31
|
throw Error('candidate_kind_mismatch');
|
|
34
|
-
return { input: { op: 'create', kind: row.candidate.kind, title: text.slice(0, 200), note: text.length > 200 ? text : ''
|
|
32
|
+
return { input: { op: 'create', kind: row.candidate.kind, title: text.slice(0, 200), note: text.length > 200 ? text : '' } };
|
|
35
33
|
}
|
|
36
|
-
snapshot() { const source = this.options.source(); return { available: !!this.options.pipeline, status: this.#status, error: this.#error,
|
|
34
|
+
snapshot() { const source = this.options.source(); return { available: !!this.options.pipeline, status: this.#status, error: this.#error, items: this.#rows.filter(r => r.status === 'proposed' && r.decision.capture !== 'none' && !this.#accepted.has(r.candidate.id) && !this.#dismissed.has(r.candidate.id) && !!source && this.#current(r.source)).map(r => ({ id: r.candidate.id, kind: r.candidate.kind, text: r.candidate.text, quote: r.candidate.span.quote, source_id: r.source.id, importance: r.decision.importance })) }; }
|
|
37
35
|
/** Called after durable host commits. Selection/replay invalidates but never starts extraction. */
|
|
38
36
|
observe(newMessage = false) { const source = this.options.source(), key = JSON.stringify(source); if (key !== this.#key) {
|
|
39
37
|
this.#abort.abort();
|
|
@@ -54,7 +52,7 @@ export class PersonalUnderstanding {
|
|
|
54
52
|
const source = this.options.source();
|
|
55
53
|
if (!source)
|
|
56
54
|
throw Error('no_user_message');
|
|
57
|
-
const controller = this.#abort
|
|
55
|
+
const controller = this.#abort;
|
|
58
56
|
this.#seen.add(JSON.stringify(source));
|
|
59
57
|
for (const key of [...this.#seen].slice(0, -256))
|
|
60
58
|
this.#seen.delete(key);
|
|
@@ -72,7 +70,7 @@ export class PersonalUnderstanding {
|
|
|
72
70
|
this.#rows = rows;
|
|
73
71
|
if (automatic)
|
|
74
72
|
for (const row of rows) {
|
|
75
|
-
if (row.status !== 'proposed' ||
|
|
73
|
+
if (row.status !== 'proposed' || row.candidate.operation !== 'update' || row.decision.capture !== 'explicit')
|
|
76
74
|
continue;
|
|
77
75
|
const guard = () => { signal.throwIfAborted(); const current = this.options.source(); if (!current)
|
|
78
76
|
throw Error('candidate_stale_source'); assertAcceptable(row, current); };
|
|
@@ -80,11 +78,7 @@ export class PersonalUnderstanding {
|
|
|
80
78
|
const resolved = await this.#resolve(row, signal, guard);
|
|
81
79
|
guard();
|
|
82
80
|
if (resolved.input !== null) {
|
|
83
|
-
|
|
84
|
-
if (resolved.input.op === 'create') {
|
|
85
|
-
this.#recorded.push({ id: row.candidate.id, object_id: result.id, version: result.version, text: row.candidate.text, scope });
|
|
86
|
-
this.#recorded = this.#recorded.slice(-20);
|
|
87
|
-
}
|
|
81
|
+
await this.options.life.mutate(resolved.input, 'candidate:' + row.candidate.id, guard, { type: 'explicit_candidate', row, ...(resolved.resolution ? { resolution: resolved.resolution } : {}) });
|
|
88
82
|
}
|
|
89
83
|
this.#accepted.add(row.candidate.id);
|
|
90
84
|
}
|
|
@@ -108,16 +102,7 @@ export class PersonalUnderstanding {
|
|
|
108
102
|
this.#run = run;
|
|
109
103
|
}
|
|
110
104
|
async action(raw) {
|
|
111
|
-
const p = z.object({ id: z.string(), action: z.enum(['accept', 'dismiss'
|
|
112
|
-
if (p.action === 'undo') {
|
|
113
|
-
const record = this.#recorded.find(r => r.id === p.id && r.scope === this.#scope());
|
|
114
|
-
if (!record)
|
|
115
|
-
throw Error('record_not_found');
|
|
116
|
-
await this.options.life.mutate({ op: 'undo_create', id: record.object_id, expected_version: record.version }, 'undo-candidate:' + p.id);
|
|
117
|
-
this.#recorded = this.#recorded.filter(r => r !== record);
|
|
118
|
-
this.options.changed();
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
105
|
+
const p = z.object({ id: z.string(), action: z.enum(['accept', 'dismiss']), text: z.string().trim().min(1).max(1000).optional(), expected_profile_version: z.number().int().optional() }).strict().parse(raw);
|
|
121
106
|
const row = this.#rows.find(r => r.candidate.id === p.id);
|
|
122
107
|
if (!row)
|
|
123
108
|
throw Error('candidate_not_found');
|
|
@@ -155,6 +140,6 @@ export class PersonalUnderstanding {
|
|
|
155
140
|
this.options.changed();
|
|
156
141
|
}
|
|
157
142
|
async close() { this.#abort.abort(); await this.#run; }
|
|
158
|
-
reopen() { this.#abort = new AbortController(); this.#rows = []; this.#
|
|
143
|
+
reopen() { this.#abort = new AbortController(); this.#rows = []; this.#status = 'idle'; this.#error = null; this.#key = ''; this.#seen.clear(); this.#accepted.clear(); this.#dismissed.clear(); }
|
|
159
144
|
}
|
|
160
145
|
//# sourceMappingURL=understanding.js.map
|
|
@@ -5,13 +5,12 @@ import { versionSchema } from './contracts.js';
|
|
|
5
5
|
import { digestEligible, selectContextCandidates } from './context-candidates.js';
|
|
6
6
|
const refSchema = z.object({ entry_id: z.string().min(1), version: versionSchema }).strict();
|
|
7
7
|
const line = (max) => z.string().trim().min(1).max(max).nullable().default(null);
|
|
8
|
-
/** A
|
|
9
|
-
export const contextCardSchema = z.object({ candidate_id: z.string().min(1).max(128), tab: z.enum(['
|
|
10
|
-
export const
|
|
11
|
-
export const contextCardsSchema = z.object({ recap: recapSchema.nullable().default(null), cards: z.array(contextCardSchema).max(9) }).strict();
|
|
8
|
+
/** A goal card names a state to reach, how to tell it is reached, and a first step; ideas leave why/next null. */
|
|
9
|
+
export const contextCardSchema = z.object({ candidate_id: z.string().min(1).max(128), tab: z.enum(['ideas', 'goals']), title: z.string().trim().min(1).max(80), body: z.string().trim().min(1).max(120), why: line(80), next: line(80), refs: z.array(refSchema).min(1).max(8) }).strict();
|
|
10
|
+
export const contextCardsSchema = z.object({ cards: z.array(contextCardSchema).max(9) }).strict();
|
|
12
11
|
const keyOf = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
13
12
|
const generationRevision = 'project-digest-v4';
|
|
14
|
-
const stateSchema = contextCardsSchema.extend({
|
|
13
|
+
const stateSchema = contextCardsSchema.extend({ card_sources: z.record(z.string().max(128), z.object({ root: z.string().max(512), entries: z.array(z.string().max(512)).max(64) }).strict()).default({}), version: z.literal(2), key: z.string(), automatic_call_times: z.array(z.number().int().nonnegative()).max(6).default([]), retry_key: z.string().default(''), retry_not_before: z.number().int().nonnegative().default(0), dismissed: z.array(z.string()).max(1000), legacyDismissed: z.array(z.object({ tab: z.string(), refs: z.array(refSchema) }).strict()).max(1000) });
|
|
15
14
|
const diskSchema = z.preprocess(value => {
|
|
16
15
|
// An earlier local build recorded only cited refs under card_basis; that is not complete provenance, so it is dropped rather than trusted.
|
|
17
16
|
if (value && typeof value === 'object' && 'card_basis' in value) {
|
|
@@ -25,9 +24,9 @@ const diskSchema = z.preprocess(value => {
|
|
|
25
24
|
const legacy = z.object({ cards: z.array(z.object({ tab: z.string(), title: z.string(), body: z.string(), refs: z.array(refSchema) }).passthrough()), dismissed: z.array(z.string()), key: z.string() }).safeParse(old);
|
|
26
25
|
if (!legacy.success)
|
|
27
26
|
return emptyState();
|
|
28
|
-
return { version: 2,
|
|
27
|
+
return { version: 2, cards: [], key: '', dismissed: [], legacyDismissed: legacy.data.cards.filter(card => legacy.data.dismissed.includes(keyOf(card))).map(card => ({ tab: card.tab, refs: card.refs })) };
|
|
29
28
|
}, stateSchema);
|
|
30
|
-
const emptyState = () => ({ version: 2,
|
|
29
|
+
const emptyState = () => ({ version: 2, card_sources: {}, cards: [], key: '', automatic_call_times: [], retry_key: '', retry_not_before: 0, dismissed: [], legacyDismissed: [] });
|
|
31
30
|
const sameRef = (a, b) => a.entry_id === b.entry_id && a.version === b.version;
|
|
32
31
|
const leaksRawText = (text) => /(?:^|[^\w.])\/[\w.-]+\/[\w.-]|\b[A-Za-z]:[\\/]|\\\\[\w.$-]+\\|~[\\/]|\b(?:source|file):[\w-]+|\b(?:src|config|docs|runtime|clients)\/[\w./-]+|\b[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\b|\b(?:api[_-]?key|access[_-]?token|secret|password)\s*[:=:]|\b[a-f\d]{40,}\b/iu.test(text);
|
|
33
32
|
const leaksRawField = (card) => leaksRawText([card.title, card.body, card.why ?? '', card.next ?? ''].join(' '));
|
|
@@ -35,6 +34,7 @@ const leaksRawField = (card) => leaksRawText([card.title, card.body, card.why ??
|
|
|
35
34
|
export class WorkbenchContext {
|
|
36
35
|
generate;
|
|
37
36
|
changed;
|
|
37
|
+
#deferGeneration = false;
|
|
38
38
|
#store;
|
|
39
39
|
#state = emptyState();
|
|
40
40
|
#inputs = [];
|
|
@@ -56,7 +56,7 @@ export class WorkbenchContext {
|
|
|
56
56
|
this.changed = changed;
|
|
57
57
|
this.#store = new BoundedJsonStore(path, diskSchema);
|
|
58
58
|
}
|
|
59
|
-
async open() { try {
|
|
59
|
+
async open({ deferGeneration = false } = {}) { this.#deferGeneration = deferGeneration; try {
|
|
60
60
|
this.#state = await this.#store.read(emptyState());
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
@@ -64,6 +64,8 @@ export class WorkbenchContext {
|
|
|
64
64
|
throw error;
|
|
65
65
|
this.#state = emptyState();
|
|
66
66
|
} this.#opened = true; this.#abort = new AbortController(); this.#firstChangeAt = null; this.#pendingKey = ''; this.#manualPending = false; }
|
|
67
|
+
startGeneration() { if (!this.#opened)
|
|
68
|
+
return; this.#deferGeneration = false; this.#schedule(); }
|
|
67
69
|
async close() { this.#opened = false; clearTimeout(this.#timer); this.#timer = undefined; this.#manualPending = false; this.#abort.abort(); await this.#run; await this.#tail; }
|
|
68
70
|
async clear() { const reopen = this.#opened; await this.close(); this.#inputs = []; this.#candidates = []; this.#digests = undefined; this.#digestsPending = 0; await this.#write(next => Object.assign(next, emptyState())); this.#abort = new AbortController(); this.#opened = reopen; this.#status = 'idle'; }
|
|
69
71
|
#candidate(card) { return this.#candidates.find(candidate => candidate.candidate_id === card.candidate_id && candidate.tab === card.tab && card.refs.every(ref => candidate.refs.some(allowed => sameRef(ref, allowed)))); }
|
|
@@ -83,17 +85,13 @@ export class WorkbenchContext {
|
|
|
83
85
|
return null;
|
|
84
86
|
return this.#candidates.find(candidate => candidate.root === basis.root && candidate.tab === card.tab)?.refs ?? null;
|
|
85
87
|
}
|
|
86
|
-
#recapGrounded(recap, candidates = this.#candidates) { return recap.refs.every(ref => candidates.some(c => c.tab === 'todos' && c.refs.some(allowed => sameRef(ref, allowed)))); }
|
|
87
|
-
/** Todo candidates a recap draws on; any of them changing or leaving retires the recap, even if its cited refs survive. */
|
|
88
|
-
#recapBasis(recap, candidates) { return candidates.filter(c => c.tab === 'todos' && c.refs.some(allowed => recap.refs.some(ref => sameRef(ref, allowed)))).map(c => c.candidate_id); }
|
|
89
|
-
#recapCurrent() { const basis = this.#state.recap_basis; return Boolean(this.#state.recap) && basis.length > 0 && basis.every(id => this.#candidates.some(c => c.tab === 'todos' && c.candidate_id === id)) && this.#recapGrounded(this.#state.recap); }
|
|
90
88
|
#emptyReason(tab, cards) { if (cards)
|
|
91
89
|
return null; if (!this.#candidates.some(c => c.tab === tab))
|
|
92
90
|
return tab !== 'ideas' && this.#digestsPending ? 'digests_pending' : 'no_eligible_sources'; return this.#status === 'ready' ? 'model_abstained' : this.#status === 'failed' ? 'generation_failed' : null; }
|
|
93
91
|
#key() { return keyOf([generationRevision, this.#candidates.map(candidate => [candidate.candidate_id, candidate.version])]); }
|
|
94
92
|
/** Active own projects, one line each, straight from their digests; no model call. */
|
|
95
93
|
#projects() { return (this.#digests ?? []).filter(d => d.role === 'own').slice(0, 4).map(d => ({ name: d.name, line: d.focus ?? d.summary })).filter(p => !leaksRawText(p.name + ' ' + p.line)); }
|
|
96
|
-
|
|
94
|
+
sourcesForRefs(refs) {
|
|
97
95
|
const sources = refs.flatMap(ref => {
|
|
98
96
|
const input = this.#inputs.find(input => input.id === ref.entry_id && input.version === ref.version);
|
|
99
97
|
if (!input)
|
|
@@ -106,9 +104,9 @@ export class WorkbenchContext {
|
|
|
106
104
|
return structuredClone([...new Map(sources.map(source => [JSON.stringify(source), source])).values()]);
|
|
107
105
|
}
|
|
108
106
|
snapshot() {
|
|
109
|
-
const
|
|
110
|
-
const empty_reasons = {
|
|
111
|
-
return { status: this.#status, candidate_count: this.#candidates.length, recap: { text:
|
|
107
|
+
const cards = this.#state.cards.flatMap(card => { const refs = this.#shownRefs(card); return refs && !this.#state.dismissed.includes(card.candidate_id) ? [{ card, refs }] : []; }).map(({ card, refs }) => ({ ...structuredClone(card), id: card.candidate_id, sources: this.sourcesForRefs(refs), refs: refs.map(ref => ({ ...ref, label: this.#inputs.find(input => input.id === ref.entry_id)?.content.slice(0, 700) ?? '来源内容不可用' })) }));
|
|
108
|
+
const empty_reasons = { ideas: this.#emptyReason('ideas', cards.filter(card => card.tab === 'ideas').length), goals: this.#emptyReason('goals', cards.filter(card => card.tab === 'goals').length) };
|
|
109
|
+
return { status: this.#status, candidate_count: this.#candidates.length, recap: { text: null, projects: this.#projects() }, empty_reason: this.#candidates.length === 0 ? this.#digestsPending ? 'digests_pending' : 'no_eligible_sources' : cards.length === 0 && this.#status === 'ready' ? 'model_abstained' : cards.length === 0 && this.#status === 'failed' ? 'generation_failed' : null, empty_reasons, cards };
|
|
112
110
|
}
|
|
113
111
|
#write(fn) { const run = this.#tail.then(async () => { const next = structuredClone(this.#state); fn(next); await this.#store.write(next); this.#state = next; this.changed(); }); this.#tail = run.catch(() => undefined); return run; }
|
|
114
112
|
dismiss(id) { if (!this.#state.cards.some(card => card.candidate_id === id))
|
|
@@ -161,7 +159,7 @@ export class WorkbenchContext {
|
|
|
161
159
|
#schedule() {
|
|
162
160
|
clearTimeout(this.#timer);
|
|
163
161
|
this.#timer = undefined;
|
|
164
|
-
if (!this.#opened || !this.generate || this.#run || !this.#candidates.length || this.#key() === this.#state.key || this.#firstChangeAt === null)
|
|
162
|
+
if (this.#deferGeneration || !this.#opened || !this.generate || this.#run || !this.#candidates.length || this.#key() === this.#state.key || this.#firstChangeAt === null)
|
|
165
163
|
return;
|
|
166
164
|
const now = Date.now(), recent = this.#state.automatic_call_times.filter(at => at > now - 3_600_000), first = this.#state.automatic_call_times.length === 0 && this.#state.key === '';
|
|
167
165
|
const due = Math.min(this.#firstChangeAt + (first ? 10_000 : 120_000), this.#lastChangeAt + (first ? 3_000 : 30_000));
|
|
@@ -175,7 +173,7 @@ export class WorkbenchContext {
|
|
|
175
173
|
return this.#run;
|
|
176
174
|
} await this.#generate(false); }
|
|
177
175
|
async #generate(automatic) {
|
|
178
|
-
if (!this.#opened || !this.generate || this.#run || !this.#candidates.length)
|
|
176
|
+
if (this.#deferGeneration || !this.#opened || !this.generate || this.#run || !this.#candidates.length)
|
|
179
177
|
return;
|
|
180
178
|
clearTimeout(this.#timer);
|
|
181
179
|
this.#timer = undefined;
|
|
@@ -200,10 +198,8 @@ export class WorkbenchContext {
|
|
|
200
198
|
const seen = new Set();
|
|
201
199
|
const cards = result.cards.filter(card => { if (seen.has(card.candidate_id) || leaksRawField(card) || !this.#candidate(card) || !card.refs.every(ref => candidates.some(candidate => candidate.candidate_id === card.candidate_id && candidate.refs.some(allowed => sameRef(ref, allowed)))))
|
|
202
200
|
return false; seen.add(card.candidate_id); return true; });
|
|
203
|
-
const basis = result.recap ? this.#recapBasis(result.recap, candidates) : [];
|
|
204
|
-
const recap = result.recap && basis.length && !leaksRawText(result.recap.text) && this.#recapGrounded(result.recap, candidates) ? result.recap : null;
|
|
205
201
|
const cardBasis = Object.fromEntries(cards.map(card => { const candidate = candidates.find(c => c.candidate_id === card.candidate_id); return [card.candidate_id, { root: candidate.root, entries: [...(candidate.sources ?? new Set(candidate.refs.map(ref => ref.entry_id)))] }]; }));
|
|
206
|
-
await this.#write(next => { next.
|
|
202
|
+
await this.#write(next => { next.card_sources = cardBasis; next.cards = cards; next.key = key; next.retry_key = ''; next.retry_not_before = 0; });
|
|
207
203
|
this.#status = 'ready';
|
|
208
204
|
}
|
|
209
205
|
catch (error) {
|