pinecall 0.1.0
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 +202 -0
- package/README.md +134 -0
- package/dist/agent/accepts.d.ts +32 -0
- package/dist/agent/accepts.d.ts.map +1 -0
- package/dist/agent/accepts.js +28 -0
- package/dist/agent/accepts.js.map +1 -0
- package/dist/agent/agent.d.ts +189 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +262 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/authors.d.ts +12 -0
- package/dist/agent/authors.d.ts.map +1 -0
- package/dist/agent/authors.js +28 -0
- package/dist/agent/authors.js.map +1 -0
- package/dist/agent/decorators.d.ts +22 -0
- package/dist/agent/decorators.d.ts.map +1 -0
- package/dist/agent/decorators.js +49 -0
- package/dist/agent/decorators.js.map +1 -0
- package/dist/agent/docstrings.d.ts +43 -0
- package/dist/agent/docstrings.d.ts.map +1 -0
- package/dist/agent/docstrings.js +311 -0
- package/dist/agent/docstrings.js.map +1 -0
- package/dist/agent/lifecycle.d.ts +29 -0
- package/dist/agent/lifecycle.d.ts.map +1 -0
- package/dist/agent/lifecycle.js +11 -0
- package/dist/agent/lifecycle.js.map +1 -0
- package/dist/agent/stages.d.ts +28 -0
- package/dist/agent/stages.d.ts.map +1 -0
- package/dist/agent/stages.js +32 -0
- package/dist/agent/stages.js.map +1 -0
- package/dist/agent/state.d.ts +43 -0
- package/dist/agent/state.d.ts.map +1 -0
- package/dist/agent/state.js +104 -0
- package/dist/agent/state.js.map +1 -0
- package/dist/agent/tools.d.ts +66 -0
- package/dist/agent/tools.d.ts.map +1 -0
- package/dist/agent/tools.js +148 -0
- package/dist/agent/tools.js.map +1 -0
- package/dist/agent/visibility.d.ts +40 -0
- package/dist/agent/visibility.d.ts.map +1 -0
- package/dist/agent/visibility.js +89 -0
- package/dist/agent/visibility.js.map +1 -0
- package/dist/call/call.d.ts +55 -0
- package/dist/call/call.d.ts.map +1 -0
- package/dist/call/call.js +108 -0
- package/dist/call/call.js.map +1 -0
- package/dist/call/history.d.ts +34 -0
- package/dist/call/history.d.ts.map +1 -0
- package/dist/call/history.js +38 -0
- package/dist/call/history.js.map +1 -0
- package/dist/call/room.d.ts +58 -0
- package/dist/call/room.d.ts.map +1 -0
- package/dist/call/room.js +68 -0
- package/dist/call/room.js.map +1 -0
- package/dist/cli/browser.d.ts +8 -0
- package/dist/cli/browser.d.ts.map +1 -0
- package/dist/cli/browser.js +27 -0
- package/dist/cli/browser.js.map +1 -0
- package/dist/cli/callbacks.d.ts +26 -0
- package/dist/cli/callbacks.d.ts.map +1 -0
- package/dist/cli/callbacks.js +68 -0
- package/dist/cli/callbacks.js.map +1 -0
- package/dist/cli/chat.d.ts +21 -0
- package/dist/cli/chat.d.ts.map +1 -0
- package/dist/cli/chat.js +214 -0
- package/dist/cli/chat.js.map +1 -0
- package/dist/cli/config.d.ts +16 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +94 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/connected.d.ts +30 -0
- package/dist/cli/connected.d.ts.map +1 -0
- package/dist/cli/connected.js +32 -0
- package/dist/cli/connected.js.map +1 -0
- package/dist/cli/credentials.d.ts +41 -0
- package/dist/cli/credentials.d.ts.map +1 -0
- package/dist/cli/credentials.js +98 -0
- package/dist/cli/credentials.js.map +1 -0
- package/dist/cli/ear.d.ts +3 -0
- package/dist/cli/ear.d.ts.map +1 -0
- package/dist/cli/ear.js +59 -0
- package/dist/cli/ear.js.map +1 -0
- package/dist/cli/env.d.ts +40 -0
- package/dist/cli/env.d.ts.map +1 -0
- package/dist/cli/env.js +45 -0
- package/dist/cli/env.js.map +1 -0
- package/dist/cli/eval.d.ts +37 -0
- package/dist/cli/eval.d.ts.map +1 -0
- package/dist/cli/eval.js +83 -0
- package/dist/cli/eval.js.map +1 -0
- package/dist/cli/groups.d.ts +17 -0
- package/dist/cli/groups.d.ts.map +1 -0
- package/dist/cli/groups.js +38 -0
- package/dist/cli/groups.js.map +1 -0
- package/dist/cli/index.d.ts +16 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +169 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/keys.d.ts +28 -0
- package/dist/cli/keys.d.ts.map +1 -0
- package/dist/cli/keys.js +137 -0
- package/dist/cli/keys.js.map +1 -0
- package/dist/cli/knowledge.d.ts +35 -0
- package/dist/cli/knowledge.d.ts.map +1 -0
- package/dist/cli/knowledge.js +174 -0
- package/dist/cli/knowledge.js.map +1 -0
- package/dist/cli/line.d.ts +33 -0
- package/dist/cli/line.d.ts.map +1 -0
- package/dist/cli/line.js +134 -0
- package/dist/cli/line.js.map +1 -0
- package/dist/cli/listening.d.ts +38 -0
- package/dist/cli/listening.d.ts.map +1 -0
- package/dist/cli/listening.js +124 -0
- package/dist/cli/listening.js.map +1 -0
- package/dist/cli/load.d.ts +38 -0
- package/dist/cli/load.d.ts.map +1 -0
- package/dist/cli/load.js +99 -0
- package/dist/cli/load.js.map +1 -0
- package/dist/cli/login.d.ts +30 -0
- package/dist/cli/login.d.ts.map +1 -0
- package/dist/cli/login.js +158 -0
- package/dist/cli/login.js.map +1 -0
- package/dist/cli/machine.d.ts +8 -0
- package/dist/cli/machine.d.ts.map +1 -0
- package/dist/cli/machine.js +41 -0
- package/dist/cli/machine.js.map +1 -0
- package/dist/cli/memory.d.ts +26 -0
- package/dist/cli/memory.d.ts.map +1 -0
- package/dist/cli/memory.js +148 -0
- package/dist/cli/memory.js.map +1 -0
- package/dist/cli/numbers.d.ts +25 -0
- package/dist/cli/numbers.d.ts.map +1 -0
- package/dist/cli/numbers.js +132 -0
- package/dist/cli/numbers.js.map +1 -0
- package/dist/cli/personas.d.ts +5 -0
- package/dist/cli/personas.d.ts.map +1 -0
- package/dist/cli/personas.js +94 -0
- package/dist/cli/personas.js.map +1 -0
- package/dist/cli/pipeline.d.ts +52 -0
- package/dist/cli/pipeline.d.ts.map +1 -0
- package/dist/cli/pipeline.js +184 -0
- package/dist/cli/pipeline.js.map +1 -0
- package/dist/cli/profiles.d.ts +70 -0
- package/dist/cli/profiles.d.ts.map +1 -0
- package/dist/cli/profiles.js +210 -0
- package/dist/cli/profiles.js.map +1 -0
- package/dist/cli/prompt.d.ts +20 -0
- package/dist/cli/prompt.d.ts.map +1 -0
- package/dist/cli/prompt.js +58 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/providers.d.ts +14 -0
- package/dist/cli/providers.d.ts.map +1 -0
- package/dist/cli/providers.js +116 -0
- package/dist/cli/providers.js.map +1 -0
- package/dist/cli/remember.d.ts +29 -0
- package/dist/cli/remember.d.ts.map +1 -0
- package/dist/cli/remember.js +112 -0
- package/dist/cli/remember.js.map +1 -0
- package/dist/cli/run.d.ts +20 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +347 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/runs/candidate.d.ts +51 -0
- package/dist/cli/runs/candidate.d.ts.map +1 -0
- package/dist/cli/runs/candidate.js +127 -0
- package/dist/cli/runs/candidate.js.map +1 -0
- package/dist/cli/runs/drift.d.ts +75 -0
- package/dist/cli/runs/drift.d.ts.map +1 -0
- package/dist/cli/runs/drift.js +151 -0
- package/dist/cli/runs/drift.js.map +1 -0
- package/dist/cli/runs/index.d.ts +5 -0
- package/dist/cli/runs/index.d.ts.map +1 -0
- package/dist/cli/runs/index.js +99 -0
- package/dist/cli/runs/index.js.map +1 -0
- package/dist/cli/runs/suites.d.ts +16 -0
- package/dist/cli/runs/suites.d.ts.map +1 -0
- package/dist/cli/runs/suites.js +63 -0
- package/dist/cli/runs/suites.js.map +1 -0
- package/dist/cli/secret.d.ts +18 -0
- package/dist/cli/secret.d.ts.map +1 -0
- package/dist/cli/secret.js +41 -0
- package/dist/cli/secret.js.map +1 -0
- package/dist/cli/sessions.d.ts +21 -0
- package/dist/cli/sessions.d.ts.map +1 -0
- package/dist/cli/sessions.js +174 -0
- package/dist/cli/sessions.js.map +1 -0
- package/dist/cli/signup.d.ts +25 -0
- package/dist/cli/signup.d.ts.map +1 -0
- package/dist/cli/signup.js +122 -0
- package/dist/cli/signup.js.map +1 -0
- package/dist/cli/simulate.d.ts +45 -0
- package/dist/cli/simulate.d.ts.map +1 -0
- package/dist/cli/simulate.js +320 -0
- package/dist/cli/simulate.js.map +1 -0
- package/dist/cli/supervise.d.ts +18 -0
- package/dist/cli/supervise.d.ts.map +1 -0
- package/dist/cli/supervise.js +134 -0
- package/dist/cli/supervise.js.map +1 -0
- package/dist/cli/test.d.ts +12 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +128 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/testing/caller.d.ts +28 -0
- package/dist/cli/testing/caller.d.ts.map +1 -0
- package/dist/cli/testing/caller.js +30 -0
- package/dist/cli/testing/caller.js.map +1 -0
- package/dist/cli/testing/gateway.d.ts +172 -0
- package/dist/cli/testing/gateway.d.ts.map +1 -0
- package/dist/cli/testing/gateway.js +96 -0
- package/dist/cli/testing/gateway.js.map +1 -0
- package/dist/cli/testing/goldens.d.ts +61 -0
- package/dist/cli/testing/goldens.d.ts.map +1 -0
- package/dist/cli/testing/goldens.js +54 -0
- package/dist/cli/testing/goldens.js.map +1 -0
- package/dist/cli/testing/latency.d.ts +15 -0
- package/dist/cli/testing/latency.d.ts.map +1 -0
- package/dist/cli/testing/latency.js +44 -0
- package/dist/cli/testing/latency.js.map +1 -0
- package/dist/cli/testing/matrix.d.ts +12 -0
- package/dist/cli/testing/matrix.d.ts.map +1 -0
- package/dist/cli/testing/matrix.js +103 -0
- package/dist/cli/testing/matrix.js.map +1 -0
- package/dist/cli/testing/progress.d.ts +26 -0
- package/dist/cli/testing/progress.d.ts.map +1 -0
- package/dist/cli/testing/progress.js +185 -0
- package/dist/cli/testing/progress.js.map +1 -0
- package/dist/cli/testing/reproduction.d.ts +19 -0
- package/dist/cli/testing/reproduction.d.ts.map +1 -0
- package/dist/cli/testing/reproduction.js +65 -0
- package/dist/cli/testing/reproduction.js.map +1 -0
- package/dist/cli/testing/score.d.ts +11 -0
- package/dist/cli/testing/score.d.ts.map +1 -0
- package/dist/cli/testing/score.js +54 -0
- package/dist/cli/testing/score.js.map +1 -0
- package/dist/cli/testing/seeding.d.ts +32 -0
- package/dist/cli/testing/seeding.d.ts.map +1 -0
- package/dist/cli/testing/seeding.js +44 -0
- package/dist/cli/testing/seeding.js.map +1 -0
- package/dist/cli/testing/suite.d.ts +40 -0
- package/dist/cli/testing/suite.d.ts.map +1 -0
- package/dist/cli/testing/suite.js +103 -0
- package/dist/cli/testing/suite.js.map +1 -0
- package/dist/cli/testing/voice.d.ts +37 -0
- package/dist/cli/testing/voice.d.ts.map +1 -0
- package/dist/cli/testing/voice.js +53 -0
- package/dist/cli/testing/voice.js.map +1 -0
- package/dist/cli/ui/admin/assets/index-C3WMXdfL.css +1 -0
- package/dist/cli/ui/admin/assets/index-DR1mxoAh.js +58 -0
- package/dist/cli/ui/admin/index.html +20 -0
- package/dist/cli/ui/asked.d.ts +16 -0
- package/dist/cli/ui/asked.d.ts.map +1 -0
- package/dist/cli/ui/asked.js +53 -0
- package/dist/cli/ui/asked.js.map +1 -0
- package/dist/cli/ui/browser.d.ts +10 -0
- package/dist/cli/ui/browser.d.ts.map +1 -0
- package/dist/cli/ui/browser.js +30 -0
- package/dist/cli/ui/browser.js.map +1 -0
- package/dist/cli/ui/chatting.d.ts +62 -0
- package/dist/cli/ui/chatting.d.ts.map +1 -0
- package/dist/cli/ui/chatting.js +171 -0
- package/dist/cli/ui/chatting.js.map +1 -0
- package/dist/cli/ui/console/assets/index-DCTnou52.css +1 -0
- package/dist/cli/ui/console/assets/index-dOcE4usU.js +99 -0
- package/dist/cli/ui/console/index.html +20 -0
- package/dist/cli/ui/console/logo-mark.png +0 -0
- package/dist/cli/ui/doors.d.ts +37 -0
- package/dist/cli/ui/doors.d.ts.map +1 -0
- package/dist/cli/ui/doors.js +70 -0
- package/dist/cli/ui/doors.js.map +1 -0
- package/dist/cli/ui/drifting.d.ts +23 -0
- package/dist/cli/ui/drifting.d.ts.map +1 -0
- package/dist/cli/ui/drifting.js +33 -0
- package/dist/cli/ui/drifting.js.map +1 -0
- package/dist/cli/ui/index.d.ts +15 -0
- package/dist/cli/ui/index.d.ts.map +1 -0
- package/dist/cli/ui/index.js +117 -0
- package/dist/cli/ui/index.js.map +1 -0
- package/dist/cli/ui/knowing.d.ts +36 -0
- package/dist/cli/ui/knowing.d.ts.map +1 -0
- package/dist/cli/ui/knowing.js +86 -0
- package/dist/cli/ui/knowing.js.map +1 -0
- package/dist/cli/ui/promoting.d.ts +26 -0
- package/dist/cli/ui/promoting.d.ts.map +1 -0
- package/dist/cli/ui/promoting.js +44 -0
- package/dist/cli/ui/promoting.js.map +1 -0
- package/dist/cli/ui/refusal.d.ts +18 -0
- package/dist/cli/ui/refusal.d.ts.map +1 -0
- package/dist/cli/ui/refusal.js +26 -0
- package/dist/cli/ui/refusal.js.map +1 -0
- package/dist/cli/ui/refused.d.ts +8 -0
- package/dist/cli/ui/refused.d.ts.map +1 -0
- package/dist/cli/ui/refused.js +11 -0
- package/dist/cli/ui/refused.js.map +1 -0
- package/dist/cli/ui/remembering.d.ts +38 -0
- package/dist/cli/ui/remembering.d.ts.map +1 -0
- package/dist/cli/ui/remembering.js +87 -0
- package/dist/cli/ui/remembering.js.map +1 -0
- package/dist/cli/ui/reproducing.d.ts +23 -0
- package/dist/cli/ui/reproducing.d.ts.map +1 -0
- package/dist/cli/ui/reproducing.js +52 -0
- package/dist/cli/ui/reproducing.js.map +1 -0
- package/dist/cli/ui/server.d.ts +22 -0
- package/dist/cli/ui/server.d.ts.map +1 -0
- package/dist/cli/ui/server.js +211 -0
- package/dist/cli/ui/server.js.map +1 -0
- package/dist/cli/ui/simulating.d.ts +47 -0
- package/dist/cli/ui/simulating.d.ts.map +1 -0
- package/dist/cli/ui/simulating.js +86 -0
- package/dist/cli/ui/simulating.js.map +1 -0
- package/dist/cli/ui/testing.d.ts +49 -0
- package/dist/cli/ui/testing.d.ts.map +1 -0
- package/dist/cli/ui/testing.js +104 -0
- package/dist/cli/ui/testing.js.map +1 -0
- package/dist/cli/view.d.ts +43 -0
- package/dist/cli/view.d.ts.map +1 -0
- package/dist/cli/view.js +137 -0
- package/dist/cli/view.js.map +1 -0
- package/dist/cli/whoami.d.ts +37 -0
- package/dist/cli/whoami.d.ts.map +1 -0
- package/dist/cli/whoami.js +78 -0
- package/dist/cli/whoami.js.map +1 -0
- package/dist/cli/world.d.ts +33 -0
- package/dist/cli/world.d.ts.map +1 -0
- package/dist/cli/world.js +48 -0
- package/dist/cli/world.js.map +1 -0
- package/dist/client/agent.d.ts +87 -0
- package/dist/client/agent.d.ts.map +1 -0
- package/dist/client/agent.js +209 -0
- package/dist/client/agent.js.map +1 -0
- package/dist/client/calls.d.ts +77 -0
- package/dist/client/calls.d.ts.map +1 -0
- package/dist/client/calls.js +153 -0
- package/dist/client/calls.js.map +1 -0
- package/dist/client/client.d.ts +58 -0
- package/dist/client/client.d.ts.map +1 -0
- package/dist/client/client.js +146 -0
- package/dist/client/client.js.map +1 -0
- package/dist/client/connection.d.ts +47 -0
- package/dist/client/connection.d.ts.map +1 -0
- package/dist/client/connection.js +141 -0
- package/dist/client/connection.js.map +1 -0
- package/dist/client/endpoints.d.ts +7 -0
- package/dist/client/endpoints.d.ts.map +1 -0
- package/dist/client/endpoints.js +21 -0
- package/dist/client/endpoints.js.map +1 -0
- package/dist/client/frames.d.ts +24 -0
- package/dist/client/frames.d.ts.map +1 -0
- package/dist/client/frames.js +49 -0
- package/dist/client/frames.js.map +1 -0
- package/dist/client/index.d.ts +15 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +14 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/listeners.d.ts +36 -0
- package/dist/client/listeners.d.ts.map +1 -0
- package/dist/client/listeners.js +61 -0
- package/dist/client/listeners.js.map +1 -0
- package/dist/client/observe.d.ts +44 -0
- package/dist/client/observe.d.ts.map +1 -0
- package/dist/client/observe.js +122 -0
- package/dist/client/observe.js.map +1 -0
- package/dist/client/testing/gateway.d.ts +39 -0
- package/dist/client/testing/gateway.d.ts.map +1 -0
- package/dist/client/testing/gateway.js +129 -0
- package/dist/client/testing/gateway.js.map +1 -0
- package/dist/client/testing/index.d.ts +4 -0
- package/dist/client/testing/index.d.ts.map +1 -0
- package/dist/client/testing/index.js +4 -0
- package/dist/client/testing/index.js.map +1 -0
- package/dist/client/testing/log.d.ts +26 -0
- package/dist/client/testing/log.d.ts.map +1 -0
- package/dist/client/testing/log.js +111 -0
- package/dist/client/testing/log.js.map +1 -0
- package/dist/client/testing/loopback.d.ts +3 -0
- package/dist/client/testing/loopback.d.ts.map +1 -0
- package/dist/client/testing/loopback.js +3 -0
- package/dist/client/testing/loopback.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/channels.d.ts +16 -0
- package/dist/runtime/channels.d.ts.map +1 -0
- package/dist/runtime/channels.js +30 -0
- package/dist/runtime/channels.js.map +1 -0
- package/dist/runtime/connect.d.ts +51 -0
- package/dist/runtime/connect.d.ts.map +1 -0
- package/dist/runtime/connect.js +284 -0
- package/dist/runtime/connect.js.map +1 -0
- package/dist/runtime/dispatch.d.ts +37 -0
- package/dist/runtime/dispatch.d.ts.map +1 -0
- package/dist/runtime/dispatch.js +52 -0
- package/dist/runtime/dispatch.js.map +1 -0
- package/dist/runtime/grounding.d.ts +15 -0
- package/dist/runtime/grounding.d.ts.map +1 -0
- package/dist/runtime/grounding.js +72 -0
- package/dist/runtime/grounding.js.map +1 -0
- package/dist/runtime/recall.d.ts +10 -0
- package/dist/runtime/recall.d.ts.map +1 -0
- package/dist/runtime/recall.js +13 -0
- package/dist/runtime/recall.js.map +1 -0
- package/dist/runtime/run-tool.d.ts +26 -0
- package/dist/runtime/run-tool.d.ts.map +1 -0
- package/dist/runtime/run-tool.js +82 -0
- package/dist/runtime/run-tool.js.map +1 -0
- package/dist/views/components.d.ts +17 -0
- package/dist/views/components.d.ts.map +1 -0
- package/dist/views/components.js +33 -0
- package/dist/views/components.js.map +1 -0
- package/dist/views/jsx-dev-runtime.d.ts +3 -0
- package/dist/views/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/views/jsx-dev-runtime.js +5 -0
- package/dist/views/jsx-dev-runtime.js.map +1 -0
- package/dist/views/jsx-runtime.d.ts +49 -0
- package/dist/views/jsx-runtime.d.ts.map +1 -0
- package/dist/views/jsx-runtime.js +67 -0
- package/dist/views/jsx-runtime.js.map +1 -0
- package/dist/views/lang.d.ts +17 -0
- package/dist/views/lang.d.ts.map +1 -0
- package/dist/views/lang.js +46 -0
- package/dist/views/lang.js.map +1 -0
- package/dist/views/layout.d.ts +19 -0
- package/dist/views/layout.d.ts.map +1 -0
- package/dist/views/layout.js +62 -0
- package/dist/views/layout.js.map +1 -0
- package/dist/views/render.d.ts +19 -0
- package/dist/views/render.d.ts.map +1 -0
- package/dist/views/render.js +26 -0
- package/dist/views/render.js.map +1 -0
- package/package.json +76 -0
- package/tsconfig.tenant.json +24 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** The tool registry: what a class declares, what the wire is sent, and what the state shows now. */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { ToolSpec } from "@pinecall/protocol";
|
|
4
|
+
import { type ParamDoc } from "./docstrings.js";
|
|
5
|
+
import type { StageOf } from "./stages.js";
|
|
6
|
+
import { type Snapshot } from "./state.js";
|
|
7
|
+
export type { ToolSpec };
|
|
8
|
+
export type SideEffect = NonNullable<ToolSpec["side_effect"]>;
|
|
9
|
+
/**
|
|
10
|
+
* Everything `@tool({...})` accepts, and nothing else. `T` is the class the decorator was written
|
|
11
|
+
* on — TypeScript infers it from the prototype the decorator is handed, so `when` gets the real
|
|
12
|
+
* state and `s.identified` is a boolean instead of `s["identified"]` being unknown.
|
|
13
|
+
*/
|
|
14
|
+
export interface ToolOptions<T = unknown> {
|
|
15
|
+
/** Visibility, and the only one there is: a question asked of the state, on every change. */
|
|
16
|
+
when?: (state: Snapshot<T>) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Visible while the state is in one of these stages — sugar the decorator lowers to the `when`
|
|
19
|
+
* above. The names are typed against the class's own `stage` field, so a misspelling is a
|
|
20
|
+
* compile error; with a `when` beside it, the tool is there where both hold.
|
|
21
|
+
*/
|
|
22
|
+
stage?: StageOf<T> | StageOf<T>[];
|
|
23
|
+
/** The read-back the agent says before running, `{{slot.when}}` filled from state and args. */
|
|
24
|
+
confirm?: string;
|
|
25
|
+
/** How many rows of a list result the model sees; the field itself keeps them all. */
|
|
26
|
+
preview?: number;
|
|
27
|
+
/** Parameter names that carry personal data, masked in the log by declaration. */
|
|
28
|
+
pii?: string[];
|
|
29
|
+
/** How long the platform waits for this method, in seconds. */
|
|
30
|
+
timeout?: number;
|
|
31
|
+
/** An explicit schema, when the signature's types are not enough. Optional, never required. */
|
|
32
|
+
params?: z.ZodObject;
|
|
33
|
+
}
|
|
34
|
+
export type ErasedToolOptions = ToolOptions<any>;
|
|
35
|
+
/** One declared tool: the wire's half, the halves the wire never sees, and the method itself. */
|
|
36
|
+
export interface ToolDeclaration {
|
|
37
|
+
name: string;
|
|
38
|
+
options: ErasedToolOptions;
|
|
39
|
+
method: (...args: unknown[]) => unknown;
|
|
40
|
+
owner: Function;
|
|
41
|
+
spec: ToolSpec;
|
|
42
|
+
}
|
|
43
|
+
/** A declaration the platform would refuse before the app's method ever ran. */
|
|
44
|
+
export declare class DeclarationRefused extends Error {
|
|
45
|
+
constructor(message: string);
|
|
46
|
+
}
|
|
47
|
+
interface Declared {
|
|
48
|
+
name: string;
|
|
49
|
+
options: ErasedToolOptions;
|
|
50
|
+
method: (...args: unknown[]) => unknown;
|
|
51
|
+
}
|
|
52
|
+
/** Record one decorated method against the class that declared it. */
|
|
53
|
+
export declare function register(prototype: object, declared: Declared): void;
|
|
54
|
+
/** The JSON Schema a model must satisfy, from an explicit zod object or from the signature. */
|
|
55
|
+
export declare function parametersOf(params: ParamDoc[], explicit?: z.ZodObject): Record<string, unknown>;
|
|
56
|
+
/** Every tool this agent declares, its own class's first, then the ones it inherits. */
|
|
57
|
+
export declare function toolsOf(agent: object): ToolDeclaration[];
|
|
58
|
+
/** One declared tool by the name the model calls. */
|
|
59
|
+
export declare function toolNamed(agent: object, name: string): ToolDeclaration | undefined;
|
|
60
|
+
/** The tools the state shows right now: `when` is asked of a snapshot, never of a stage. */
|
|
61
|
+
export declare function visibleToolsOf(agent: object): ToolDeclaration[];
|
|
62
|
+
/** The specs a model may call right now — the list the runtime puts in the request. */
|
|
63
|
+
export declare function visibleTools(agent: object): ToolSpec[];
|
|
64
|
+
/** The docstring of the agent's own class, as the model reads it above everything else. */
|
|
65
|
+
export declare function docOf(agent: object): string | undefined;
|
|
66
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/agent/tools.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAErG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAkD,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAIrD,YAAY,EAAE,QAAQ,EAAE,CAAC;AAIzB,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AAE9D;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,6FAA6F;IAC7F,IAAI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AG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWhG;AAyDD,wFAAwF;AACxF,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,EAAE,CAuBxD;AAED,qDAAqD;AACrD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAElF;AAED,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,EAAE,CAG/D;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE,CAEtD;AAED,2FAA2F;AAC3F,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvD"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/** The tool registry: what a class declares, what the wire is sent, and what the state shows now. */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { classDoc, docsVersion, methodDoc, methodParams } from "./docstrings.js";
|
|
4
|
+
import { snapshot } from "./state.js";
|
|
5
|
+
/** A declaration the platform would refuse before the app's method ever ran. */
|
|
6
|
+
export class DeclarationRefused extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "DeclarationRefused";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
// Keyed by the prototype the decorator was handed, so a tool is declared once per class and not
|
|
13
|
+
// once per instance. The chain is walked at read time, so a subclass inherits its parent's tools.
|
|
14
|
+
const registries = new WeakMap();
|
|
15
|
+
const specs = new WeakMap();
|
|
16
|
+
const A_NAME_A_MODEL_CAN_CALL = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
17
|
+
/** Record one decorated method against the class that declared it. */
|
|
18
|
+
export function register(prototype, declared) {
|
|
19
|
+
if (!A_NAME_A_MODEL_CAN_CALL.test(declared.name)) {
|
|
20
|
+
throw new DeclarationRefused(`a tool name is one word a model can call, not ${declared.name}`);
|
|
21
|
+
}
|
|
22
|
+
let registry = registries.get(prototype);
|
|
23
|
+
if (!registry) {
|
|
24
|
+
registry = new Map();
|
|
25
|
+
registries.set(prototype, registry);
|
|
26
|
+
}
|
|
27
|
+
registry.set(declared.name, declared);
|
|
28
|
+
}
|
|
29
|
+
// string, number and boolean are the three a model fills directly. A shape the source could resolve
|
|
30
|
+
// — a Slot, a Patient — arrives already expanded in `param.schema`; this maps what is left, the
|
|
31
|
+
// types a scraped class body still gives as bare text, and an open object is the honest answer.
|
|
32
|
+
function schemaOf(type) {
|
|
33
|
+
const name = (type ?? "").split(" ").join("");
|
|
34
|
+
if (name.includes("=>"))
|
|
35
|
+
return { description: "callback" };
|
|
36
|
+
if (name.endsWith("[]"))
|
|
37
|
+
return { type: "array", items: schemaOf(name.slice(0, -2)) };
|
|
38
|
+
if (name === "string" || name === "number" || name === "boolean")
|
|
39
|
+
return { type: name };
|
|
40
|
+
return { type: "object", additionalProperties: true };
|
|
41
|
+
}
|
|
42
|
+
/** The JSON Schema a model must satisfy, from an explicit zod object or from the signature. */
|
|
43
|
+
export function parametersOf(params, explicit) {
|
|
44
|
+
if (explicit)
|
|
45
|
+
return z.toJSONSchema(explicit);
|
|
46
|
+
const properties = {};
|
|
47
|
+
const required = [];
|
|
48
|
+
for (const param of params) {
|
|
49
|
+
const schema = param.schema ?? schemaOf(param.type);
|
|
50
|
+
properties[param.name] = schema;
|
|
51
|
+
// A callback is the app's own plumbing: the model cannot write one, so it is never asked for.
|
|
52
|
+
if (!param.optional && schema["description"] !== "callback")
|
|
53
|
+
required.push(param.name);
|
|
54
|
+
}
|
|
55
|
+
return { type: "object", properties, required, additionalProperties: false };
|
|
56
|
+
}
|
|
57
|
+
/** Build the wire spec for one declared tool, refusing what the gateway would refuse. */
|
|
58
|
+
function specFor(ctor, declared) {
|
|
59
|
+
const description = methodDoc(ctor, declared.name);
|
|
60
|
+
if (!description) {
|
|
61
|
+
throw new DeclarationRefused(`tool ${declared.name}: without a docstring no model can choose it; ` +
|
|
62
|
+
`write a /** one line */ above the method`);
|
|
63
|
+
}
|
|
64
|
+
const options = declared.options;
|
|
65
|
+
const parameters = parametersOf(methodParams(ctor, declared.name), options.params);
|
|
66
|
+
const properties = (parameters["properties"] ?? {});
|
|
67
|
+
const unknownPii = (options.pii ?? []).filter((field) => !(field in properties));
|
|
68
|
+
if (unknownPii.length > 0) {
|
|
69
|
+
throw new DeclarationRefused(`tool ${declared.name}: pii names parameters the tool has; unknown: ${unknownPii.join(", ")}`);
|
|
70
|
+
}
|
|
71
|
+
// A read-back is what makes a tool irreversible: the platform reads it, hears the yes, then runs.
|
|
72
|
+
const spec = {
|
|
73
|
+
name: declared.name,
|
|
74
|
+
description,
|
|
75
|
+
parameters,
|
|
76
|
+
side_effect: options.confirm ? "irreversible" : "read",
|
|
77
|
+
};
|
|
78
|
+
if (options.confirm !== undefined)
|
|
79
|
+
spec.confirm = options.confirm;
|
|
80
|
+
if (options.pii !== undefined)
|
|
81
|
+
spec.pii = [...options.pii];
|
|
82
|
+
if (options.timeout !== undefined)
|
|
83
|
+
spec.timeout_s = options.timeout;
|
|
84
|
+
return spec;
|
|
85
|
+
}
|
|
86
|
+
function cachedSpec(ctor, prototype, declared) {
|
|
87
|
+
let byName = specs.get(prototype);
|
|
88
|
+
if (!byName) {
|
|
89
|
+
byName = new Map();
|
|
90
|
+
specs.set(prototype, byName);
|
|
91
|
+
}
|
|
92
|
+
const known = byName.get(declared.name);
|
|
93
|
+
if (known && known.version === docsVersion())
|
|
94
|
+
return known.spec;
|
|
95
|
+
const spec = specFor(ctor, declared);
|
|
96
|
+
byName.set(declared.name, { spec, version: docsVersion() });
|
|
97
|
+
return spec;
|
|
98
|
+
}
|
|
99
|
+
// A `stage` is a question about the class's own `stage` field, so a class that declares none would
|
|
100
|
+
// hide every staged tool for the whole call. The compiler says so first; this is the same sentence
|
|
101
|
+
// for a class written in JavaScript, and it is read at mount, before a model ever sees the list.
|
|
102
|
+
function refuseAStageWithNoField(agent, ctor, name) {
|
|
103
|
+
if ("stage" in agent)
|
|
104
|
+
return;
|
|
105
|
+
throw new DeclarationRefused(`tool ${name}: stage names a value of this agent's own stage field, and ${ctor.name} ` +
|
|
106
|
+
`declares none; add \`stage: Stages<"…"> = "…"\` to the class, or ask when(state) instead`);
|
|
107
|
+
}
|
|
108
|
+
/** Every tool this agent declares, its own class's first, then the ones it inherits. */
|
|
109
|
+
export function toolsOf(agent) {
|
|
110
|
+
const ctor = agent.constructor;
|
|
111
|
+
const declarations = [];
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
for (let prototype = Object.getPrototypeOf(agent); prototype && prototype !== Object.prototype; prototype = Object.getPrototypeOf(prototype)) {
|
|
114
|
+
for (const declared of registries.get(prototype)?.values() ?? []) {
|
|
115
|
+
if (seen.has(declared.name))
|
|
116
|
+
continue;
|
|
117
|
+
seen.add(declared.name);
|
|
118
|
+
if (declared.options.stage !== undefined)
|
|
119
|
+
refuseAStageWithNoField(agent, ctor, declared.name);
|
|
120
|
+
declarations.push({
|
|
121
|
+
name: declared.name,
|
|
122
|
+
options: declared.options,
|
|
123
|
+
method: declared.method,
|
|
124
|
+
owner: prototype.constructor,
|
|
125
|
+
spec: cachedSpec(ctor, prototype, declared),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return declarations;
|
|
130
|
+
}
|
|
131
|
+
/** One declared tool by the name the model calls. */
|
|
132
|
+
export function toolNamed(agent, name) {
|
|
133
|
+
return toolsOf(agent).find((declared) => declared.name === name);
|
|
134
|
+
}
|
|
135
|
+
/** The tools the state shows right now: `when` is asked of a snapshot, never of a stage. */
|
|
136
|
+
export function visibleToolsOf(agent) {
|
|
137
|
+
const state = snapshot(agent);
|
|
138
|
+
return toolsOf(agent).filter((declared) => declared.options.when?.(state) ?? true);
|
|
139
|
+
}
|
|
140
|
+
/** The specs a model may call right now — the list the runtime puts in the request. */
|
|
141
|
+
export function visibleTools(agent) {
|
|
142
|
+
return visibleToolsOf(agent).map((declared) => declared.spec);
|
|
143
|
+
}
|
|
144
|
+
/** The docstring of the agent's own class, as the model reads it above everything else. */
|
|
145
|
+
export function docOf(agent) {
|
|
146
|
+
return classDoc(agent.constructor);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/agent/tools.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAErG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AAEhG,OAAO,EAAE,QAAQ,EAAiB,MAAM,YAAY,CAAC;AAiDrD,gFAAgF;AAChF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAQD,gGAAgG;AAChG,kGAAkG;AAClG,MAAM,UAAU,GAAG,IAAI,OAAO,EAAiC,CAAC;AAChE,MAAM,KAAK,GAAG,IAAI,OAAO,EAA4D,CAAC;AAEtF,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAE1D,sEAAsE;AACtE,MAAM,UAAU,QAAQ,CAAC,SAAiB,EAAE,QAAkB;IAC5D,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,kBAAkB,CAAC,iDAAiD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,GAAG,EAAE,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C,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,KAAa,EAAE,IAAY;IACnD,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC;AACrF,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,OAAO,QAAQ,CAAE,KAAmC,CAAC,WAAW,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** `@state`: which fields are the state, and who may see them. Declared once on the class. */
|
|
2
|
+
/** Who may see a field of the state. The wire's three words, from protocol/schema/defs.json. */
|
|
3
|
+
export type Visibility = "public" | "tenant" | "pii";
|
|
4
|
+
/** Everything `@state({...})` accepts: who may see the field, or `pii: true`, which is the same answer. */
|
|
5
|
+
export interface StateOptions {
|
|
6
|
+
visibility?: Visibility;
|
|
7
|
+
/** Sugar for `visibility: "pii"` — the one every app writes, spelled the way it is thought about. */
|
|
8
|
+
pii?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** One field's declaration, in the shape AgentConfig.state_fields carries it. */
|
|
11
|
+
export interface StateFieldSpec {
|
|
12
|
+
name: string;
|
|
13
|
+
visibility: Visibility;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Declare a field as the agent's state, and optionally who may see it. Three spellings, one
|
|
17
|
+
* meaning: `@state`, `@state({ pii: true })`, `@state({ visibility: "public" })`.
|
|
18
|
+
*
|
|
19
|
+
* A field with no visibility is `tenant`, which is also the wire's default, so the framework never
|
|
20
|
+
* sends a declaration the tenant did not write.
|
|
21
|
+
*/
|
|
22
|
+
export declare function state(prototype: object, name: string): void;
|
|
23
|
+
export declare function state(options?: StateOptions): (prototype: object, name: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Every field declaration this class carries, parents first: the `@state` decorators up the
|
|
26
|
+
* prototype chain, and then `static visibility = { field: "public" }` for a class that would
|
|
27
|
+
* rather write a map than a decorator. The map wins, because it is written last and closest.
|
|
28
|
+
*/
|
|
29
|
+
export declare function visibilityOf(ctor: Function): StateFieldSpec[];
|
|
30
|
+
/**
|
|
31
|
+
* The fields this class said are its state, or null when it decorated none.
|
|
32
|
+
*
|
|
33
|
+
* One rule, and it is the whole feature: a class that decorates NO field has every own field as
|
|
34
|
+
* state, as it always did; a class that decorates ANY field means "these, and nothing else", so an
|
|
35
|
+
* undecorated field on it is the tenant's own scratch space — out of the snapshot, out of the
|
|
36
|
+
* prompt, out of `state.changed`. `static visibility` says who may see a field and never whether it
|
|
37
|
+
* is one: a map is an answer about visibility, not a declaration of the state.
|
|
38
|
+
*/
|
|
39
|
+
export declare function declaredStateOf(ctor: Function): ReadonlySet<string> | null;
|
|
40
|
+
//# sourceMappingURL=visibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../src/agent/visibility.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAI9F,gGAAgG;AAChG,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;AAErD,2GAA2G;AAC3G,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,qGAAqG;IACrG,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;CACxB;AAaD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;AAC7D,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAYzF;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,EAAE,CAU7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAU1E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** `@state`: which fields are the state, and who may see them. Declared once on the class. */
|
|
2
|
+
import { DeclarationRefused } from "./tools.js";
|
|
3
|
+
// Keyed by prototype, like the tool registry: a legacy decorator runs once per class at
|
|
4
|
+
// definition time, so a subclass inherits its parent's declarations by walking the chain. A field
|
|
5
|
+
// declared with no visibility maps to undefined: it is state, and the wire is told nothing about
|
|
6
|
+
// who may see it, which is the wire's own default.
|
|
7
|
+
const declared = new WeakMap();
|
|
8
|
+
// The merged declaration of a class, worked out once. Every `@state` of a class runs at definition
|
|
9
|
+
// time, before any instance exists, so the answer cannot change after the first read — and the
|
|
10
|
+
// Proxy asks this on every assignment.
|
|
11
|
+
const merged = new WeakMap();
|
|
12
|
+
export function state(first, name) {
|
|
13
|
+
// A legacy property decorator is called `(prototype, name)`, a factory with its options or with
|
|
14
|
+
// nothing at all: the second argument is what tells the two apart.
|
|
15
|
+
if (typeof name === "string")
|
|
16
|
+
return declare(first, name, {});
|
|
17
|
+
const options = (first ?? {});
|
|
18
|
+
return (prototype, field) => declare(prototype, field, options);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Every field declaration this class carries, parents first: the `@state` decorators up the
|
|
22
|
+
* prototype chain, and then `static visibility = { field: "public" }` for a class that would
|
|
23
|
+
* rather write a map than a decorator. The map wins, because it is written last and closest.
|
|
24
|
+
*/
|
|
25
|
+
export function visibilityOf(ctor) {
|
|
26
|
+
const fields = new Map();
|
|
27
|
+
for (const prototype of chainOf(ctor)) {
|
|
28
|
+
for (const [field, visibility] of declared.get(prototype) ?? [])
|
|
29
|
+
fields.set(field, visibility);
|
|
30
|
+
}
|
|
31
|
+
const map = ctor.visibility;
|
|
32
|
+
for (const [field, visibility] of Object.entries(map ?? {}))
|
|
33
|
+
fields.set(field, visibility);
|
|
34
|
+
return [...fields]
|
|
35
|
+
.filter((entry) => entry[1] !== undefined)
|
|
36
|
+
.map(([name, visibility]) => ({ name, visibility }));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The fields this class said are its state, or null when it decorated none.
|
|
40
|
+
*
|
|
41
|
+
* One rule, and it is the whole feature: a class that decorates NO field has every own field as
|
|
42
|
+
* state, as it always did; a class that decorates ANY field means "these, and nothing else", so an
|
|
43
|
+
* undecorated field on it is the tenant's own scratch space — out of the snapshot, out of the
|
|
44
|
+
* prompt, out of `state.changed`. `static visibility` says who may see a field and never whether it
|
|
45
|
+
* is one: a map is an answer about visibility, not a declaration of the state.
|
|
46
|
+
*/
|
|
47
|
+
export function declaredStateOf(ctor) {
|
|
48
|
+
const known = merged.get(ctor);
|
|
49
|
+
if (known !== undefined)
|
|
50
|
+
return known;
|
|
51
|
+
const fields = new Set();
|
|
52
|
+
for (const prototype of chainOf(ctor)) {
|
|
53
|
+
for (const field of (declared.get(prototype) ?? new Map()).keys())
|
|
54
|
+
fields.add(field);
|
|
55
|
+
}
|
|
56
|
+
const answer = fields.size === 0 ? null : fields;
|
|
57
|
+
merged.set(ctor, answer);
|
|
58
|
+
return answer;
|
|
59
|
+
}
|
|
60
|
+
// The prototypes of a class, parents first, so a subclass's own declaration is written last.
|
|
61
|
+
function chainOf(ctor) {
|
|
62
|
+
const chain = [];
|
|
63
|
+
for (let prototype = ctor.prototype ?? null; prototype !== null && prototype !== Object.prototype; prototype = Object.getPrototypeOf(prototype)) {
|
|
64
|
+
chain.unshift(prototype);
|
|
65
|
+
}
|
|
66
|
+
return chain;
|
|
67
|
+
}
|
|
68
|
+
function declare(prototype, name, options) {
|
|
69
|
+
let own = declared.get(prototype);
|
|
70
|
+
if (own === undefined) {
|
|
71
|
+
own = new Map();
|
|
72
|
+
declared.set(prototype, own);
|
|
73
|
+
}
|
|
74
|
+
own.set(name, visibilityIn(options, prototype, name));
|
|
75
|
+
}
|
|
76
|
+
// `pii: true` is `visibility: "pii"` said the way an app thinks about it. Written together they
|
|
77
|
+
// are either the same answer twice or two different ones, and the second is a field whose masking
|
|
78
|
+
// depends on which line the reader believes.
|
|
79
|
+
function visibilityIn(options, prototype, name) {
|
|
80
|
+
if (options.pii === true && options.visibility !== undefined && options.visibility !== "pii") {
|
|
81
|
+
throw new DeclarationRefused(`@state({ pii: true, visibility: ${JSON.stringify(options.visibility)} }) on ` +
|
|
82
|
+
`${prototype.constructor.name}.${name}: ` +
|
|
83
|
+
`two different answers to one question; write one`);
|
|
84
|
+
}
|
|
85
|
+
if (options.pii === true)
|
|
86
|
+
return "pii";
|
|
87
|
+
return options.visibility;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=visibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.js","sourceRoot":"","sources":["../../src/agent/visibility.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;A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AAE,IAAY,EAAE,OAAqB;IACrE,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,GAAG,GAAG,IAAI,GAAG,EAAkC,CAAC;QAChD,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC/B,CAAC;IACD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,gGAAgG;AAChG,kGAAkG;AAClG,6CAA6C;AAC7C,SAAS,YAAY,CAAC,OAAqB,EAAE,SAAiB,EAAE,IAAY;IAC1E,IAAI,OAAO,CAAC,GAAG,KAAK,IAAI,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;QAC7F,MAAM,IAAI,kBAAkB,CAC1B,mCAAmC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS;YAC5E,GAAI,SAAuC,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,IAAI;YACxE,kDAAkD,CACrD,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,OAAO,CAAC,UAAU,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** `this.call`: the one call this instance is serving — its line, its room, its turns, its verbs. */
|
|
2
|
+
import type { Call as HookCall } from "../agent/lifecycle.js";
|
|
3
|
+
import { History } from "./history.js";
|
|
4
|
+
import { ParticipantHandle, Room, type Commander } from "./room.js";
|
|
5
|
+
/** What the call world needs to know about the line, beyond what the room's entries tell it. */
|
|
6
|
+
export interface CallLine extends HookCall {
|
|
7
|
+
today?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One live call, as the class holds it. Everything on it was reduced from entries the runtime
|
|
11
|
+
* already receives, and every verb is one command on the wire — there is no LiveKit here and no
|
|
12
|
+
* escape hatch to it: a need the room cannot express is a new command with a name.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CallWorld implements HookCall {
|
|
15
|
+
#private;
|
|
16
|
+
private readonly out;
|
|
17
|
+
private readonly ackMs;
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly contact: string;
|
|
20
|
+
readonly from?: string;
|
|
21
|
+
readonly channel?: string;
|
|
22
|
+
/** The day this call opened, `YYYY-MM-DD`. What a prompt — and an agenda — means by today. */
|
|
23
|
+
readonly today?: string;
|
|
24
|
+
readonly room: Room;
|
|
25
|
+
readonly history: History;
|
|
26
|
+
/** The event being dispatched right now, so a write inside onEvent can name its cause. */
|
|
27
|
+
cause: {
|
|
28
|
+
name: string;
|
|
29
|
+
seq: number;
|
|
30
|
+
} | null;
|
|
31
|
+
constructor(line: CallLine, out: Commander, ackMs?: number);
|
|
32
|
+
/** The next outside fact's place in this call's own stream of them; the wire's seq is not on it. */
|
|
33
|
+
numbered(): number;
|
|
34
|
+
/** One participant, and what may be done to them: `call.participant(id).mute()`. */
|
|
35
|
+
participant(identity: string): ParticipantHandle;
|
|
36
|
+
/** Push a payload to a browser in the room. The log keeps its size, never the payload. */
|
|
37
|
+
send(topic: string, data: Record<string, unknown>, options?: {
|
|
38
|
+
to?: string;
|
|
39
|
+
}): void;
|
|
40
|
+
/** Say this, word for word. Resolves true when the turn it lands as arrived, false on the wait. */
|
|
41
|
+
say(text: string, options?: {
|
|
42
|
+
allowInterruptions?: boolean;
|
|
43
|
+
}): Promise<boolean>;
|
|
44
|
+
/** Make the model speak, guided by words the caller never hears. Resolves like `say`. */
|
|
45
|
+
reply(instructions: string, options?: {
|
|
46
|
+
allowInterruptions?: boolean;
|
|
47
|
+
}): Promise<boolean>;
|
|
48
|
+
/** Invite somebody into the room: the room's own verb, reachable from the call for symmetry. */
|
|
49
|
+
invite(to: string, options: {
|
|
50
|
+
kind: "sip" | "participant";
|
|
51
|
+
}): void;
|
|
52
|
+
/** One entry of this call's, folded into the room and the history. Unknown types are ignored. */
|
|
53
|
+
take(type: string, data: Record<string, unknown>, at: number): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=call.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../src/call/call.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAErG,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,KAAK,SAAS,EAAwB,MAAM,WAAW,CAAC;AAK1F,gGAAgG;AAChG,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,qBAAa,SAAU,YAAW,QAAQ;;IAoBtC,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IApBxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,OAAO,UAAiB;IAMjC,0FAA0F;IAC1F,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAQ;IAGnD,YACE,IAAI,EAAE,QAAQ,EACG,GAAG,EAAE,SAAS,EACd,KAAK,SAAS,EAQhC;IAED,oGAAoG;IACpG,QAAQ,IAAI,MAAM,CAEjB;IAED,oFAAoF;IACpF,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAE/C;IAED,0FAA0F;IAC1F,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI,CAEtF;IAED,mGAAmG;IACnG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAGlF;IAED,yFAAyF;IACzF,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAG5F;IAED,gGAAgG;IAChG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,KAAK,GAAG,aAAa,CAAA;KAAE,GAAG,IAAI,CAEjE;IAED,iGAAiG;IACjG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAuBlE;CAmBF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** `this.call`: the one call this instance is serving — its line, its room, its turns, its verbs. */
|
|
2
|
+
import { History } from "./history.js";
|
|
3
|
+
import { ParticipantHandle, Room } from "./room.js";
|
|
4
|
+
/** How long a say or a reply waits for the turn it lands as before it gives up saying so. */
|
|
5
|
+
const ACK_MS = 30_000;
|
|
6
|
+
/**
|
|
7
|
+
* One live call, as the class holds it. Everything on it was reduced from entries the runtime
|
|
8
|
+
* already receives, and every verb is one command on the wire — there is no LiveKit here and no
|
|
9
|
+
* escape hatch to it: a need the room cannot express is a new command with a name.
|
|
10
|
+
*/
|
|
11
|
+
export class CallWorld {
|
|
12
|
+
out;
|
|
13
|
+
ackMs;
|
|
14
|
+
id;
|
|
15
|
+
contact;
|
|
16
|
+
from;
|
|
17
|
+
channel;
|
|
18
|
+
/** The day this call opened, `YYYY-MM-DD`. What a prompt — and an agenda — means by today. */
|
|
19
|
+
today;
|
|
20
|
+
room;
|
|
21
|
+
history = new History();
|
|
22
|
+
// Who is waiting for the agent's next turn. say and reply both settle on it, because turn.agent
|
|
23
|
+
// is the only acknowledgement the wire has for either: the command frame itself is fire and
|
|
24
|
+
// forget, and the gateway answers commands with the entries they land as.
|
|
25
|
+
#speaking = [];
|
|
26
|
+
/** The event being dispatched right now, so a write inside onEvent can name its cause. */
|
|
27
|
+
cause = null;
|
|
28
|
+
#events = 0;
|
|
29
|
+
constructor(line, out, ackMs = ACK_MS) {
|
|
30
|
+
this.out = out;
|
|
31
|
+
this.ackMs = ackMs;
|
|
32
|
+
this.id = line.id;
|
|
33
|
+
this.contact = line.contact;
|
|
34
|
+
if (line.from !== undefined)
|
|
35
|
+
this.from = line.from;
|
|
36
|
+
if (line.channel !== undefined)
|
|
37
|
+
this.channel = line.channel;
|
|
38
|
+
if (line.today !== undefined)
|
|
39
|
+
this.today = line.today;
|
|
40
|
+
this.room = new Room(out);
|
|
41
|
+
}
|
|
42
|
+
/** The next outside fact's place in this call's own stream of them; the wire's seq is not on it. */
|
|
43
|
+
numbered() {
|
|
44
|
+
return (this.#events += 1);
|
|
45
|
+
}
|
|
46
|
+
/** One participant, and what may be done to them: `call.participant(id).mute()`. */
|
|
47
|
+
participant(identity) {
|
|
48
|
+
return new ParticipantHandle(identity, this.out);
|
|
49
|
+
}
|
|
50
|
+
/** Push a payload to a browser in the room. The log keeps its size, never the payload. */
|
|
51
|
+
send(topic, data, options = {}) {
|
|
52
|
+
this.out("room.send", options.to === undefined ? { topic, data } : { topic, data, to: options.to });
|
|
53
|
+
}
|
|
54
|
+
/** Say this, word for word. Resolves true when the turn it lands as arrived, false on the wait. */
|
|
55
|
+
say(text, options = {}) {
|
|
56
|
+
this.out("agent.say", { text, ...options });
|
|
57
|
+
return this.#spoken();
|
|
58
|
+
}
|
|
59
|
+
/** Make the model speak, guided by words the caller never hears. Resolves like `say`. */
|
|
60
|
+
reply(instructions, options = {}) {
|
|
61
|
+
this.out("agent.reply", { instructions, ...options });
|
|
62
|
+
return this.#spoken();
|
|
63
|
+
}
|
|
64
|
+
/** Invite somebody into the room: the room's own verb, reachable from the call for symmetry. */
|
|
65
|
+
invite(to, options) {
|
|
66
|
+
this.room.invite(to, options);
|
|
67
|
+
}
|
|
68
|
+
/** One entry of this call's, folded into the room and the history. Unknown types are ignored. */
|
|
69
|
+
take(type, data, at) {
|
|
70
|
+
switch (type) {
|
|
71
|
+
case "participant.joined":
|
|
72
|
+
return this.room.joined({
|
|
73
|
+
identity: String(data["identity"]),
|
|
74
|
+
kind: data["kind"],
|
|
75
|
+
...(typeof data["name"] === "string" ? { name: data["name"] } : {}),
|
|
76
|
+
}, at);
|
|
77
|
+
case "participant.left":
|
|
78
|
+
return this.room.left(String(data["identity"]));
|
|
79
|
+
case "participant.speaking":
|
|
80
|
+
return this.room.speaking(String(data["identity"]), data["speaking"] === true);
|
|
81
|
+
case "turn.user":
|
|
82
|
+
return this.history.took({ who: "user", text: String(data["text"] ?? ""), speechId: String(data["speech_id"] ?? data["speechId"] ?? ""), interrupted: false, at });
|
|
83
|
+
case "turn.agent":
|
|
84
|
+
this.history.took({ who: "agent", text: String(data["text"] ?? ""), speechId: String(data["speech_id"] ?? data["speechId"] ?? ""), interrupted: data["interrupted"] === true, at });
|
|
85
|
+
return this.#settle(true);
|
|
86
|
+
default:
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
#spoken() {
|
|
91
|
+
return new Promise((resolve) => {
|
|
92
|
+
this.#speaking.push(resolve);
|
|
93
|
+
// A line that hung up mid-sentence must not leave a tool awaiting forever, and a hang-up is
|
|
94
|
+
// not an error the tool can do anything about: the wait answers false and the call goes on.
|
|
95
|
+
setTimeout(() => {
|
|
96
|
+
this.#speaking = this.#speaking.filter((waiting) => waiting !== resolve);
|
|
97
|
+
resolve(false);
|
|
98
|
+
}, this.ackMs).unref?.();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
#settle(spoken) {
|
|
102
|
+
const waiting = this.#speaking;
|
|
103
|
+
this.#speaking = [];
|
|
104
|
+
for (const resolve of waiting)
|
|
105
|
+
resolve(spoken);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../src/call/call.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAGrG,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAwC,MAAM,WAAW,CAAC;AAE1F,6FAA6F;AAC7F,MAAM,MAAM,GAAG,MAAM,CAAC;AAOtB;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAoBD,GAAG;IACH,KAAK;IApBf,EAAE,CAAS;IACX,OAAO,CAAS;IAChB,IAAI,CAAU;IACd,OAAO,CAAU;IAC1B,8FAA8F;IACrF,KAAK,CAAU;IACf,IAAI,CAAO;IACX,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAEjC,gGAAgG;IAChG,4FAA4F;IAC5F,0EAA0E;IAC1E,SAAS,GAAkC,EAAE,CAAC;IAC9C,0FAA0F;IAC1F,KAAK,GAAyC,IAAI,CAAC;IACnD,OAAO,GAAG,CAAC,CAAC;IAEZ,YACE,IAAc,EACG,GAAc,EACd,KAAK,GAAG,MAAM;mBADd,GAAG;qBACH,KAAK;QAEtB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,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 -0,0 +1,34 @@
|
|
|
1
|
+
/** The conversation so far: finished turns, and the one sentence a long call collapses them to. */
|
|
2
|
+
/** One finished turn, from turn.user or turn.agent. Only what was said; the metrics stay in the log. */
|
|
3
|
+
export interface Turn {
|
|
4
|
+
who: "user" | "agent";
|
|
5
|
+
text: string;
|
|
6
|
+
/** The id that joins a caller's turn to the reply it triggered. */
|
|
7
|
+
speechId: string;
|
|
8
|
+
/** True when the caller cut the agent off; always false for a caller's own turn. */
|
|
9
|
+
interrupted: boolean;
|
|
10
|
+
at: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The turns this call has finished, oldest first. A turn lands here when its entry does, so the
|
|
14
|
+
* words the model is still speaking are not in it — the log is the record, this is the reading.
|
|
15
|
+
*/
|
|
16
|
+
export declare class History {
|
|
17
|
+
#private;
|
|
18
|
+
/** Every finished turn, oldest first. */
|
|
19
|
+
get turns(): readonly Turn[];
|
|
20
|
+
/** How many turns are being kept. */
|
|
21
|
+
get length(): number;
|
|
22
|
+
/** The sentence a `collapse` left in place of the turns before it, or null while none was made. */
|
|
23
|
+
get summary(): string | null;
|
|
24
|
+
/** The last turn, whoever took it. */
|
|
25
|
+
get last(): Turn | undefined;
|
|
26
|
+
/** Add a finished turn. The bridge calls this from turn.user and turn.agent; nothing else does. */
|
|
27
|
+
took(turn: Turn): void;
|
|
28
|
+
/**
|
|
29
|
+
* Drop the turns and keep one sentence in their place. This is the view's memory, not the log's:
|
|
30
|
+
* the call log keeps every turn it ever had, and a summary here never rewrites one.
|
|
31
|
+
*/
|
|
32
|
+
collapse(summary: string): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/call/history.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAEnG,wGAAwG;AACxG,MAAM,WAAW,IAAI;IACnB,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,WAAW,EAAE,OAAO,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,qBAAa,OAAO;;IAIlB,yCAAyC;IACzC,IAAI,KAAK,IAAI,SAAS,IAAI,EAAE,CAE3B;IAED,qCAAqC;IACrC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,mGAAmG;IACnG,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,sCAAsC;IACtC,IAAI,IAAI,IAAI,IAAI,GAAG,SAAS,CAE3B;IAED,mGAAmG;IACnG,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAErB;IAED;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAG9B;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** The conversation so far: finished turns, and the one sentence a long call collapses them to. */
|
|
2
|
+
/**
|
|
3
|
+
* The turns this call has finished, oldest first. A turn lands here when its entry does, so the
|
|
4
|
+
* words the model is still speaking are not in it — the log is the record, this is the reading.
|
|
5
|
+
*/
|
|
6
|
+
export class History {
|
|
7
|
+
#turns = [];
|
|
8
|
+
#summary = null;
|
|
9
|
+
/** Every finished turn, oldest first. */
|
|
10
|
+
get turns() {
|
|
11
|
+
return this.#turns;
|
|
12
|
+
}
|
|
13
|
+
/** How many turns are being kept. */
|
|
14
|
+
get length() {
|
|
15
|
+
return this.#turns.length;
|
|
16
|
+
}
|
|
17
|
+
/** The sentence a `collapse` left in place of the turns before it, or null while none was made. */
|
|
18
|
+
get summary() {
|
|
19
|
+
return this.#summary;
|
|
20
|
+
}
|
|
21
|
+
/** The last turn, whoever took it. */
|
|
22
|
+
get last() {
|
|
23
|
+
return this.#turns[this.#turns.length - 1];
|
|
24
|
+
}
|
|
25
|
+
/** Add a finished turn. The bridge calls this from turn.user and turn.agent; nothing else does. */
|
|
26
|
+
took(turn) {
|
|
27
|
+
this.#turns.push(turn);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Drop the turns and keep one sentence in their place. This is the view's memory, not the log's:
|
|
31
|
+
* the call log keeps every turn it ever had, and a summary here never rewrites one.
|
|
32
|
+
*/
|
|
33
|
+
collapse(summary) {
|
|
34
|
+
this.#turns.length = 0;
|
|
35
|
+
this.#summary = summary;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/call/history.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAanG;;;GAGG;AACH,MAAM,OAAO,OAAO;IACT,MAAM,GAAW,EAAE,CAAC;IAC7B,QAAQ,GAAkB,IAAI,CAAC;IAE/B,yCAAyC;IACzC,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,qCAAqC;IACrC,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,mGAAmG;IACnG,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,sCAAsC;IACtC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,mGAAmG;IACnG,IAAI,CAAC,IAAU;QACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,OAAe;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;CACF"}
|