luca 3.0.0 → 3.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/.github/workflows/release.yaml +1 -0
- package/CLAUDE.md +10 -2
- package/README.md +130 -112
- package/assistants/codingAssistant/CORE.md +6 -1
- package/assistants/codingAssistant/hooks.ts +1 -1
- package/assistants/inkbot/hooks.ts +1 -1
- package/assistants/inkbot/tools.ts +1 -1
- package/bun.lock +264 -321
- package/commands/audit-docs.ts +2 -2
- package/commands/build-bootstrap.ts +2 -3
- package/commands/build-python-bridge.ts +2 -3
- package/commands/build-scaffolds.ts +2 -3
- package/commands/bundle-consumer-project.ts +521 -0
- package/commands/generate-api-docs.ts +2 -2
- package/commands/inkbot.ts +2 -2
- package/commands/release.ts +2 -2
- package/commands/social.ts +137 -0
- package/commands/try-all-challenges.ts +3 -3
- package/commands/try-challenge.ts +3 -3
- package/datasets/lora/agentic-loop-session-candidates.jsonl +91 -0
- package/datasets/lora/agentic-loop-session-curation-summary.json +123 -0
- package/datasets/lora/luca-session-candidates.jsonl +29 -0
- package/datasets/lora/luca-session-curation-summary.json +121 -0
- package/datasets/lora/review-batch-1.jsonl +30 -0
- package/datasets/lora/review-manifest.json +41 -0
- package/datasets/lora/review-queue.jsonl +120 -0
- package/datasets/lora/review-schema.json +134 -0
- package/datasets/lora/review-template.jsonl +2 -0
- package/datasets/lora/review-ui.html +725 -0
- package/dist/agi/container.server.d.ts +2 -2
- package/dist/agi/features/assistant.d.ts +2 -2
- package/dist/agi/features/assistants-manager.d.ts +1 -1
- package/dist/agi/features/autonomous-assistant.d.ts +1 -1
- package/dist/agi/features/browser-use.d.ts +1 -1
- package/dist/agi/features/claude-code.d.ts +1 -1
- package/dist/agi/features/conversation-history.d.ts +2 -2
- package/dist/agi/features/conversation.d.ts +1 -1
- package/dist/agi/features/docs-reader.d.ts +1 -1
- package/dist/agi/features/file-tools.d.ts +1 -1
- package/dist/agi/features/luca-coder.d.ts +1 -1
- package/dist/agi/features/openai-codex.d.ts +1 -1
- package/dist/agi/features/skills-library.d.ts +1 -1
- package/dist/clients/civitai/index.d.ts +4 -4
- package/dist/clients/client-template.d.ts +4 -4
- package/dist/clients/comfyui/index.d.ts +2 -2
- package/dist/clients/elevenlabs/index.d.ts +2 -2
- package/dist/clients/openai/index.d.ts +2 -2
- package/dist/clients/supabase/index.d.ts +3 -3
- package/dist/command.d.ts +1 -1
- package/dist/node/container.d.ts +1 -1
- package/dist/node/features/helpers.d.ts +3 -3
- package/dist/node/features/semantic-search.d.ts +1 -1
- package/dist/node/features/vm.d.ts +3 -3
- package/dist/node.d.ts +1 -1
- package/dist/scaffolds/generated.d.ts +1 -1
- package/dist/selector.d.ts +1 -1
- package/features/cipher-social.ts +493 -0
- package/index.html +217 -190
- package/luca.console.ts +1 -1
- package/package.json +7 -2
- package/public/index.html +217 -190
- package/public/slides-ai-native.html +1 -1
- package/public/slides-intro.html +2 -2
- package/scripts/curate-claude-sessions.ts +561 -0
- package/scripts/examples/ask-luca-expert.ts +1 -1
- package/scripts/examples/assistant-questions.ts +1 -1
- package/scripts/examples/excalidraw-expert.ts +1 -1
- package/scripts/examples/file-manager.ts +1 -1
- package/scripts/examples/ideas.ts +1 -1
- package/scripts/examples/interactive-chat.ts +1 -1
- package/scripts/examples/opening-a-web-browser.ts +1 -1
- package/scripts/examples/telegram-bot.ts +1 -1
- package/scripts/examples/using-assistant-with-mcp.ts +1 -1
- package/scripts/examples/using-claude-code.ts +1 -1
- package/scripts/examples/using-contentdb.ts +2 -2
- package/scripts/examples/using-conversations.ts +1 -1
- package/scripts/examples/using-disk-cache.ts +1 -1
- package/scripts/examples/using-docker-shell.ts +1 -1
- package/scripts/examples/using-elevenlabs.ts +1 -1
- package/scripts/examples/using-google-calendar.ts +1 -1
- package/scripts/examples/using-google-docs.ts +1 -1
- package/scripts/examples/using-google-drive.ts +1 -1
- package/scripts/examples/using-google-sheets.ts +1 -1
- package/scripts/examples/using-nlp.ts +1 -1
- package/scripts/examples/using-ollama.ts +1 -1
- package/scripts/examples/using-postgres.ts +1 -1
- package/scripts/examples/using-runpod.ts +1 -1
- package/scripts/examples/using-tts.ts +1 -1
- package/scripts/scaffold.ts +5 -5
- package/scripts/scratch.ts +1 -1
- package/scripts/test-assistant-hooks.ts +1 -1
- package/scripts/test-docs-reader.ts +1 -1
- package/src/agi/container.server.ts +6 -2
- package/src/agi/features/agent-memory.ts +25 -25
- package/src/agi/features/assistant.ts +34 -5
- package/src/agi/features/assistants-manager.ts +122 -6
- package/src/agi/features/autonomous-assistant.ts +1 -1
- package/src/agi/features/browser-use.ts +20 -1
- package/src/agi/features/claude-code.ts +51 -5
- package/src/agi/features/coding-tools.ts +1 -1
- package/src/agi/features/conversation-history.ts +181 -4
- package/src/agi/features/conversation.ts +186 -15
- package/src/agi/features/docs-reader.ts +2 -2
- package/src/agi/features/file-tools.ts +49 -2
- package/src/agi/features/luca-coder.ts +7 -5
- package/src/agi/features/mcp-bridge.ts +532 -0
- package/src/agi/features/openai-codex.ts +2 -2
- package/src/agi/features/skills-library.ts +131 -52
- package/src/agi/lib/token-counter.ts +80 -0
- package/src/bootstrap/generated.ts +56 -57
- package/src/browser.ts +1 -1
- package/src/cli/build-info.ts +2 -2
- package/src/cli/cli.ts +2 -2
- package/src/clients/civitai/index.ts +5 -5
- package/src/clients/client-template.ts +4 -4
- package/src/clients/comfyui/index.ts +4 -4
- package/src/clients/elevenlabs/index.ts +4 -4
- package/src/clients/openai/index.ts +7 -7
- package/src/clients/supabase/index.ts +4 -4
- package/src/clients/voicebox/index.ts +4 -4
- package/src/command.ts +2 -1
- package/src/commands/chat.ts +1 -0
- package/src/commands/eval.ts +2 -56
- package/src/commands/introspect.ts +1 -1
- package/src/commands/prompt.ts +41 -9
- package/src/container-describer.ts +8 -1
- package/src/container.ts +13 -0
- package/src/entity.ts +2 -2
- package/src/helper.ts +1 -1
- package/src/introspection/generated.agi.ts +29596 -27654
- package/src/introspection/generated.node.ts +20284 -19247
- package/src/introspection/generated.web.ts +605 -584
- package/src/introspection/scan.ts +11 -6
- package/src/node/container.ts +9 -1
- package/src/node/features/content-db.ts +39 -2
- package/src/node/features/display-result.ts +57 -0
- package/src/node/features/helpers.ts +46 -7
- package/src/node/features/python.ts +25 -19
- package/src/node/features/repl.ts +1 -1
- package/src/node/features/secure-shell.ts +11 -17
- package/src/node/features/semantic-search.ts +2 -2
- package/src/node/features/socket-repl.ts +336 -0
- package/src/node/features/telnyx-assistant-connector.ts +1206 -0
- package/src/node/features/transpiler.ts +2 -3
- package/src/node/features/ui.ts +5 -0
- package/src/node/features/vm.ts +20 -3
- package/src/node.ts +3 -3
- package/src/python/generated.ts +0 -1
- package/src/scaffolds/generated.ts +82 -83
- package/src/selector.ts +1 -1
- package/src/servers/express.ts +1 -1
- package/src/web/features/helpers.ts +22 -0
- package/tsconfig.json +12 -12
- package/docs/CLI.md +0 -335
- package/docs/CNAME +0 -1
- package/docs/README.md +0 -60
- package/docs/TABLE-OF-CONTENTS.md +0 -183
- package/docs/apis/clients/elevenlabs.md +0 -308
- package/docs/apis/clients/graph.md +0 -107
- package/docs/apis/clients/openai.md +0 -429
- package/docs/apis/clients/rest.md +0 -161
- package/docs/apis/clients/websocket.md +0 -174
- package/docs/apis/features/agi/assistant.md +0 -625
- package/docs/apis/features/agi/assistants-manager.md +0 -282
- package/docs/apis/features/agi/auto-assistant.md +0 -279
- package/docs/apis/features/agi/browser-use.md +0 -802
- package/docs/apis/features/agi/claude-code.md +0 -884
- package/docs/apis/features/agi/conversation-history.md +0 -364
- package/docs/apis/features/agi/conversation.md +0 -548
- package/docs/apis/features/agi/docs-reader.md +0 -99
- package/docs/apis/features/agi/file-tools.md +0 -163
- package/docs/apis/features/agi/luca-coder.md +0 -407
- package/docs/apis/features/agi/openai-codex.md +0 -396
- package/docs/apis/features/agi/openapi.md +0 -138
- package/docs/apis/features/agi/semantic-search.md +0 -387
- package/docs/apis/features/agi/skills-library.md +0 -239
- package/docs/apis/features/node/container-link.md +0 -192
- package/docs/apis/features/node/content-db.md +0 -450
- package/docs/apis/features/node/disk-cache.md +0 -379
- package/docs/apis/features/node/dns.md +0 -652
- package/docs/apis/features/node/docker.md +0 -706
- package/docs/apis/features/node/downloader.md +0 -81
- package/docs/apis/features/node/esbuild.md +0 -60
- package/docs/apis/features/node/file-manager.md +0 -191
- package/docs/apis/features/node/fs.md +0 -1217
- package/docs/apis/features/node/git.md +0 -371
- package/docs/apis/features/node/google-auth.md +0 -193
- package/docs/apis/features/node/google-calendar.md +0 -202
- package/docs/apis/features/node/google-docs.md +0 -173
- package/docs/apis/features/node/google-drive.md +0 -246
- package/docs/apis/features/node/google-mail.md +0 -214
- package/docs/apis/features/node/google-sheets.md +0 -194
- package/docs/apis/features/node/grep.md +0 -292
- package/docs/apis/features/node/helpers.md +0 -164
- package/docs/apis/features/node/ink.md +0 -334
- package/docs/apis/features/node/ipc-socket.md +0 -249
- package/docs/apis/features/node/json-tree.md +0 -86
- package/docs/apis/features/node/networking.md +0 -316
- package/docs/apis/features/node/nlp.md +0 -133
- package/docs/apis/features/node/opener.md +0 -97
- package/docs/apis/features/node/os.md +0 -146
- package/docs/apis/features/node/package-finder.md +0 -392
- package/docs/apis/features/node/postgres.md +0 -234
- package/docs/apis/features/node/proc.md +0 -399
- package/docs/apis/features/node/process-manager.md +0 -305
- package/docs/apis/features/node/python.md +0 -604
- package/docs/apis/features/node/redis.md +0 -380
- package/docs/apis/features/node/repl.md +0 -88
- package/docs/apis/features/node/runpod.md +0 -674
- package/docs/apis/features/node/secure-shell.md +0 -176
- package/docs/apis/features/node/semantic-search.md +0 -408
- package/docs/apis/features/node/sqlite.md +0 -233
- package/docs/apis/features/node/telegram.md +0 -279
- package/docs/apis/features/node/transpiler.md +0 -74
- package/docs/apis/features/node/tts.md +0 -133
- package/docs/apis/features/node/ui.md +0 -701
- package/docs/apis/features/node/vault.md +0 -59
- package/docs/apis/features/node/vm.md +0 -75
- package/docs/apis/features/node/yaml-tree.md +0 -85
- package/docs/apis/features/node/yaml.md +0 -176
- package/docs/apis/features/web/asset-loader.md +0 -59
- package/docs/apis/features/web/container-link.md +0 -192
- package/docs/apis/features/web/esbuild.md +0 -54
- package/docs/apis/features/web/helpers.md +0 -164
- package/docs/apis/features/web/network.md +0 -44
- package/docs/apis/features/web/speech.md +0 -69
- package/docs/apis/features/web/vault.md +0 -59
- package/docs/apis/features/web/vm.md +0 -75
- package/docs/apis/features/web/voice.md +0 -84
- package/docs/apis/servers/express.md +0 -171
- package/docs/apis/servers/mcp.md +0 -238
- package/docs/apis/servers/websocket.md +0 -170
- package/docs/bootstrap/CLAUDE.md +0 -101
- package/docs/bootstrap/SKILL.md +0 -341
- package/docs/bootstrap/templates/about-command.ts +0 -41
- package/docs/bootstrap/templates/docs-models.ts +0 -22
- package/docs/bootstrap/templates/docs-readme.md +0 -43
- package/docs/bootstrap/templates/example-feature.ts +0 -53
- package/docs/bootstrap/templates/health-endpoint.ts +0 -15
- package/docs/bootstrap/templates/luca-cli.ts +0 -30
- package/docs/bootstrap/templates/runme.md +0 -54
- package/docs/challenges/caching-proxy.md +0 -16
- package/docs/challenges/content-db-round-trip.md +0 -14
- package/docs/challenges/custom-command.md +0 -9
- package/docs/challenges/file-watcher-pipeline.md +0 -11
- package/docs/challenges/grep-audit-report.md +0 -15
- package/docs/challenges/multi-feature-dashboard.md +0 -14
- package/docs/challenges/process-orchestrator.md +0 -17
- package/docs/challenges/rest-api-server-with-client.md +0 -12
- package/docs/challenges/script-runner-with-vm.md +0 -11
- package/docs/challenges/simple-rest-api.md +0 -15
- package/docs/challenges/websocket-serve-and-client.md +0 -11
- package/docs/challenges/yaml-config-system.md +0 -14
- package/docs/command-system-overhaul.md +0 -94
- package/docs/documentation-audit.md +0 -134
- package/docs/examples/assistant/CORE.md +0 -18
- package/docs/examples/assistant/hooks.ts +0 -3
- package/docs/examples/assistant/tools.ts +0 -10
- package/docs/examples/assistant-hooks-reference.ts +0 -171
- package/docs/examples/assistant-with-process-manager.md +0 -84
- package/docs/examples/content-db.md +0 -77
- package/docs/examples/disk-cache.md +0 -83
- package/docs/examples/docker.md +0 -101
- package/docs/examples/downloader.md +0 -70
- package/docs/examples/entity.md +0 -124
- package/docs/examples/esbuild.md +0 -80
- package/docs/examples/feature-as-tool-provider.md +0 -143
- package/docs/examples/file-manager.md +0 -82
- package/docs/examples/fs.md +0 -83
- package/docs/examples/git.md +0 -85
- package/docs/examples/google-auth.md +0 -88
- package/docs/examples/google-calendar.md +0 -94
- package/docs/examples/google-docs.md +0 -82
- package/docs/examples/google-drive.md +0 -96
- package/docs/examples/google-sheets.md +0 -95
- package/docs/examples/grep.md +0 -85
- package/docs/examples/ink-blocks.md +0 -75
- package/docs/examples/ink-renderer.md +0 -41
- package/docs/examples/ink.md +0 -103
- package/docs/examples/ipc-socket.md +0 -103
- package/docs/examples/json-tree.md +0 -91
- package/docs/examples/networking.md +0 -58
- package/docs/examples/nlp.md +0 -91
- package/docs/examples/opener.md +0 -78
- package/docs/examples/os.md +0 -72
- package/docs/examples/package-finder.md +0 -89
- package/docs/examples/postgres.md +0 -91
- package/docs/examples/proc.md +0 -81
- package/docs/examples/process-manager.md +0 -79
- package/docs/examples/python.md +0 -132
- package/docs/examples/repl.md +0 -93
- package/docs/examples/runpod.md +0 -119
- package/docs/examples/secure-shell.md +0 -92
- package/docs/examples/sqlite.md +0 -86
- package/docs/examples/structured-output-with-assistants.md +0 -144
- package/docs/examples/telegram.md +0 -77
- package/docs/examples/tts.md +0 -86
- package/docs/examples/ui.md +0 -80
- package/docs/examples/vault.md +0 -70
- package/docs/examples/vm.md +0 -86
- package/docs/examples/websocket-ask-and-reply-example.md +0 -128
- package/docs/examples/yaml-tree.md +0 -93
- package/docs/examples/yaml.md +0 -104
- package/docs/ideas/assistant-factory-pattern.md +0 -142
- package/docs/in-memory-fs.md +0 -4
- package/docs/introspection-audit.md +0 -49
- package/docs/introspection.md +0 -164
- package/docs/mcp/readme.md +0 -162
- package/docs/models.ts +0 -41
- package/docs/philosophy.md +0 -86
- package/docs/principles.md +0 -7
- package/docs/prompts/audit-codebase-for-failures-to-use-the-container.md +0 -34
- package/docs/prompts/check-for-undocumented-features.md +0 -27
- package/docs/prompts/mcp-test-easy-command.md +0 -27
- package/docs/scaffolds/client.md +0 -149
- package/docs/scaffolds/command.md +0 -120
- package/docs/scaffolds/endpoint.md +0 -171
- package/docs/scaffolds/feature.md +0 -158
- package/docs/scaffolds/selector.md +0 -91
- package/docs/scaffolds/server.md +0 -196
- package/docs/selectors.md +0 -115
- package/docs/sessions/custom-command/attempt-log-2.md +0 -195
- package/docs/sessions/file-watcher-pipeline/attempt-log-1.md +0 -728
- package/docs/sessions/file-watcher-pipeline/attempt-log-2.md +0 -555
- package/docs/sessions/grep-audit-report/attempt-log-1.md +0 -289
- package/docs/sessions/multi-feature-dashboard/attempt-log-2.md +0 -679
- package/docs/sessions/rest-api-server-with-client/attempt-log-1.md +0 -1
- package/docs/sessions/rest-api-server-with-client/attempt-log-3.md +0 -920
- package/docs/sessions/simple-rest-api/attempt-log-1.md +0 -593
- package/docs/sessions/websocket-serve-and-client/attempt-log-2.md +0 -995
- package/docs/tutorials/00-bootstrap.md +0 -166
- package/docs/tutorials/01-getting-started.md +0 -106
- package/docs/tutorials/02-container.md +0 -210
- package/docs/tutorials/03-scripts.md +0 -194
- package/docs/tutorials/04-features-overview.md +0 -196
- package/docs/tutorials/05-state-and-events.md +0 -171
- package/docs/tutorials/06-servers.md +0 -157
- package/docs/tutorials/07-endpoints.md +0 -198
- package/docs/tutorials/08-commands.md +0 -252
- package/docs/tutorials/09-clients.md +0 -162
- package/docs/tutorials/10-creating-features.md +0 -203
- package/docs/tutorials/11-contentbase.md +0 -191
- package/docs/tutorials/12-assistants.md +0 -215
- package/docs/tutorials/13-introspection.md +0 -157
- package/docs/tutorials/14-type-system.md +0 -174
- package/docs/tutorials/15-project-patterns.md +0 -222
- package/docs/tutorials/16-google-features.md +0 -534
- package/docs/tutorials/17-tui-blocks.md +0 -530
- package/docs/tutorials/18-semantic-search.md +0 -334
- package/docs/tutorials/19-python-sessions.md +0 -401
- package/docs/tutorials/20-browser-esm.md +0 -234
- package/index.ts +0 -1
- package/src/agi/endpoints/ask.ts +0 -60
- package/src/agi/endpoints/conversations/[id].ts +0 -45
- package/src/agi/endpoints/conversations.ts +0 -31
- package/src/agi/endpoints/experts.ts +0 -37
- package/test/assistant-hooks.test.ts +0 -306
- package/test/assistant.test.ts +0 -81
- package/test/bus.test.ts +0 -134
- package/test/clients-servers.test.ts +0 -217
- package/test/command.test.ts +0 -267
- package/test/container-link.test.ts +0 -274
- package/test/conversation.test.ts +0 -220
- package/test/features.test.ts +0 -160
- package/test/fork-and-research.test.ts +0 -450
- package/test/integration.test.ts +0 -787
- package/test/interceptor-chain.test.ts +0 -61
- package/test/node-container.test.ts +0 -121
- package/test/python-session.test.ts +0 -105
- package/test/rate-limit.test.ts +0 -272
- package/test/semantic-search.test.ts +0 -550
- package/test/state.test.ts +0 -121
- package/test/vm-context.test.ts +0 -146
- package/test/vm-loadmodule.test.ts +0 -213
- package/test/websocket-ask.test.ts +0 -101
- package/test-integration/assistant.test.ts +0 -138
- package/test-integration/assistants-manager.test.ts +0 -113
- package/test-integration/claude-code.test.ts +0 -98
- package/test-integration/conversation-history.test.ts +0 -205
- package/test-integration/conversation.test.ts +0 -137
- package/test-integration/elevenlabs.test.ts +0 -55
- package/test-integration/google-services.test.ts +0 -80
- package/test-integration/helpers.ts +0 -89
- package/test-integration/memory.test.ts +0 -204
- package/test-integration/openai-codex.test.ts +0 -93
- package/test-integration/runpod.test.ts +0 -58
- package/test-integration/server-endpoints.test.ts +0 -97
- package/test-integration/telegram.test.ts +0 -46
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import type { EndpointContext } from '../../../endpoint.js'
|
|
3
|
-
|
|
4
|
-
export const path = '/api/conversations/:id'
|
|
5
|
-
export const description = 'Get or delete a specific conversation'
|
|
6
|
-
export const tags = ['conversations']
|
|
7
|
-
|
|
8
|
-
export const getSchema = z.object({
|
|
9
|
-
id: z.string().describe('Conversation ID'),
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
export async function get(parameters: z.infer<typeof getSchema>, ctx: EndpointContext) {
|
|
13
|
-
const container = ctx.container as any
|
|
14
|
-
const history = container.feature('conversationHistory')
|
|
15
|
-
|
|
16
|
-
const record = await history.load(parameters.id)
|
|
17
|
-
|
|
18
|
-
if (!record) {
|
|
19
|
-
ctx.response.status(404)
|
|
20
|
-
return { error: 'Conversation not found' }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return { conversation: record }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const deleteSchema = z.object({
|
|
27
|
-
id: z.string().describe('Conversation ID'),
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
export async function del(parameters: z.infer<typeof deleteSchema>, ctx: EndpointContext) {
|
|
31
|
-
const container = ctx.container as any
|
|
32
|
-
const history = container.feature('conversationHistory')
|
|
33
|
-
|
|
34
|
-
const deleted = await history.delete(parameters.id)
|
|
35
|
-
|
|
36
|
-
if (!deleted) {
|
|
37
|
-
ctx.response.status(404)
|
|
38
|
-
return { error: 'Conversation not found' }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return { deleted: true }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// endpoint system uses 'delete' as the key
|
|
45
|
-
export { del as delete }
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import type { EndpointContext } from '../../endpoint.js'
|
|
3
|
-
|
|
4
|
-
export const path = '/api/conversations'
|
|
5
|
-
export const description = 'List and search saved conversations'
|
|
6
|
-
export const tags = ['conversations']
|
|
7
|
-
|
|
8
|
-
export const getSchema = z.object({
|
|
9
|
-
tag: z.string().optional().describe('Filter by tag'),
|
|
10
|
-
thread: z.string().optional().describe('Filter by thread'),
|
|
11
|
-
model: z.string().optional().describe('Filter by model'),
|
|
12
|
-
query: z.string().optional().describe('Text search across titles, tags, metadata'),
|
|
13
|
-
expert: z.string().optional().describe('Filter by expert name (stored in metadata)'),
|
|
14
|
-
limit: z.coerce.number().optional().describe('Max results'),
|
|
15
|
-
offset: z.coerce.number().optional().describe('Skip N results'),
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
export async function get(parameters: z.infer<typeof getSchema>, ctx: EndpointContext) {
|
|
19
|
-
const container = ctx.container as any
|
|
20
|
-
const history = container.feature('conversationHistory')
|
|
21
|
-
|
|
22
|
-
const { expert, ...searchOpts } = parameters
|
|
23
|
-
|
|
24
|
-
let results = await history.list(searchOpts)
|
|
25
|
-
|
|
26
|
-
if (expert) {
|
|
27
|
-
results = results.filter((m: any) => m.metadata?.expert === expert)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return { conversations: results }
|
|
31
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import type { EndpointContext } from '../../endpoint.js'
|
|
3
|
-
|
|
4
|
-
export const path = '/api/experts'
|
|
5
|
-
export const description = 'List all available experts with their descriptions'
|
|
6
|
-
export const tags = ['experts']
|
|
7
|
-
|
|
8
|
-
export async function get(_parameters: any, ctx: EndpointContext) {
|
|
9
|
-
const container = ctx.container as any
|
|
10
|
-
const fs = container.feature('fs')
|
|
11
|
-
const fileManager = container.feature('fileManager')
|
|
12
|
-
|
|
13
|
-
if (!fileManager.isStarted) {
|
|
14
|
-
await fileManager.start()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const promptFiles = fileManager.match('experts/*/SYSTEM-PROMPT.md')
|
|
18
|
-
const experts: any[] = []
|
|
19
|
-
|
|
20
|
-
for (const relativePath of promptFiles) {
|
|
21
|
-
const name = relativePath.split('/')[1]
|
|
22
|
-
const prompt = await fs.readFileAsync(container.paths.resolve(relativePath))
|
|
23
|
-
const lines = prompt.split('\n').filter((l: string) => l.trim())
|
|
24
|
-
const title = lines[0]?.replace(/^#+\s*/, '') || name
|
|
25
|
-
const description = lines[1] || ''
|
|
26
|
-
|
|
27
|
-
experts.push({
|
|
28
|
-
name,
|
|
29
|
-
title,
|
|
30
|
-
description,
|
|
31
|
-
url: `/api/experts/${name}`,
|
|
32
|
-
askUrl: `/api/experts/${name}/ask`,
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return { experts }
|
|
37
|
-
}
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'bun:test'
|
|
2
|
-
import { AGIContainer } from '../src/agi/container.server'
|
|
3
|
-
import type { Assistant } from '../src/agi/features/assistant'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Helper: create a runtime assistant with no folder, stub the conversation
|
|
7
|
-
* so tests never hit the network, and inject hook functions directly.
|
|
8
|
-
*/
|
|
9
|
-
function makeAssistant(hooks: Record<string, (...args: any[]) => any> = {}) {
|
|
10
|
-
const container = new AGIContainer()
|
|
11
|
-
const assistant = container.feature('assistant', {
|
|
12
|
-
systemPrompt: 'You are a test assistant.',
|
|
13
|
-
model: 'gpt-5',
|
|
14
|
-
}) as Assistant
|
|
15
|
-
|
|
16
|
-
// Inject hooks into state (same shape loadHooks() produces)
|
|
17
|
-
assistant.state.set('hooks', hooks)
|
|
18
|
-
|
|
19
|
-
return assistant
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Start + stub so ask() never touches the network */
|
|
23
|
-
async function startWithStub(assistant: Assistant, pattern: string | RegExp = /.*/, response: string = 'stubbed') {
|
|
24
|
-
await assistant.start()
|
|
25
|
-
assistant.conversation.stub(pattern, response)
|
|
26
|
-
return assistant
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe('Assistant triggerHook', () => {
|
|
30
|
-
it('returns undefined when no hook exists for the name', async () => {
|
|
31
|
-
const assistant = makeAssistant()
|
|
32
|
-
const result = await assistant.triggerHook('nonexistent', 'arg1')
|
|
33
|
-
expect(result).toBeUndefined()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('calls the hook with (assistant, ...args) and awaits it', async () => {
|
|
37
|
-
const calls: any[][] = []
|
|
38
|
-
const assistant = makeAssistant({
|
|
39
|
-
myHook: async (asst: any, a: string, b: number) => {
|
|
40
|
-
calls.push([asst, a, b])
|
|
41
|
-
return 'hook-result'
|
|
42
|
-
},
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const result = await assistant.triggerHook('myHook', 'hello', 42)
|
|
46
|
-
expect(result).toBe('hook-result')
|
|
47
|
-
expect(calls).toHaveLength(1)
|
|
48
|
-
expect(calls[0]![0]).toBe(assistant)
|
|
49
|
-
expect(calls[0]![1]).toBe('hello')
|
|
50
|
-
expect(calls[0]![2]).toBe(42)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('emits hookFired before calling the hook', async () => {
|
|
54
|
-
const events: string[] = []
|
|
55
|
-
const assistant = makeAssistant({
|
|
56
|
-
myHook: async () => { events.push('hook-ran') },
|
|
57
|
-
})
|
|
58
|
-
assistant.on('hookFired', (name: string) => { events.push(`hookFired:${name}`) })
|
|
59
|
-
|
|
60
|
-
await assistant.triggerHook('myHook')
|
|
61
|
-
expect(events).toEqual(['hookFired:myHook', 'hook-ran'])
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('awaits async hooks to completion before returning', async () => {
|
|
65
|
-
let resolved = false
|
|
66
|
-
const assistant = makeAssistant({
|
|
67
|
-
slowHook: async () => {
|
|
68
|
-
await new Promise(r => setTimeout(r, 50))
|
|
69
|
-
resolved = true
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
await assistant.triggerHook('slowHook')
|
|
74
|
-
expect(resolved).toBe(true)
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
describe('Assistant lifecycle hooks', () => {
|
|
79
|
-
it('beforeStart runs before the assistant is started', async () => {
|
|
80
|
-
const order: string[] = []
|
|
81
|
-
const assistant = makeAssistant({
|
|
82
|
-
beforeStart: async () => { order.push('beforeStart') },
|
|
83
|
-
started: async () => { order.push('started') },
|
|
84
|
-
afterStart: async () => { order.push('afterStart') },
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
await assistant.start()
|
|
88
|
-
expect(order).toEqual(['beforeStart', 'started', 'afterStart'])
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('afterStart blocks start() until complete', async () => {
|
|
92
|
-
let afterStartDone = false
|
|
93
|
-
const assistant = makeAssistant({
|
|
94
|
-
afterStart: async () => {
|
|
95
|
-
await new Promise(r => setTimeout(r, 50))
|
|
96
|
-
afterStartDone = true
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
await assistant.start()
|
|
101
|
-
expect(afterStartDone).toBe(true)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('formatSystemPrompt modifies the system prompt before conversation creation', async () => {
|
|
105
|
-
const assistant = makeAssistant({
|
|
106
|
-
formatSystemPrompt: async (_asst: any, prompt: string) => {
|
|
107
|
-
return prompt + '\nExtra instructions.'
|
|
108
|
-
},
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
await assistant.start()
|
|
112
|
-
expect(assistant.systemPrompt).toContain('Extra instructions.')
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
describe('Assistant ask hooks', () => {
|
|
117
|
-
it('beforeAsk fires on every ask() call', async () => {
|
|
118
|
-
let callCount = 0
|
|
119
|
-
const assistant = makeAssistant({
|
|
120
|
-
beforeAsk: async () => { callCount++ },
|
|
121
|
-
})
|
|
122
|
-
await startWithStub(assistant)
|
|
123
|
-
|
|
124
|
-
await assistant.ask('first')
|
|
125
|
-
await assistant.ask('second')
|
|
126
|
-
expect(callCount).toBe(2)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('beforeAsk can rewrite the question via return value', async () => {
|
|
130
|
-
const questionsReceived: string[] = []
|
|
131
|
-
const assistant = makeAssistant({
|
|
132
|
-
beforeAsk: async (_asst: any, question: string) => {
|
|
133
|
-
return question + ' (rewritten)'
|
|
134
|
-
},
|
|
135
|
-
})
|
|
136
|
-
await assistant.start()
|
|
137
|
-
|
|
138
|
-
// Stub that captures the actual question sent to the conversation
|
|
139
|
-
assistant.conversation.on('userMessage', (content: any) => {
|
|
140
|
-
questionsReceived.push(typeof content === 'string' ? content : JSON.stringify(content))
|
|
141
|
-
})
|
|
142
|
-
assistant.conversation.stub(/.*/, 'ok')
|
|
143
|
-
|
|
144
|
-
await assistant.ask('hello')
|
|
145
|
-
expect(questionsReceived[0]).toContain('(rewritten)')
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it('beforeInitialAsk fires only on the first ask()', async () => {
|
|
149
|
-
let callCount = 0
|
|
150
|
-
const assistant = makeAssistant({
|
|
151
|
-
beforeInitialAsk: async () => { callCount++ },
|
|
152
|
-
})
|
|
153
|
-
await startWithStub(assistant)
|
|
154
|
-
|
|
155
|
-
await assistant.ask('first')
|
|
156
|
-
await assistant.ask('second')
|
|
157
|
-
await assistant.ask('third')
|
|
158
|
-
expect(callCount).toBe(1)
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
it('answered hook fires after the response is produced', async () => {
|
|
162
|
-
let hookResponse: string | undefined
|
|
163
|
-
const assistant = makeAssistant({
|
|
164
|
-
answered: async (_asst: any, result: string) => {
|
|
165
|
-
hookResponse = result
|
|
166
|
-
},
|
|
167
|
-
})
|
|
168
|
-
await startWithStub(assistant, /.*/, 'the answer')
|
|
169
|
-
|
|
170
|
-
await assistant.ask('question')
|
|
171
|
-
expect(hookResponse).toBe('the answer')
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('answered hook is awaited before ask() returns', async () => {
|
|
175
|
-
let hookDone = false
|
|
176
|
-
const assistant = makeAssistant({
|
|
177
|
-
answered: async () => {
|
|
178
|
-
await new Promise(r => setTimeout(r, 50))
|
|
179
|
-
hookDone = true
|
|
180
|
-
},
|
|
181
|
-
})
|
|
182
|
-
await startWithStub(assistant)
|
|
183
|
-
|
|
184
|
-
await assistant.ask('question')
|
|
185
|
-
expect(hookDone).toBe(true)
|
|
186
|
-
})
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
describe('Assistant tool hooks', () => {
|
|
190
|
-
it('beforeToolCall hook fires before tool execution', async () => {
|
|
191
|
-
const hookCalls: any[] = []
|
|
192
|
-
const assistant = makeAssistant({
|
|
193
|
-
beforeToolCall: async (_asst: any, ctx: any) => {
|
|
194
|
-
hookCalls.push({ name: ctx.name, args: { ...ctx.args } })
|
|
195
|
-
},
|
|
196
|
-
})
|
|
197
|
-
await assistant.start()
|
|
198
|
-
|
|
199
|
-
// Add a simple tool and stub a response that triggers it
|
|
200
|
-
assistant.addTool('echo', {
|
|
201
|
-
description: 'Echo tool',
|
|
202
|
-
parameters: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
|
|
203
|
-
handler: async (args: any) => args.text,
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
// Directly invoke the toolExecutor to test hooks without needing model responses
|
|
207
|
-
const handler = async (args: any) => args.text
|
|
208
|
-
await assistant.conversation.toolExecutor!('echo', { text: 'hello' }, handler)
|
|
209
|
-
|
|
210
|
-
expect(hookCalls).toHaveLength(1)
|
|
211
|
-
expect(hookCalls[0]!.name).toBe('echo')
|
|
212
|
-
expect(hookCalls[0]!.args.text).toBe('hello')
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
it('afterToolCall hook fires after tool execution with result', async () => {
|
|
216
|
-
const hookCalls: any[] = []
|
|
217
|
-
const assistant = makeAssistant({
|
|
218
|
-
afterToolCall: async (_asst: any, ctx: any) => {
|
|
219
|
-
hookCalls.push({ name: ctx.name, result: ctx.result })
|
|
220
|
-
},
|
|
221
|
-
})
|
|
222
|
-
await assistant.start()
|
|
223
|
-
|
|
224
|
-
const handler = async (args: any) => args.text
|
|
225
|
-
await assistant.conversation.toolExecutor!('echo', { text: 'world' }, handler)
|
|
226
|
-
|
|
227
|
-
expect(hookCalls).toHaveLength(1)
|
|
228
|
-
expect(hookCalls[0]!.name).toBe('echo')
|
|
229
|
-
expect(hookCalls[0]!.result).toBe('world')
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
it('beforeToolCall can modify args via ctx mutation', async () => {
|
|
233
|
-
const assistant = makeAssistant({
|
|
234
|
-
beforeToolCall: async (_asst: any, ctx: any) => {
|
|
235
|
-
ctx.args.text = 'intercepted'
|
|
236
|
-
},
|
|
237
|
-
})
|
|
238
|
-
await assistant.start()
|
|
239
|
-
|
|
240
|
-
let receivedArgs: any
|
|
241
|
-
const handler = async (args: any) => { receivedArgs = args; return 'ok' }
|
|
242
|
-
await assistant.conversation.toolExecutor!('echo', { text: 'original' }, handler)
|
|
243
|
-
|
|
244
|
-
expect(receivedArgs.text).toBe('intercepted')
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
it('beforeToolCall can skip execution via ctx.skip', async () => {
|
|
248
|
-
const assistant = makeAssistant({
|
|
249
|
-
beforeToolCall: async (_asst: any, ctx: any) => {
|
|
250
|
-
ctx.skip = true
|
|
251
|
-
ctx.result = 'skipped-by-hook'
|
|
252
|
-
},
|
|
253
|
-
})
|
|
254
|
-
await assistant.start()
|
|
255
|
-
|
|
256
|
-
let handlerCalled = false
|
|
257
|
-
const handler = async () => { handlerCalled = true; return 'should not run' }
|
|
258
|
-
const result = await assistant.conversation.toolExecutor!('echo', { text: 'hi' }, handler)
|
|
259
|
-
|
|
260
|
-
expect(handlerCalled).toBe(false)
|
|
261
|
-
expect(result).toBe('skipped-by-hook')
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
it('afterToolCall can modify the result via ctx mutation', async () => {
|
|
265
|
-
const assistant = makeAssistant({
|
|
266
|
-
afterToolCall: async (_asst: any, ctx: any) => {
|
|
267
|
-
ctx.result = 'modified-result'
|
|
268
|
-
},
|
|
269
|
-
})
|
|
270
|
-
await assistant.start()
|
|
271
|
-
|
|
272
|
-
const handler = async () => 'original-result'
|
|
273
|
-
const result = await assistant.conversation.toolExecutor!('echo', {}, handler)
|
|
274
|
-
|
|
275
|
-
expect(result).toBe('modified-result')
|
|
276
|
-
})
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
describe('Assistant forwarded event hooks', () => {
|
|
280
|
-
it('turnStart hook fires before the turnStart event on the assistant bus', async () => {
|
|
281
|
-
const order: string[] = []
|
|
282
|
-
const assistant = makeAssistant({
|
|
283
|
-
turnStart: async () => { order.push('hook') },
|
|
284
|
-
})
|
|
285
|
-
await startWithStub(assistant)
|
|
286
|
-
|
|
287
|
-
assistant.on('turnStart', () => { order.push('event') })
|
|
288
|
-
|
|
289
|
-
await assistant.ask('go')
|
|
290
|
-
expect(order[0]).toBe('hook')
|
|
291
|
-
expect(order[1]).toBe('event')
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
it('response hook fires with the final response text', async () => {
|
|
295
|
-
let hookText: string | undefined
|
|
296
|
-
const assistant = makeAssistant({
|
|
297
|
-
response: async (_asst: any, text: string) => {
|
|
298
|
-
hookText = text
|
|
299
|
-
},
|
|
300
|
-
})
|
|
301
|
-
await startWithStub(assistant, /.*/, 'final answer')
|
|
302
|
-
|
|
303
|
-
await assistant.ask('question')
|
|
304
|
-
expect(hookText).toBe('final answer')
|
|
305
|
-
})
|
|
306
|
-
})
|
package/test/assistant.test.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'bun:test'
|
|
2
|
-
import { AGIContainer } from '../src/agi/container.server'
|
|
3
|
-
|
|
4
|
-
describe('Assistant', () => {
|
|
5
|
-
let container: AGIContainer
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
container = new AGIContainer()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
describe('codingAssistant', () => {
|
|
12
|
-
it('loads a non-empty system prompt from CORE.md', () => {
|
|
13
|
-
const assistant = container.feature('assistant', { folder: 'assistants/codingAssistant' })
|
|
14
|
-
expect(assistant.systemPrompt.length).toBeGreaterThan(0)
|
|
15
|
-
expect(assistant.systemPrompt).toContain('coding assistant')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('loads tools from codingTools feature after start', async () => {
|
|
19
|
-
const assistant = container.feature('assistant', {
|
|
20
|
-
folder: 'assistants/codingAssistant',
|
|
21
|
-
local: true,
|
|
22
|
-
model: 'qwen/qwen3-8b',
|
|
23
|
-
})
|
|
24
|
-
await assistant.start()
|
|
25
|
-
const tools = assistant.availableTools
|
|
26
|
-
expect(tools).toContain('rg')
|
|
27
|
-
expect(tools).toContain('ls')
|
|
28
|
-
expect(tools).toContain('cat')
|
|
29
|
-
expect(tools.length).toBeGreaterThan(0)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('tools have descriptions and parameter schemas', async () => {
|
|
33
|
-
const assistant = container.feature('assistant', {
|
|
34
|
-
folder: 'assistants/codingAssistant',
|
|
35
|
-
local: true,
|
|
36
|
-
model: 'qwen/qwen3-8b',
|
|
37
|
-
})
|
|
38
|
-
await assistant.start()
|
|
39
|
-
const { rg, ls, cat } = assistant.tools
|
|
40
|
-
expect(rg.description.length).toBeGreaterThan(0)
|
|
41
|
-
expect(rg.parameters.type).toBe('object')
|
|
42
|
-
expect(rg.parameters.properties).toHaveProperty('args')
|
|
43
|
-
expect(ls.parameters.properties).toHaveProperty('args')
|
|
44
|
-
expect(cat.parameters.properties).toHaveProperty('args')
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('loads hooks from hooks.ts via the VM', () => {
|
|
48
|
-
const assistant = container.feature('assistant', { folder: 'assistants/codingAssistant' })
|
|
49
|
-
const hooks = assistant.state.get('hooks') as Record<string, Function>
|
|
50
|
-
expect(hooks).toBeDefined()
|
|
51
|
-
expect(typeof hooks.started).toBe('function')
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('hooks fire when the assistant starts', async () => {
|
|
55
|
-
const assistant = container.feature('assistant', {
|
|
56
|
-
folder: 'assistants/codingAssistant',
|
|
57
|
-
local: true,
|
|
58
|
-
model: 'qwen/qwen3-8b',
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// triggerHook emits 'hookFired' with the hook name each time a hook runs
|
|
62
|
-
const fired: string[] = []
|
|
63
|
-
assistant.on('hookFired', (eventName: string) => { fired.push(eventName) })
|
|
64
|
-
|
|
65
|
-
await assistant.start()
|
|
66
|
-
expect(fired).toContain('started')
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('tools are wired into the conversation after start', async () => {
|
|
70
|
-
const assistant = container.feature('assistant', {
|
|
71
|
-
folder: 'assistants/codingAssistant',
|
|
72
|
-
local: true,
|
|
73
|
-
model: 'qwen/qwen3-8b',
|
|
74
|
-
})
|
|
75
|
-
await assistant.start()
|
|
76
|
-
const convTools = assistant.conversation.tools
|
|
77
|
-
expect(Object.keys(convTools)).toContain('rg')
|
|
78
|
-
expect(Object.keys(convTools)).toContain('ls')
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
})
|
package/test/bus.test.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, mock, beforeEach, afterEach } from 'bun:test'
|
|
2
|
-
import { Bus } from '../src/bus'
|
|
3
|
-
|
|
4
|
-
describe('Bus', () => {
|
|
5
|
-
it('emits events to listeners', () => {
|
|
6
|
-
const bus = new Bus()
|
|
7
|
-
const listener = mock()
|
|
8
|
-
bus.on('test', listener)
|
|
9
|
-
bus.emit('test', 'arg1', 'arg2')
|
|
10
|
-
expect(listener).toHaveBeenCalledWith('arg1', 'arg2')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('supports multiple listeners', () => {
|
|
14
|
-
const bus = new Bus()
|
|
15
|
-
const a = mock()
|
|
16
|
-
const b = mock()
|
|
17
|
-
bus.on('event', a)
|
|
18
|
-
bus.on('event', b)
|
|
19
|
-
bus.emit('event', 42)
|
|
20
|
-
expect(a).toHaveBeenCalledWith(42)
|
|
21
|
-
expect(b).toHaveBeenCalledWith(42)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('off removes a specific listener', () => {
|
|
25
|
-
const bus = new Bus()
|
|
26
|
-
const listener = mock()
|
|
27
|
-
bus.on('test', listener)
|
|
28
|
-
bus.off('test', listener)
|
|
29
|
-
bus.emit('test')
|
|
30
|
-
expect(listener).not.toHaveBeenCalled()
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('off without listener removes all listeners for event', () => {
|
|
34
|
-
const bus = new Bus()
|
|
35
|
-
const a = mock()
|
|
36
|
-
const b = mock()
|
|
37
|
-
bus.on('test', a)
|
|
38
|
-
bus.on('test', b)
|
|
39
|
-
bus.off('test')
|
|
40
|
-
bus.emit('test')
|
|
41
|
-
expect(a).not.toHaveBeenCalled()
|
|
42
|
-
expect(b).not.toHaveBeenCalled()
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('once fires only once', () => {
|
|
46
|
-
const bus = new Bus()
|
|
47
|
-
const listener = mock()
|
|
48
|
-
bus.once('test', listener)
|
|
49
|
-
bus.emit('test', 'first')
|
|
50
|
-
bus.emit('test', 'second')
|
|
51
|
-
expect(listener).toHaveBeenCalledTimes(1)
|
|
52
|
-
expect(listener).toHaveBeenCalledWith('first')
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('waitFor returns a promise that resolves on emit', async () => {
|
|
56
|
-
const bus = new Bus()
|
|
57
|
-
const promise = bus.waitFor('done')
|
|
58
|
-
bus.emit('done', 'result')
|
|
59
|
-
const value = await promise
|
|
60
|
-
expect(value).toBe('result')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('emit with no listeners does not throw', () => {
|
|
64
|
-
const bus = new Bus()
|
|
65
|
-
expect(() => bus.emit('nope')).not.toThrow()
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
describe('event stats tracking', () => {
|
|
69
|
-
it('tracks fire count for events', () => {
|
|
70
|
-
const bus = new Bus()
|
|
71
|
-
bus.emit('click')
|
|
72
|
-
bus.emit('click')
|
|
73
|
-
bus.emit('click')
|
|
74
|
-
const stats = bus.getEventStats('click')
|
|
75
|
-
expect(stats.fireCount).toBe(3)
|
|
76
|
-
expect(stats.event).toBe('click')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('tracks lastFiredAt timestamp', () => {
|
|
80
|
-
const bus = new Bus()
|
|
81
|
-
const before = Date.now()
|
|
82
|
-
bus.emit('ping')
|
|
83
|
-
const after = Date.now()
|
|
84
|
-
const stats = bus.getEventStats('ping')
|
|
85
|
-
expect(stats.lastFiredAt).toBeGreaterThanOrEqual(before)
|
|
86
|
-
expect(stats.lastFiredAt).toBeLessThanOrEqual(after)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('returns zero stats for events that never fired', () => {
|
|
90
|
-
const bus = new Bus()
|
|
91
|
-
const stats = bus.getEventStats('ghost')
|
|
92
|
-
expect(stats.fireCount).toBe(0)
|
|
93
|
-
expect(stats.lastFiredAt).toBeNull()
|
|
94
|
-
expect(stats.firesPerMinute).toBe(0)
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('history returns stats for all fired events', () => {
|
|
98
|
-
const bus = new Bus()
|
|
99
|
-
bus.emit('a')
|
|
100
|
-
bus.emit('b')
|
|
101
|
-
bus.emit('b')
|
|
102
|
-
bus.emit('c')
|
|
103
|
-
const history = bus.history
|
|
104
|
-
expect(history).toHaveLength(3)
|
|
105
|
-
expect(history.find(s => s.event === 'a')?.fireCount).toBe(1)
|
|
106
|
-
expect(history.find(s => s.event === 'b')?.fireCount).toBe(2)
|
|
107
|
-
expect(history.find(s => s.event === 'c')?.fireCount).toBe(1)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('firedEvents lists all event names that have been emitted', () => {
|
|
111
|
-
const bus = new Bus()
|
|
112
|
-
bus.emit('x')
|
|
113
|
-
bus.emit('y')
|
|
114
|
-
bus.emit('x')
|
|
115
|
-
expect(bus.firedEvents).toEqual(['x', 'y'])
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('tracks events even with no listeners', () => {
|
|
119
|
-
const bus = new Bus()
|
|
120
|
-
bus.emit('orphan')
|
|
121
|
-
bus.emit('orphan')
|
|
122
|
-
expect(bus.getEventStats('orphan').fireCount).toBe(2)
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
it('computes firesPerMinute for recent events', () => {
|
|
126
|
-
const bus = new Bus()
|
|
127
|
-
bus.emit('rapid')
|
|
128
|
-
bus.emit('rapid')
|
|
129
|
-
bus.emit('rapid')
|
|
130
|
-
const stats = bus.getEventStats('rapid')
|
|
131
|
-
expect(stats.firesPerMinute).toBe(3)
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
})
|