@soederpop/luca 0.1.2 → 0.2.1
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 +167 -0
- package/CLAUDE.md +2 -0
- package/README.md +3 -0
- package/assistants/codingAssistant/ABOUT.md +3 -0
- package/assistants/codingAssistant/CORE.md +22 -17
- package/assistants/codingAssistant/hooks.ts +17 -4
- package/assistants/codingAssistant/tools.ts +1 -106
- package/assistants/inkbot/ABOUT.md +5 -0
- package/assistants/inkbot/CORE.md +71 -0
- package/assistants/inkbot/hooks.ts +14 -0
- package/assistants/inkbot/tools.ts +47 -0
- package/bun.lock +20 -4
- package/commands/inkbot.ts +353 -0
- package/commands/release.ts +75 -181
- package/dist/agi/container.server.d.ts +63 -0
- package/dist/agi/container.server.d.ts.map +1 -0
- package/dist/agi/endpoints/ask.d.ts +20 -0
- package/dist/agi/endpoints/ask.d.ts.map +1 -0
- package/dist/agi/endpoints/conversations/[id].d.ts +27 -0
- package/dist/agi/endpoints/conversations/[id].d.ts.map +1 -0
- package/dist/agi/endpoints/conversations.d.ts +18 -0
- package/dist/agi/endpoints/conversations.d.ts.map +1 -0
- package/dist/agi/endpoints/experts.d.ts +8 -0
- package/dist/agi/endpoints/experts.d.ts.map +1 -0
- package/dist/agi/feature.d.ts +9 -0
- package/dist/agi/feature.d.ts.map +1 -0
- package/dist/agi/features/assistant.d.ts +509 -0
- package/dist/agi/features/assistant.d.ts.map +1 -0
- package/dist/agi/features/assistants-manager.d.ts +236 -0
- package/dist/agi/features/assistants-manager.d.ts.map +1 -0
- package/dist/agi/features/autonomous-assistant.d.ts +281 -0
- package/dist/agi/features/autonomous-assistant.d.ts.map +1 -0
- package/dist/agi/features/browser-use.d.ts +479 -0
- package/dist/agi/features/browser-use.d.ts.map +1 -0
- package/dist/agi/features/claude-code.d.ts +824 -0
- package/dist/agi/features/claude-code.d.ts.map +1 -0
- package/dist/agi/features/conversation-history.d.ts +245 -0
- package/dist/agi/features/conversation-history.d.ts.map +1 -0
- package/dist/agi/features/conversation.d.ts +464 -0
- package/dist/agi/features/conversation.d.ts.map +1 -0
- package/dist/agi/features/docs-reader.d.ts +72 -0
- package/dist/agi/features/docs-reader.d.ts.map +1 -0
- package/dist/agi/features/file-tools.d.ts +110 -0
- package/dist/agi/features/file-tools.d.ts.map +1 -0
- package/dist/agi/features/luca-coder.d.ts +323 -0
- package/dist/agi/features/luca-coder.d.ts.map +1 -0
- package/dist/agi/features/openai-codex.d.ts +381 -0
- package/dist/agi/features/openai-codex.d.ts.map +1 -0
- package/dist/agi/features/openapi.d.ts +200 -0
- package/dist/agi/features/openapi.d.ts.map +1 -0
- package/dist/agi/features/skills-library.d.ts +167 -0
- package/dist/agi/features/skills-library.d.ts.map +1 -0
- package/dist/agi/index.d.ts +5 -0
- package/dist/agi/index.d.ts.map +1 -0
- package/dist/agi/lib/interceptor-chain.d.ts +44 -0
- package/dist/agi/lib/interceptor-chain.d.ts.map +1 -0
- package/dist/agi/lib/token-counter.d.ts +13 -0
- package/dist/agi/lib/token-counter.d.ts.map +1 -0
- package/dist/bootstrap/generated.d.ts +5 -0
- package/dist/bootstrap/generated.d.ts.map +1 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/bus.d.ts +29 -0
- package/dist/bus.d.ts.map +1 -0
- package/dist/cli/build-info.d.ts +4 -0
- package/dist/cli/build-info.d.ts.map +1 -0
- package/dist/cli/cli.d.ts +3 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/client.d.ts +60 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/clients/civitai/index.d.ts +472 -0
- package/dist/clients/civitai/index.d.ts.map +1 -0
- package/dist/clients/client-template.d.ts +30 -0
- package/dist/clients/client-template.d.ts.map +1 -0
- package/dist/clients/comfyui/index.d.ts +281 -0
- package/dist/clients/comfyui/index.d.ts.map +1 -0
- package/dist/clients/elevenlabs/index.d.ts +197 -0
- package/dist/clients/elevenlabs/index.d.ts.map +1 -0
- package/dist/clients/graph.d.ts +64 -0
- package/dist/clients/graph.d.ts.map +1 -0
- package/dist/clients/openai/index.d.ts +247 -0
- package/dist/clients/openai/index.d.ts.map +1 -0
- package/dist/clients/rest.d.ts +92 -0
- package/dist/clients/rest.d.ts.map +1 -0
- package/dist/clients/supabase/index.d.ts +176 -0
- package/dist/clients/supabase/index.d.ts.map +1 -0
- package/dist/clients/websocket.d.ts +127 -0
- package/dist/clients/websocket.d.ts.map +1 -0
- package/dist/command.d.ts +163 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/commands/bootstrap.d.ts +20 -0
- package/dist/commands/bootstrap.d.ts.map +1 -0
- package/dist/commands/chat.d.ts +37 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/code.d.ts +28 -0
- package/dist/commands/code.d.ts.map +1 -0
- package/dist/commands/console.d.ts +22 -0
- package/dist/commands/console.d.ts.map +1 -0
- package/dist/commands/describe.d.ts +50 -0
- package/dist/commands/describe.d.ts.map +1 -0
- package/dist/commands/eval.d.ts +23 -0
- package/dist/commands/eval.d.ts.map +1 -0
- package/dist/commands/help.d.ts +25 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/index.d.ts +18 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/introspect.d.ts +24 -0
- package/dist/commands/introspect.d.ts.map +1 -0
- package/dist/commands/mcp.d.ts +35 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/prompt.d.ts +38 -0
- package/dist/commands/prompt.d.ts.map +1 -0
- package/dist/commands/run.d.ts +24 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/sandbox-mcp.d.ts +34 -0
- package/dist/commands/sandbox-mcp.d.ts.map +1 -0
- package/dist/commands/save-api-docs.d.ts +21 -0
- package/dist/commands/save-api-docs.d.ts.map +1 -0
- package/dist/commands/scaffold.d.ts +24 -0
- package/dist/commands/scaffold.d.ts.map +1 -0
- package/dist/commands/select.d.ts +22 -0
- package/dist/commands/select.d.ts.map +1 -0
- package/dist/commands/serve.d.ts +29 -0
- package/dist/commands/serve.d.ts.map +1 -0
- package/dist/container-describer.d.ts +144 -0
- package/dist/container-describer.d.ts.map +1 -0
- package/dist/container.d.ts +451 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/endpoint.d.ts +113 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/feature.d.ts +47 -0
- package/dist/feature.d.ts.map +1 -0
- package/dist/graft.d.ts +29 -0
- package/dist/graft.d.ts.map +1 -0
- package/dist/hash-object.d.ts +8 -0
- package/dist/hash-object.d.ts.map +1 -0
- package/dist/helper.d.ts +209 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/introspection/generated.node.d.ts +44623 -0
- package/dist/introspection/generated.node.d.ts.map +1 -0
- package/dist/introspection/generated.web.d.ts +1412 -0
- package/dist/introspection/generated.web.d.ts.map +1 -0
- package/dist/introspection/index.d.ts +156 -0
- package/dist/introspection/index.d.ts.map +1 -0
- package/dist/introspection/scan.d.ts +147 -0
- package/dist/introspection/scan.d.ts.map +1 -0
- package/dist/node/container.d.ts +256 -0
- package/dist/node/container.d.ts.map +1 -0
- package/dist/node/feature.d.ts +9 -0
- package/dist/node/feature.d.ts.map +1 -0
- package/dist/node/features/container-link.d.ts +213 -0
- package/dist/node/features/container-link.d.ts.map +1 -0
- package/dist/node/features/content-db.d.ts +354 -0
- package/dist/node/features/content-db.d.ts.map +1 -0
- package/dist/node/features/disk-cache.d.ts +236 -0
- package/dist/node/features/disk-cache.d.ts.map +1 -0
- package/dist/node/features/dns.d.ts +511 -0
- package/dist/node/features/dns.d.ts.map +1 -0
- package/dist/node/features/docker.d.ts +485 -0
- package/dist/node/features/docker.d.ts.map +1 -0
- package/dist/node/features/downloader.d.ts +73 -0
- package/dist/node/features/downloader.d.ts.map +1 -0
- package/dist/node/features/figlet-fonts.d.ts +4 -0
- package/dist/node/features/figlet-fonts.d.ts.map +1 -0
- package/dist/node/features/file-manager.d.ts +177 -0
- package/dist/node/features/file-manager.d.ts.map +1 -0
- package/dist/node/features/fs.d.ts +635 -0
- package/dist/node/features/fs.d.ts.map +1 -0
- package/dist/node/features/git.d.ts +329 -0
- package/dist/node/features/git.d.ts.map +1 -0
- package/dist/node/features/google-auth.d.ts +200 -0
- package/dist/node/features/google-auth.d.ts.map +1 -0
- package/dist/node/features/google-calendar.d.ts +194 -0
- package/dist/node/features/google-calendar.d.ts.map +1 -0
- package/dist/node/features/google-docs.d.ts +138 -0
- package/dist/node/features/google-docs.d.ts.map +1 -0
- package/dist/node/features/google-drive.d.ts +202 -0
- package/dist/node/features/google-drive.d.ts.map +1 -0
- package/dist/node/features/google-mail.d.ts +221 -0
- package/dist/node/features/google-mail.d.ts.map +1 -0
- package/dist/node/features/google-sheets.d.ts +157 -0
- package/dist/node/features/google-sheets.d.ts.map +1 -0
- package/dist/node/features/grep.d.ts +207 -0
- package/dist/node/features/grep.d.ts.map +1 -0
- package/dist/node/features/helpers.d.ts +236 -0
- package/dist/node/features/helpers.d.ts.map +1 -0
- package/dist/node/features/ink.d.ts +332 -0
- package/dist/node/features/ink.d.ts.map +1 -0
- package/dist/node/features/ipc-socket.d.ts +298 -0
- package/dist/node/features/ipc-socket.d.ts.map +1 -0
- package/dist/node/features/json-tree.d.ts +140 -0
- package/dist/node/features/json-tree.d.ts.map +1 -0
- package/dist/node/features/networking.d.ts +373 -0
- package/dist/node/features/networking.d.ts.map +1 -0
- package/dist/node/features/nlp.d.ts +125 -0
- package/dist/node/features/nlp.d.ts.map +1 -0
- package/dist/node/features/opener.d.ts +93 -0
- package/dist/node/features/opener.d.ts.map +1 -0
- package/dist/node/features/os.d.ts +168 -0
- package/dist/node/features/os.d.ts.map +1 -0
- package/dist/node/features/package-finder.d.ts +419 -0
- package/dist/node/features/package-finder.d.ts.map +1 -0
- package/dist/node/features/postgres.d.ts +173 -0
- package/dist/node/features/postgres.d.ts.map +1 -0
- package/dist/node/features/proc.d.ts +285 -0
- package/dist/node/features/proc.d.ts.map +1 -0
- package/dist/node/features/process-manager.d.ts +427 -0
- package/dist/node/features/process-manager.d.ts.map +1 -0
- package/dist/node/features/python.d.ts +477 -0
- package/dist/node/features/python.d.ts.map +1 -0
- package/dist/node/features/redis.d.ts +247 -0
- package/dist/node/features/redis.d.ts.map +1 -0
- package/dist/node/features/repl.d.ts +84 -0
- package/dist/node/features/repl.d.ts.map +1 -0
- package/dist/node/features/runpod.d.ts +527 -0
- package/dist/node/features/runpod.d.ts.map +1 -0
- package/dist/node/features/secure-shell.d.ts +145 -0
- package/dist/node/features/secure-shell.d.ts.map +1 -0
- package/dist/node/features/semantic-search.d.ts +207 -0
- package/dist/node/features/semantic-search.d.ts.map +1 -0
- package/dist/node/features/sqlite.d.ts +180 -0
- package/dist/node/features/sqlite.d.ts.map +1 -0
- package/dist/node/features/telegram.d.ts +173 -0
- package/dist/node/features/telegram.d.ts.map +1 -0
- package/dist/node/features/transpiler.d.ts +51 -0
- package/dist/node/features/transpiler.d.ts.map +1 -0
- package/dist/node/features/tts.d.ts +108 -0
- package/dist/node/features/tts.d.ts.map +1 -0
- package/dist/node/features/ui.d.ts +562 -0
- package/dist/node/features/ui.d.ts.map +1 -0
- package/dist/node/features/vault.d.ts +90 -0
- package/dist/node/features/vault.d.ts.map +1 -0
- package/dist/node/features/vm.d.ts +285 -0
- package/dist/node/features/vm.d.ts.map +1 -0
- package/dist/node/features/yaml-tree.d.ts +118 -0
- package/dist/node/features/yaml-tree.d.ts.map +1 -0
- package/dist/node/features/yaml.d.ts +127 -0
- package/dist/node/features/yaml.d.ts.map +1 -0
- package/dist/node.d.ts +67 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/python/generated.d.ts +2 -0
- package/dist/python/generated.d.ts.map +1 -0
- package/dist/react/index.d.ts +36 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/registry.d.ts +97 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/scaffolds/generated.d.ts +13 -0
- package/dist/scaffolds/generated.d.ts.map +1 -0
- package/dist/scaffolds/template.d.ts +11 -0
- package/dist/scaffolds/template.d.ts.map +1 -0
- package/dist/schemas/base.d.ts +254 -0
- package/dist/schemas/base.d.ts.map +1 -0
- package/dist/selector.d.ts +130 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/server.d.ts +89 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/servers/express.d.ts +104 -0
- package/dist/servers/express.d.ts.map +1 -0
- package/dist/servers/mcp.d.ts +201 -0
- package/dist/servers/mcp.d.ts.map +1 -0
- package/dist/servers/socket.d.ts +121 -0
- package/dist/servers/socket.d.ts.map +1 -0
- package/dist/state.d.ts +24 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/web/clients/socket.d.ts +37 -0
- package/dist/web/clients/socket.d.ts.map +1 -0
- package/dist/web/container.d.ts +55 -0
- package/dist/web/container.d.ts.map +1 -0
- package/dist/web/extension.d.ts +4 -0
- package/dist/web/extension.d.ts.map +1 -0
- package/dist/web/feature.d.ts +8 -0
- package/dist/web/feature.d.ts.map +1 -0
- package/dist/web/features/asset-loader.d.ts +35 -0
- package/dist/web/features/asset-loader.d.ts.map +1 -0
- package/dist/web/features/container-link.d.ts +167 -0
- package/dist/web/features/container-link.d.ts.map +1 -0
- package/dist/web/features/esbuild.d.ts +51 -0
- package/dist/web/features/esbuild.d.ts.map +1 -0
- package/dist/web/features/helpers.d.ts +140 -0
- package/dist/web/features/helpers.d.ts.map +1 -0
- package/dist/web/features/network.d.ts +69 -0
- package/dist/web/features/network.d.ts.map +1 -0
- package/dist/web/features/speech.d.ts +71 -0
- package/dist/web/features/speech.d.ts.map +1 -0
- package/dist/web/features/vault.d.ts +62 -0
- package/dist/web/features/vault.d.ts.map +1 -0
- package/dist/web/features/vm.d.ts +48 -0
- package/dist/web/features/vm.d.ts.map +1 -0
- package/dist/web/features/voice-recognition.d.ts +96 -0
- package/dist/web/features/voice-recognition.d.ts.map +1 -0
- package/dist/web/shims/isomorphic-vm.d.ts +22 -0
- package/dist/web/shims/isomorphic-vm.d.ts.map +1 -0
- package/docs/apis/features/agi/assistant.md +1 -0
- package/docs/apis/features/agi/assistants-manager.md +62 -2
- package/docs/apis/features/agi/auto-assistant.md +11 -109
- package/docs/apis/features/agi/claude-code.md +138 -0
- package/docs/apis/features/agi/conversation.md +60 -31
- package/docs/apis/features/agi/luca-coder.md +407 -0
- package/docs/apis/features/agi/openapi.md +2 -2
- package/docs/apis/features/agi/skills-library.md +12 -0
- package/docs/apis/features/node/python.md +81 -11
- package/docs/apis/features/node/transpiler.md +74 -0
- package/docs/apis/features/web/esbuild.md +0 -6
- package/docs/apis/servers/mcp.md +2 -2
- package/docs/examples/entity.md +124 -0
- package/docs/ideas/assistant-factory-pattern.md +142 -0
- package/package.json +74 -21
- package/src/agi/container.server.ts +10 -0
- package/src/agi/feature.ts +13 -0
- package/src/agi/features/agent-memory.ts +694 -0
- package/src/agi/features/assistant.ts +37 -26
- package/src/agi/features/assistants-manager.ts +95 -5
- package/src/agi/features/autonomous-assistant.ts +1 -5
- package/src/agi/features/browser-use.ts +32 -2
- package/src/agi/features/claude-code.ts +165 -1
- package/src/agi/features/coding-tools.ts +175 -0
- package/src/agi/features/conversation-history.ts +2 -6
- package/src/agi/features/conversation.ts +95 -3
- package/src/agi/features/docs-reader.ts +2 -1
- package/src/agi/features/file-tools.ts +35 -28
- package/src/agi/features/luca-coder.ts +1 -5
- package/src/agi/features/openai-codex.ts +1 -1
- package/src/agi/features/openapi.ts +3 -3
- package/src/agi/features/skills-library.ts +111 -13
- package/src/agi/lib/interceptor-chain.ts +10 -0
- package/src/agi/lib/token-counter.ts +1 -1
- package/src/bootstrap/generated.ts +126 -1
- package/src/bus.ts +27 -5
- package/src/cli/build-info.ts +2 -2
- package/src/client.ts +2 -2
- package/src/clients/elevenlabs/index.ts +5 -0
- package/src/clients/voicebox/index.ts +300 -0
- package/src/commands/bootstrap.ts +2 -1
- package/src/commands/chat.ts +1 -0
- package/src/commands/code.ts +4 -2
- package/src/commands/prompt.ts +34 -34
- package/src/commands/sandbox-mcp.ts +69 -163
- package/src/commands/save-api-docs.ts +10 -8
- package/src/commands/select.ts +8 -3
- package/src/container-describer.ts +70 -84
- package/src/container.ts +93 -3
- package/src/endpoint.ts +1 -1
- package/src/entity.ts +173 -0
- package/src/feature.ts +3 -3
- package/src/helper.ts +8 -4
- package/src/introspection/generated.agi.ts +3012 -1356
- package/src/introspection/generated.node.ts +179 -33
- package/src/introspection/generated.web.ts +95 -3
- package/src/introspection/scan.ts +1 -1
- package/src/node/container.ts +1 -1
- package/src/node/features/content-db.ts +57 -30
- package/src/node/features/file-manager.ts +10 -9
- package/src/node/features/git.ts +5 -5
- package/src/node/features/helpers.ts +1 -1
- package/src/node/features/json-tree.ts +1 -1
- package/src/node/features/os.ts +3 -3
- package/src/node/features/package-finder.ts +1 -1
- package/src/node/features/process-manager.ts +51 -18
- package/src/node/features/python.ts +3 -3
- package/src/node/features/redis.ts +1 -1
- package/src/node/features/repl.ts +2 -2
- package/src/node/features/transpiler.ts +2 -2
- package/src/node/features/ui.ts +1 -1
- package/src/node/features/vm.ts +3 -3
- package/src/node/features/yaml-tree.ts +1 -1
- package/src/node.ts +1 -0
- package/src/python/generated.ts +1 -1
- package/src/scaffolds/generated.ts +1 -1
- package/src/selector.ts +74 -4
- package/src/server.ts +2 -2
- package/src/servers/mcp.ts +6 -6
- package/src/web/features/helpers.ts +1 -1
- package/src/web/features/network.ts +1 -0
- package/test/assistant.test.ts +14 -5
- package/test/conversation.test.ts +220 -0
- package/test-integration/memory.test.ts +204 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +1 -1
- package/scripts/examples/telegram-ink-ui.ts +0 -302
- package/scripts/examples/using-openai-codex.ts +0 -23
- package/scripts/examples/vm-loading-esm-modules.ts +0 -16
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Feature } from "../feature.js";
|
|
3
|
+
import { NodeContainer } from "../container.js";
|
|
4
|
+
import { Server, Socket } from "net";
|
|
5
|
+
/**
|
|
6
|
+
* Zod schema for the IpcSocket feature state.
|
|
7
|
+
* Tracks the operational mode of the IPC socket (server or client).
|
|
8
|
+
*/
|
|
9
|
+
export declare const IpcStateSchema: z.ZodObject<{
|
|
10
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
12
|
+
client: "client";
|
|
13
|
+
server: "server";
|
|
14
|
+
}>>;
|
|
15
|
+
socketPath: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$loose>;
|
|
17
|
+
export type IpcState = z.infer<typeof IpcStateSchema>;
|
|
18
|
+
export declare const IpcEventsSchema: z.ZodObject<{
|
|
19
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
20
|
+
enabled: z.ZodTuple<[], null>;
|
|
21
|
+
connection: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
22
|
+
disconnection: z.ZodTuple<[z.ZodString], null>;
|
|
23
|
+
message: z.ZodTuple<[z.ZodAny, z.ZodOptional<z.ZodString>], null>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
/** Metadata for a connected client */
|
|
26
|
+
type ClientInfo = {
|
|
27
|
+
socket: Socket;
|
|
28
|
+
id: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
connectedAt: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* IpcSocket Feature - Inter-Process Communication via Unix Domain Sockets
|
|
34
|
+
*
|
|
35
|
+
* This feature provides robust IPC (Inter-Process Communication) capabilities using Unix domain sockets.
|
|
36
|
+
* It supports both server and client modes, allowing processes to communicate efficiently through
|
|
37
|
+
* file system-based socket connections.
|
|
38
|
+
*
|
|
39
|
+
* **Key Features:**
|
|
40
|
+
* - Hub-and-spoke: one server, many named clients with identity tracking
|
|
41
|
+
* - Targeted messaging: sendTo(clientId), broadcast(msg, excludeId)
|
|
42
|
+
* - Request/reply: ask() + reply() with timeout-based correlation
|
|
43
|
+
* - Auto-reconnect: clients reconnect with exponential backoff
|
|
44
|
+
* - Stale socket detection: probeSocket() before listen()
|
|
45
|
+
* - Clean shutdown: stopServer() removes socket file
|
|
46
|
+
*
|
|
47
|
+
* **Server (Hub):**
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const ipc = container.feature('ipcSocket');
|
|
50
|
+
* await ipc.listen('/tmp/hub.sock', true);
|
|
51
|
+
*
|
|
52
|
+
* ipc.on('connection', (clientId, socket) => {
|
|
53
|
+
* console.log('Client joined:', clientId);
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* ipc.on('message', (data, clientId) => {
|
|
57
|
+
* console.log(`From ${clientId}:`, data);
|
|
58
|
+
* // Reply to sender, or ask and wait
|
|
59
|
+
* ipc.sendTo(clientId, { ack: true });
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* **Client (Spoke):**
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const ipc = container.feature('ipcSocket');
|
|
66
|
+
* await ipc.connect('/tmp/hub.sock', { reconnect: true, name: 'worker-1' });
|
|
67
|
+
*
|
|
68
|
+
* // Fire and forget
|
|
69
|
+
* await ipc.send({ type: 'status', ready: true });
|
|
70
|
+
*
|
|
71
|
+
* // Request/reply
|
|
72
|
+
* ipc.on('message', (data) => {
|
|
73
|
+
* if (data.requestId) ipc.reply(data.requestId, { result: 42 });
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @template T - The state type, defaults to IpcState
|
|
78
|
+
* @extends {Feature<T>}
|
|
79
|
+
*/
|
|
80
|
+
export declare class IpcSocket<T extends IpcState = IpcState> extends Feature<T> {
|
|
81
|
+
/** The shortcut path for accessing this feature */
|
|
82
|
+
static shortcut: "features.ipcSocket";
|
|
83
|
+
static stateSchema: z.ZodObject<{
|
|
84
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
85
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
client: "client";
|
|
87
|
+
server: "server";
|
|
88
|
+
}>>;
|
|
89
|
+
socketPath: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$loose>;
|
|
91
|
+
static eventsSchema: z.ZodObject<{
|
|
92
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
93
|
+
enabled: z.ZodTuple<[], null>;
|
|
94
|
+
connection: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
95
|
+
disconnection: z.ZodTuple<[z.ZodString], null>;
|
|
96
|
+
message: z.ZodTuple<[z.ZodAny, z.ZodOptional<z.ZodString>], null>;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
/** The Node.js net Server instance (when in server mode) */
|
|
99
|
+
server?: Server;
|
|
100
|
+
/** Connected clients keyed by client ID (server mode only) */
|
|
101
|
+
protected clients: Map<string, ClientInfo>;
|
|
102
|
+
/** Reverse lookup: socket → clientId */
|
|
103
|
+
private _socketToClient;
|
|
104
|
+
/** Per-socket NDJSON read buffers for accumulating partial lines */
|
|
105
|
+
private _buffers;
|
|
106
|
+
/** Pending request/reply correlation map */
|
|
107
|
+
private _pending;
|
|
108
|
+
/** Default timeout for ask() calls in ms */
|
|
109
|
+
requestTimeoutMs: number;
|
|
110
|
+
/** Reconnection config (client mode) */
|
|
111
|
+
private _reconnect;
|
|
112
|
+
private _socketPath?;
|
|
113
|
+
/**
|
|
114
|
+
* Attaches the IpcSocket feature to a NodeContainer instance.
|
|
115
|
+
* Registers the feature and creates an auto-enabled instance.
|
|
116
|
+
*
|
|
117
|
+
* @param container - The NodeContainer to attach to
|
|
118
|
+
* @returns The container for method chaining
|
|
119
|
+
*/
|
|
120
|
+
static attach(container: NodeContainer & {
|
|
121
|
+
ipcSocket?: IpcSocket;
|
|
122
|
+
}): void;
|
|
123
|
+
/**
|
|
124
|
+
* Checks if the IPC socket is operating in client mode.
|
|
125
|
+
*
|
|
126
|
+
* @returns True if the socket is configured as a client
|
|
127
|
+
*/
|
|
128
|
+
get isClient(): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Checks if the IPC socket is operating in server mode.
|
|
131
|
+
*
|
|
132
|
+
* @returns True if the socket is configured as a server
|
|
133
|
+
*/
|
|
134
|
+
get isServer(): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Returns the number of currently connected clients (server mode).
|
|
137
|
+
*/
|
|
138
|
+
get clientCount(): number;
|
|
139
|
+
/**
|
|
140
|
+
* Returns info about all connected clients (server mode).
|
|
141
|
+
*/
|
|
142
|
+
get connectedClients(): Array<{
|
|
143
|
+
id: string;
|
|
144
|
+
name?: string;
|
|
145
|
+
connectedAt: number;
|
|
146
|
+
}>;
|
|
147
|
+
/**
|
|
148
|
+
* Starts the IPC server listening on the specified socket path.
|
|
149
|
+
*
|
|
150
|
+
* This method sets up a Unix domain socket server that can accept multiple client connections.
|
|
151
|
+
* Each connected client is tracked, and the server automatically handles connection lifecycle
|
|
152
|
+
* events. Messages received from clients are JSON-parsed and emitted as 'message' events.
|
|
153
|
+
*
|
|
154
|
+
* **Server Behavior:**
|
|
155
|
+
* - Tracks all connected clients in the sockets Set
|
|
156
|
+
* - Automatically removes clients when they disconnect
|
|
157
|
+
* - JSON-parses incoming messages and emits 'message' events
|
|
158
|
+
* - Emits 'connection' events when clients connect
|
|
159
|
+
* - Prevents starting multiple servers on the same instance
|
|
160
|
+
*
|
|
161
|
+
* **Socket File Management:**
|
|
162
|
+
* - Resolves the socket path relative to the container's working directory
|
|
163
|
+
* - Optionally removes existing socket files to prevent "address in use" errors
|
|
164
|
+
* - Throws error if socket file exists and removeLock is false
|
|
165
|
+
*
|
|
166
|
+
* @param socketPath - The file system path for the Unix domain socket
|
|
167
|
+
* @param removeLock - Whether to remove existing socket file (default: false)
|
|
168
|
+
* @returns Promise resolving to the created Node.js Server instance
|
|
169
|
+
*
|
|
170
|
+
* @throws {Error} When already in client mode, server already running, or socket file exists
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Basic server setup
|
|
175
|
+
* const server = await ipc.listen('/tmp/myapp.sock');
|
|
176
|
+
*
|
|
177
|
+
* // With automatic lock removal
|
|
178
|
+
* const server = await ipc.listen('/tmp/myapp.sock', true);
|
|
179
|
+
*
|
|
180
|
+
* // Handle connections and messages
|
|
181
|
+
* ipc.on('connection', (socket) => {
|
|
182
|
+
* console.log('New client connected');
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* ipc.on('message', (data) => {
|
|
186
|
+
* console.log('Received message:', data);
|
|
187
|
+
* // Echo back to all clients
|
|
188
|
+
* ipc.broadcast({ echo: data });
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
listen(socketPath: string, removeLock?: boolean): Promise<Server>;
|
|
193
|
+
/**
|
|
194
|
+
* Stops the IPC server and cleans up all connections.
|
|
195
|
+
*
|
|
196
|
+
* This method gracefully shuts down the server by:
|
|
197
|
+
* 1. Closing the server listener
|
|
198
|
+
* 2. Destroying all active client connections
|
|
199
|
+
* 3. Clearing the sockets tracking set
|
|
200
|
+
* 4. Resetting the server instance
|
|
201
|
+
*
|
|
202
|
+
* @returns Promise that resolves when the server is fully stopped
|
|
203
|
+
*
|
|
204
|
+
* @throws {Error} When no server is currently running
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Graceful shutdown
|
|
209
|
+
* try {
|
|
210
|
+
* await ipc.stopServer();
|
|
211
|
+
* console.log('IPC server stopped successfully');
|
|
212
|
+
* } catch (error) {
|
|
213
|
+
* console.error('Failed to stop server:', error.message);
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
stopServer(): Promise<void>;
|
|
218
|
+
/** The client connection socket (client mode only) */
|
|
219
|
+
_connection?: Socket;
|
|
220
|
+
/**
|
|
221
|
+
* Gets the current client connection socket.
|
|
222
|
+
*
|
|
223
|
+
* @returns The active Socket connection, or undefined if not connected
|
|
224
|
+
*/
|
|
225
|
+
get connection(): Socket | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* Broadcasts a message to all connected clients (server mode only).
|
|
228
|
+
*
|
|
229
|
+
* @param message - The message object to broadcast
|
|
230
|
+
* @param exclude - Optional client ID to exclude from broadcast
|
|
231
|
+
* @returns This instance for method chaining
|
|
232
|
+
*/
|
|
233
|
+
broadcast(message: any, exclude?: string): this;
|
|
234
|
+
/**
|
|
235
|
+
* Sends a message to a specific client by ID (server mode only).
|
|
236
|
+
*
|
|
237
|
+
* @param clientId - The target client ID
|
|
238
|
+
* @param message - The message to send
|
|
239
|
+
* @returns True if the message was sent, false if client not found or not writable
|
|
240
|
+
*/
|
|
241
|
+
sendTo(clientId: string, message: any): boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Fire-and-forget: sends a message to the server (client mode only).
|
|
244
|
+
* For server→client, use sendTo() or broadcast().
|
|
245
|
+
*
|
|
246
|
+
* @param message - The message to send
|
|
247
|
+
*/
|
|
248
|
+
send(message: any): Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* Sends a message and waits for a correlated reply.
|
|
251
|
+
* Works in both client and server mode.
|
|
252
|
+
*
|
|
253
|
+
* The recipient should call `reply(requestId, response)` to respond.
|
|
254
|
+
*
|
|
255
|
+
* @param message - The message to send
|
|
256
|
+
* @param options - Optional: clientId (server mode target), timeoutMs
|
|
257
|
+
* @returns The reply data
|
|
258
|
+
*/
|
|
259
|
+
ask(message: any, options?: {
|
|
260
|
+
clientId?: string;
|
|
261
|
+
timeoutMs?: number;
|
|
262
|
+
}): Promise<any>;
|
|
263
|
+
/**
|
|
264
|
+
* Sends a reply to a previous ask() call, correlated by requestId.
|
|
265
|
+
*
|
|
266
|
+
* @param requestId - The requestId from the incoming message
|
|
267
|
+
* @param data - The reply payload
|
|
268
|
+
* @param clientId - Target client (server mode; for client mode, omit)
|
|
269
|
+
*/
|
|
270
|
+
reply(requestId: string, data: any, clientId?: string): void;
|
|
271
|
+
/** The server-assigned client ID (client mode only) */
|
|
272
|
+
clientId?: string;
|
|
273
|
+
/**
|
|
274
|
+
* Connects to an IPC server at the specified socket path (client mode).
|
|
275
|
+
*
|
|
276
|
+
* @param socketPath - Path to the server's Unix domain socket
|
|
277
|
+
* @param options - Optional: reconnect (enable auto-reconnect), name (identify this client)
|
|
278
|
+
* @returns The established Socket connection
|
|
279
|
+
*/
|
|
280
|
+
connect(socketPath: string, options?: {
|
|
281
|
+
reconnect?: boolean;
|
|
282
|
+
name?: string;
|
|
283
|
+
}): Promise<Socket>;
|
|
284
|
+
private _doConnect;
|
|
285
|
+
private _scheduleReconnect;
|
|
286
|
+
/**
|
|
287
|
+
* Disconnects the client and stops any reconnection attempts.
|
|
288
|
+
*/
|
|
289
|
+
disconnect(): void;
|
|
290
|
+
/**
|
|
291
|
+
* Probe an existing socket to see if a live listener is behind it.
|
|
292
|
+
* Attempts a quick connect — if it succeeds, someone is listening.
|
|
293
|
+
*/
|
|
294
|
+
probeSocket(socketPath: string): Promise<boolean>;
|
|
295
|
+
private _handleChunk;
|
|
296
|
+
}
|
|
297
|
+
export default IpcSocket;
|
|
298
|
+
//# sourceMappingURL=ipc-socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-socket.d.ts","sourceRoot":"","sources":["../../../src/node/features/ipc-socket.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Feature } from "../feature.js";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for the JsonTree feature state.
|
|
5
|
+
* Extends FeatureStateSchema and allows any additional string-keyed properties for tree data.
|
|
6
|
+
*/
|
|
7
|
+
export declare const JsonTreeStateSchema: z.ZodObject<{
|
|
8
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
}, z.core.$catchall<z.ZodAny>>;
|
|
10
|
+
export type JsonTreeState = z.infer<typeof JsonTreeStateSchema>;
|
|
11
|
+
/**
|
|
12
|
+
* JsonTree Feature - A powerful JSON file tree loader and processor
|
|
13
|
+
*
|
|
14
|
+
* This feature provides functionality to recursively load JSON files from a directory structure
|
|
15
|
+
* and build a hierarchical tree representation. It automatically processes file paths to create
|
|
16
|
+
* a nested object structure where file paths become object property paths.
|
|
17
|
+
*
|
|
18
|
+
* **Key Features:**
|
|
19
|
+
* - Recursive JSON file discovery in directory trees
|
|
20
|
+
* - Automatic path-to-property mapping using camelCase conversion
|
|
21
|
+
* - Integration with FileManager for efficient file operations
|
|
22
|
+
* - State-based tree storage and retrieval
|
|
23
|
+
* - Native JSON parsing for optimal performance
|
|
24
|
+
*
|
|
25
|
+
* **Path Processing:**
|
|
26
|
+
* Files are processed to create a nested object structure:
|
|
27
|
+
* - Directory names become object properties (camelCased)
|
|
28
|
+
* - File names become the final property names (without .json extension)
|
|
29
|
+
* - Nested directories create nested objects
|
|
30
|
+
*
|
|
31
|
+
* **Usage Example:**
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const jsonTree = container.feature('jsonTree', { enable: true });
|
|
34
|
+
* await jsonTree.loadTree('data', 'appData');
|
|
35
|
+
* const userData = jsonTree.tree.appData.users.profiles;
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* **Directory Structure Example:**
|
|
39
|
+
* ```
|
|
40
|
+
* data/
|
|
41
|
+
* users/
|
|
42
|
+
* profiles.json -> tree.data.users.profiles
|
|
43
|
+
* settings.json -> tree.data.users.settings
|
|
44
|
+
* config/
|
|
45
|
+
* app-config.json -> tree.data.config.appConfig
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @template T - The state type, defaults to JsonTreeState
|
|
49
|
+
* @extends {Feature<T>}
|
|
50
|
+
*/
|
|
51
|
+
export declare class JsonTree<T extends JsonTreeState = JsonTreeState> extends Feature<T> {
|
|
52
|
+
/** The shortcut path for accessing this feature */
|
|
53
|
+
static shortcut: "features.jsonTree";
|
|
54
|
+
static stateSchema: z.ZodObject<{
|
|
55
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
56
|
+
}, z.core.$catchall<z.ZodAny>>;
|
|
57
|
+
static optionsSchema: z.ZodObject<{
|
|
58
|
+
name: z.ZodOptional<z.ZodString>;
|
|
59
|
+
_cacheKey: z.ZodOptional<z.ZodString>;
|
|
60
|
+
cached: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
+
enable: z.ZodOptional<z.ZodBoolean>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
/**
|
|
64
|
+
* Loads a tree of JSON files from the specified base path and stores them in state.
|
|
65
|
+
*
|
|
66
|
+
* This method recursively scans the provided directory for JSON files, processes their
|
|
67
|
+
* content, and builds a hierarchical object structure. File paths are converted to
|
|
68
|
+
* camelCase property names, and the resulting tree is stored in the feature's state.
|
|
69
|
+
*
|
|
70
|
+
* **Processing Steps:**
|
|
71
|
+
* 1. Uses FileManager to discover all .json files recursively
|
|
72
|
+
* 2. Reads each file's content using the file system feature
|
|
73
|
+
* 3. Parses JSON content using native JSON.parse()
|
|
74
|
+
* 4. Converts file paths to nested object properties
|
|
75
|
+
* 5. Stores the complete tree in feature state
|
|
76
|
+
*
|
|
77
|
+
* **Path Transformation:**
|
|
78
|
+
* - Removes the base path prefix from file paths
|
|
79
|
+
* - Converts directory/file names to camelCase
|
|
80
|
+
* - Creates nested objects based on directory structure
|
|
81
|
+
* - Removes .json file extension
|
|
82
|
+
*
|
|
83
|
+
* **Example Transformation:**
|
|
84
|
+
* ```
|
|
85
|
+
* config/
|
|
86
|
+
* database/
|
|
87
|
+
* production.json -> tree.config.database.production
|
|
88
|
+
* staging.json -> tree.config.database.staging
|
|
89
|
+
* api/
|
|
90
|
+
* endpoints.json -> tree.config.api.endpoints
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param basePath - The root directory path to scan for JSON files
|
|
94
|
+
* @param key - The key to store the tree under in state (defaults to first segment of basePath)
|
|
95
|
+
* @returns Promise resolving to the complete tree object
|
|
96
|
+
*
|
|
97
|
+
* @throws {Error} When FileManager fails to start or files cannot be read/parsed
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* // Load all JSON files from 'data' directory into state.data
|
|
102
|
+
* await jsonTree.loadTree('data');
|
|
103
|
+
*
|
|
104
|
+
* // Load with custom key
|
|
105
|
+
* await jsonTree.loadTree('app/config', 'configuration');
|
|
106
|
+
*
|
|
107
|
+
* // Access the loaded data
|
|
108
|
+
* const dbConfig = jsonTree.tree.data.database.production;
|
|
109
|
+
* const apiEndpoints = jsonTree.tree.data.api.endpoints;
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
loadTree(basePath: string, key?: string): Promise<Pick<T, Exclude<keyof T, "enabled">>>;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the current tree data, excluding the 'enabled' state property.
|
|
115
|
+
*
|
|
116
|
+
* Returns a clean copy of the tree data without internal state management properties.
|
|
117
|
+
* This provides access to only the JSON tree data that has been loaded through loadTree().
|
|
118
|
+
*
|
|
119
|
+
* @returns The tree object containing all loaded JSON data, organized by keys
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* await jsonTree.loadTree('data');
|
|
124
|
+
* await jsonTree.loadTree('config', 'appConfig');
|
|
125
|
+
*
|
|
126
|
+
* const allTrees = jsonTree.tree;
|
|
127
|
+
* // Returns: {
|
|
128
|
+
* // data: { users: { ... }, products: { ... } },
|
|
129
|
+
* // appConfig: { database: { ... }, api: { ... } }
|
|
130
|
+
* // }
|
|
131
|
+
*
|
|
132
|
+
* // Access specific trees
|
|
133
|
+
* const userData = jsonTree.tree.data.users;
|
|
134
|
+
* const dbConfig = jsonTree.tree.appConfig.database;
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
get tree(): Pick<T, Exclude<keyof T, "enabled">>;
|
|
138
|
+
}
|
|
139
|
+
export default JsonTree;
|
|
140
|
+
//# sourceMappingURL=json-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-tree.d.ts","sourceRoot":"","sources":["../../../src/node/features/json-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;8BAAkD,CAAA;AAClF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,qBAAa,QAAQ,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,CAAE,SAAQ,OAAO,CAAC,CAAC,CAAC;IAE/E,mDAAmD;IACnD,OAAgB,QAAQ,EAAG,mBAAmB,CAAS;IACvD,OAAgB,WAAW;;mCAAsB;IACjD,OAAgB,aAAa;;;;;sBAAuB;IAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAE,MAAgC;IAgCtE;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,IAAI,yCAEP;CACF;AAED,eAAe,QAAQ,CAAA"}
|