@soederpop/luca 0.1.1 → 0.1.3
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/CLAUDE.md +2 -0
- package/assistants/codingAssistant/hooks.ts +3 -0
- package/assistants/inkbot/CORE.md +69 -0
- package/assistants/inkbot/hooks.ts +14 -0
- package/assistants/inkbot/tools.ts +47 -0
- package/commands/inkbot.ts +353 -0
- 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/package.json +73 -21
- package/scripts/test-assistant-hooks.ts +13 -0
- package/src/agi/feature.ts +13 -0
- package/src/agi/features/assistant.ts +36 -25
- package/src/agi/features/assistants-manager.ts +70 -5
- package/src/agi/features/autonomous-assistant.ts +1 -5
- package/src/agi/features/browser-use.ts +2 -2
- package/src/agi/features/claude-code.ts +165 -1
- 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 +2 -2
- 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 +90 -2
- 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/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 +1403 -929
- package/src/introspection/generated.node.ts +127 -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 +3 -3
- 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 +1 -1
- 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 +34 -9
- package/src/node/features/ui.ts +1 -1
- package/src/node/features/vm.ts +6 -5
- 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 +72 -0
- package/test/conversation.test.ts +220 -0
- package/test/vm-loadmodule.test.ts +213 -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,247 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Client } from "@soederpop/luca/client";
|
|
3
|
+
import type { ContainerContext } from "@soederpop/luca/container";
|
|
4
|
+
import OpenAI from "openai";
|
|
5
|
+
export declare const OpenAIClientStateSchema: z.ZodObject<{
|
|
6
|
+
connected: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
requestCount: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
lastRequestTime: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
9
|
+
tokenUsage: z.ZodDefault<z.ZodObject<{
|
|
10
|
+
prompt: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
completion: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
total: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
14
|
+
}, z.core.$loose>;
|
|
15
|
+
export type OpenAIClientState = z.infer<typeof OpenAIClientStateSchema>;
|
|
16
|
+
export declare const OpenAIClientOptionsSchema: z.ZodObject<{
|
|
17
|
+
name: z.ZodOptional<z.ZodString>;
|
|
18
|
+
_cacheKey: z.ZodOptional<z.ZodString>;
|
|
19
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
20
|
+
json: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
22
|
+
organization: z.ZodOptional<z.ZodString>;
|
|
23
|
+
project: z.ZodOptional<z.ZodString>;
|
|
24
|
+
dangerouslyAllowBrowser: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
26
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
maxRetries: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export type OpenAIClientOptions = z.infer<typeof OpenAIClientOptionsSchema>;
|
|
30
|
+
export declare const OpenAIClientEventsSchema: z.ZodObject<{
|
|
31
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
32
|
+
failure: z.ZodTuple<[z.ZodAny], null>;
|
|
33
|
+
connected: z.ZodTuple<[], null>;
|
|
34
|
+
completion: z.ZodTuple<[z.ZodAny], null>;
|
|
35
|
+
embedding: z.ZodTuple<[z.ZodAny], null>;
|
|
36
|
+
image: z.ZodTuple<[z.ZodAny], null>;
|
|
37
|
+
models: z.ZodTuple<[z.ZodAny], null>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
/**
|
|
40
|
+
* OpenAI client — wraps the OpenAI SDK for chat completions, responses API, embeddings, and image generation.
|
|
41
|
+
*
|
|
42
|
+
* Provides convenience methods for common operations while tracking token usage and request counts.
|
|
43
|
+
* Supports both the Chat Completions API and the newer Responses API.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const openai = container.client('openai', { defaultModel: 'gpt-4o' })
|
|
48
|
+
* const answer = await openai.ask('What is the meaning of life?')
|
|
49
|
+
* console.log(answer)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class OpenAIClient extends Client<OpenAIClientState, OpenAIClientOptions> {
|
|
53
|
+
private openai;
|
|
54
|
+
static shortcut: "clients.openai";
|
|
55
|
+
static envVars: string[];
|
|
56
|
+
static stateSchema: z.ZodObject<{
|
|
57
|
+
connected: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
requestCount: z.ZodDefault<z.ZodNumber>;
|
|
59
|
+
lastRequestTime: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
60
|
+
tokenUsage: z.ZodDefault<z.ZodObject<{
|
|
61
|
+
prompt: z.ZodDefault<z.ZodNumber>;
|
|
62
|
+
completion: z.ZodDefault<z.ZodNumber>;
|
|
63
|
+
total: z.ZodDefault<z.ZodNumber>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
}, z.core.$loose>;
|
|
66
|
+
static optionsSchema: z.ZodObject<{
|
|
67
|
+
name: z.ZodOptional<z.ZodString>;
|
|
68
|
+
_cacheKey: z.ZodOptional<z.ZodString>;
|
|
69
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
70
|
+
json: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
72
|
+
organization: z.ZodOptional<z.ZodString>;
|
|
73
|
+
project: z.ZodOptional<z.ZodString>;
|
|
74
|
+
dangerouslyAllowBrowser: z.ZodOptional<z.ZodBoolean>;
|
|
75
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
76
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
maxRetries: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
static eventsSchema: z.ZodObject<{
|
|
80
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
81
|
+
failure: z.ZodTuple<[z.ZodAny], null>;
|
|
82
|
+
connected: z.ZodTuple<[], null>;
|
|
83
|
+
completion: z.ZodTuple<[z.ZodAny], null>;
|
|
84
|
+
embedding: z.ZodTuple<[z.ZodAny], null>;
|
|
85
|
+
image: z.ZodTuple<[z.ZodAny], null>;
|
|
86
|
+
models: z.ZodTuple<[z.ZodAny], null>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
/** Initial state with zeroed token usage counters. */
|
|
89
|
+
get initialState(): OpenAIClientState;
|
|
90
|
+
constructor(options: OpenAIClientOptions, context: ContainerContext);
|
|
91
|
+
private initializeOpenAI;
|
|
92
|
+
/**
|
|
93
|
+
* Test the API connection by listing models.
|
|
94
|
+
*
|
|
95
|
+
* @returns This client instance
|
|
96
|
+
* @throws If the API key is invalid or the connection fails
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* await openai.connect()
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
connect(): Promise<this>;
|
|
104
|
+
/** The default model used for completions, from options or 'gpt-4o'. */
|
|
105
|
+
get defaultModel(): string;
|
|
106
|
+
private updateTokenUsage;
|
|
107
|
+
private updateResponsesTokenUsage;
|
|
108
|
+
private trackRequest;
|
|
109
|
+
/**
|
|
110
|
+
* Create a chat completion using the Chat Completions API.
|
|
111
|
+
*
|
|
112
|
+
* @param messages - Array of chat messages
|
|
113
|
+
* @param options - Additional parameters for the completion
|
|
114
|
+
* @returns The complete chat completion response
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const response = await openai.createChatCompletion([
|
|
119
|
+
* { role: 'system', content: 'You are a helpful assistant.' },
|
|
120
|
+
* { role: 'user', content: 'Hello!' }
|
|
121
|
+
* ])
|
|
122
|
+
* console.log(response.choices[0]?.message?.content)
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
createChatCompletion(messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[], options?: Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams>): Promise<OpenAI.Chat.Completions.ChatCompletion>;
|
|
126
|
+
/**
|
|
127
|
+
* Create a response using the Responses API.
|
|
128
|
+
*
|
|
129
|
+
* @param input - The input prompt or message array
|
|
130
|
+
* @param options - Additional parameters for the response
|
|
131
|
+
* @returns The complete response object
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const response = await openai.createResponse('Explain quantum computing')
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
createResponse(input: OpenAI.Responses.ResponseInput | string, options?: Partial<OpenAI.Responses.ResponseCreateParamsNonStreaming>): Promise<OpenAI.Responses.Response>;
|
|
139
|
+
/**
|
|
140
|
+
* Stream a response using the Responses API.
|
|
141
|
+
*
|
|
142
|
+
* @param input - The input prompt or message array
|
|
143
|
+
* @param options - Additional parameters for the streaming response
|
|
144
|
+
* @returns An async iterable of response stream events
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const stream = await openai.streamResponse('Write a poem')
|
|
149
|
+
* for await (const event of stream) {
|
|
150
|
+
* if (event.type === 'response.output_text.delta') {
|
|
151
|
+
* process.stdout.write(event.delta)
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
streamResponse(input: OpenAI.Responses.ResponseInput | string, options?: Partial<OpenAI.Responses.ResponseCreateParamsStreaming>): Promise<AsyncIterable<OpenAI.Responses.ResponseStreamEvent>>;
|
|
157
|
+
/**
|
|
158
|
+
* Create a legacy text completion.
|
|
159
|
+
*
|
|
160
|
+
* @param prompt - The text prompt to complete
|
|
161
|
+
* @param options - Additional parameters for the completion
|
|
162
|
+
* @returns The complete completion response
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const response = await openai.createCompletion('Once upon a time')
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
createCompletion(prompt: string, options?: Partial<OpenAI.Completions.CompletionCreateParams>): Promise<OpenAI.Completions.Completion>;
|
|
170
|
+
/**
|
|
171
|
+
* Create text embeddings for semantic search or similarity comparisons.
|
|
172
|
+
*
|
|
173
|
+
* @param input - A string or array of strings to embed
|
|
174
|
+
* @param options - Additional parameters (model, etc.)
|
|
175
|
+
* @returns The embedding response with vectors
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const response = await openai.createEmbedding('Hello world')
|
|
180
|
+
* console.log(response.data[0].embedding.length)
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
createEmbedding(input: string | string[], options?: Partial<OpenAI.Embeddings.EmbeddingCreateParams>): Promise<OpenAI.Embeddings.CreateEmbeddingResponse>;
|
|
184
|
+
/**
|
|
185
|
+
* Generate an image from a text prompt using DALL-E.
|
|
186
|
+
*
|
|
187
|
+
* @param prompt - Description of the image to generate
|
|
188
|
+
* @param options - Additional parameters (size, n, etc.)
|
|
189
|
+
* @returns The image response with URLs or base64 data
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const response = await openai.createImage('A sunset over mountains')
|
|
194
|
+
* console.log(response.data[0].url)
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
createImage(prompt: string, options?: Partial<OpenAI.Images.ImageGenerateParams>): Promise<OpenAI.Images.ImagesResponse>;
|
|
198
|
+
/**
|
|
199
|
+
* List all available models.
|
|
200
|
+
*
|
|
201
|
+
* @returns Paginated list of available models
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const models = await openai.listModels()
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
listModels(): Promise<OpenAI.Models.ModelsPage>;
|
|
209
|
+
/**
|
|
210
|
+
* Ask a single question and get a text response.
|
|
211
|
+
*
|
|
212
|
+
* Convenience wrapper around `createChatCompletion` for simple Q&A.
|
|
213
|
+
*
|
|
214
|
+
* @param question - The question to ask
|
|
215
|
+
* @param options - Additional completion parameters
|
|
216
|
+
* @returns The assistant's text response
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const answer = await openai.ask('What is 2 + 2?')
|
|
221
|
+
* console.log(answer) // '4'
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
ask(question: string, options?: Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams>): Promise<string>;
|
|
225
|
+
/**
|
|
226
|
+
* Send a multi-turn conversation and get a text response.
|
|
227
|
+
*
|
|
228
|
+
* Convenience wrapper around `createChatCompletion` that returns just the text.
|
|
229
|
+
*
|
|
230
|
+
* @param messages - Array of chat messages
|
|
231
|
+
* @param options - Additional completion parameters
|
|
232
|
+
* @returns The assistant's text response
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const reply = await openai.chat([
|
|
237
|
+
* { role: 'system', content: 'You are a pirate.' },
|
|
238
|
+
* { role: 'user', content: 'Hello!' }
|
|
239
|
+
* ])
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
chat(messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[], options?: Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams>): Promise<string>;
|
|
243
|
+
/** The underlying OpenAI SDK instance for advanced use cases. */
|
|
244
|
+
get raw(): OpenAI;
|
|
245
|
+
}
|
|
246
|
+
export default OpenAIClient;
|
|
247
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts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D,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;IAoBxC;;;;;;;;;OASG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;IAWrD;;;;;;;;;;;;;;OAcG;IACG,GAAG,CACP,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAM,GACxE,OAAO,CAAC,MAAM,CAAC;IAQlB;;;;;;;;;;;;;;;;OAgBG;IACG,IAAI,CACR,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,EAAE,EAC9D,OAAO,GAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,CAAM,GACxE,OAAO,CAAC,MAAM,CAAC;IAKlB,iEAAiE;IACjE,IAAI,GAAG,IAAI,MAAM,CAEhB;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type AxiosError, type AxiosInstance, type AxiosRequestConfig } from "axios";
|
|
2
|
+
import { Client, type ClientOptions, type ClientState } from '../client.js';
|
|
3
|
+
import type { ContainerContext } from '../container.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
export declare const RestClientEventsSchema: z.ZodObject<{
|
|
6
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
7
|
+
failure: z.ZodTuple<[z.ZodAny], null>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
declare module '../client' {
|
|
10
|
+
interface AvailableClients {
|
|
11
|
+
rest: typeof RestClient;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* HTTP REST client built on top of axios. Provides convenience methods for
|
|
16
|
+
* GET, POST, PUT, PATCH, and DELETE requests with automatic JSON handling,
|
|
17
|
+
* configurable base URL, and error event emission.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const api = container.client('rest', { baseURL: 'https://api.example.com', json: true })
|
|
22
|
+
* const users = await api.get('/users')
|
|
23
|
+
* await api.post('/users', { name: 'Alice' })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class RestClient<T extends ClientState = ClientState, K extends ClientOptions = ClientOptions> extends Client<T, K> {
|
|
27
|
+
axios: AxiosInstance;
|
|
28
|
+
static shortcut: string;
|
|
29
|
+
static eventsSchema: z.ZodObject<{
|
|
30
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
31
|
+
failure: z.ZodTuple<[z.ZodAny], null>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
constructor(options: K, context: ContainerContext);
|
|
34
|
+
beforeRequest(): Promise<void>;
|
|
35
|
+
/** Whether JSON content-type headers should be set automatically. */
|
|
36
|
+
get useJSON(): boolean;
|
|
37
|
+
get baseURL(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Send a PATCH request. Returns the parsed response body directly (not an
|
|
40
|
+
* axios Response wrapper). On HTTP errors, returns the error as JSON instead
|
|
41
|
+
* of throwing.
|
|
42
|
+
* @param url - Request path relative to baseURL
|
|
43
|
+
* @param data - Request body
|
|
44
|
+
* @param options - Additional axios request config
|
|
45
|
+
* @returns Parsed response body
|
|
46
|
+
*/
|
|
47
|
+
patch(url: string, data?: any, options?: AxiosRequestConfig): Promise<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Send a PUT request. Returns the parsed response body directly (not an
|
|
50
|
+
* axios Response wrapper). On HTTP errors, returns the error as JSON instead
|
|
51
|
+
* of throwing.
|
|
52
|
+
* @param url - Request path relative to baseURL
|
|
53
|
+
* @param data - Request body
|
|
54
|
+
* @param options - Additional axios request config
|
|
55
|
+
* @returns Parsed response body
|
|
56
|
+
*/
|
|
57
|
+
put(url: string, data?: any, options?: AxiosRequestConfig): Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Send a POST request. Returns the parsed response body directly (not an
|
|
60
|
+
* axios Response wrapper). On HTTP errors, returns the error as JSON instead
|
|
61
|
+
* of throwing.
|
|
62
|
+
* @param url - Request path relative to baseURL
|
|
63
|
+
* @param data - Request body
|
|
64
|
+
* @param options - Additional axios request config
|
|
65
|
+
* @returns Parsed response body
|
|
66
|
+
*/
|
|
67
|
+
post(url: string, data?: any, options?: AxiosRequestConfig): Promise<any>;
|
|
68
|
+
/**
|
|
69
|
+
* Send a DELETE request. Returns the parsed response body directly (not an
|
|
70
|
+
* axios Response wrapper). On HTTP errors, returns the error as JSON instead
|
|
71
|
+
* of throwing.
|
|
72
|
+
* @param url - Request path relative to baseURL
|
|
73
|
+
* @param params - Query parameters
|
|
74
|
+
* @param options - Additional axios request config
|
|
75
|
+
* @returns Parsed response body
|
|
76
|
+
*/
|
|
77
|
+
delete(url: string, params?: any, options?: AxiosRequestConfig): Promise<any>;
|
|
78
|
+
/**
|
|
79
|
+
* Send a GET request. Returns the parsed response body directly (not an
|
|
80
|
+
* axios Response wrapper). On HTTP errors, returns the error as JSON instead
|
|
81
|
+
* of throwing.
|
|
82
|
+
* @param url - Request path relative to baseURL
|
|
83
|
+
* @param params - Query parameters
|
|
84
|
+
* @param options - Additional axios request config
|
|
85
|
+
* @returns Parsed response body
|
|
86
|
+
*/
|
|
87
|
+
get(url: string, params?: any, options?: AxiosRequestConfig): Promise<any>;
|
|
88
|
+
/** Handle an axios error by emitting 'failure' and returning the error as JSON. */
|
|
89
|
+
handleError(error: AxiosError): Promise<object>;
|
|
90
|
+
}
|
|
91
|
+
export default RestClient;
|
|
92
|
+
//# sourceMappingURL=rest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../src/clients/rest.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC5F,OAAO,EAAE,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E,GAAQ,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC;IAkB3F;;;;;;;;OAQG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAQ,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,GAAG,CAAC;IAkBxF,mFAAmF;IAC7E,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;CAItD;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { Client } from "@soederpop/luca/client";
|
|
2
|
+
import type { ContainerContext } from "@soederpop/luca/container";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { type SupabaseClient as SupabaseSDKClient, type RealtimeChannel } from "@supabase/supabase-js";
|
|
5
|
+
declare module "@soederpop/luca/client" {
|
|
6
|
+
interface AvailableClients {
|
|
7
|
+
supabase: typeof SupabaseClient;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const SupabaseClientOptionsSchema: z.ZodObject<{
|
|
11
|
+
name: z.ZodOptional<z.ZodString>;
|
|
12
|
+
_cacheKey: z.ZodOptional<z.ZodString>;
|
|
13
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
14
|
+
json: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
supabaseUrl: z.ZodString;
|
|
16
|
+
supabaseKey: z.ZodString;
|
|
17
|
+
clientOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export declare const SupabaseClientStateSchema: z.ZodObject<{
|
|
20
|
+
connected: z.ZodDefault<z.ZodBoolean>;
|
|
21
|
+
authenticated: z.ZodDefault<z.ZodBoolean>;
|
|
22
|
+
userId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
userEmail: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
realtimeChannels: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
25
|
+
lastError: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
26
|
+
}, z.core.$loose>;
|
|
27
|
+
export declare const SupabaseClientEventsSchema: z.ZodObject<{
|
|
28
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
29
|
+
failure: z.ZodTuple<[z.ZodAny], null>;
|
|
30
|
+
authStateChange: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
31
|
+
realtimeMessage: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
32
|
+
realtimeStatus: z.ZodTuple<[z.ZodString, z.ZodString], null>;
|
|
33
|
+
error: z.ZodTuple<[z.ZodAny], null>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
export type SupabaseClientOptions = z.infer<typeof SupabaseClientOptionsSchema>;
|
|
36
|
+
export type SupabaseClientState = z.infer<typeof SupabaseClientStateSchema>;
|
|
37
|
+
/**
|
|
38
|
+
* Supabase client for the Luca container system.
|
|
39
|
+
*
|
|
40
|
+
* Wraps the official `@supabase/supabase-js` SDK and exposes it through Luca's
|
|
41
|
+
* typed state, events, and introspection system. The SDK is isomorphic so this
|
|
42
|
+
* single implementation works in both Node and browser containers.
|
|
43
|
+
*
|
|
44
|
+
* Use `client.sdk` for full SDK access, or use the convenience wrappers for
|
|
45
|
+
* common operations (auth, database queries, storage, edge functions, realtime).
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const supabase = container.client('supabase', {
|
|
50
|
+
* supabaseUrl: 'https://xyz.supabase.co',
|
|
51
|
+
* supabaseKey: 'your-anon-key',
|
|
52
|
+
* })
|
|
53
|
+
*
|
|
54
|
+
* // Query data
|
|
55
|
+
* const { data } = await supabase.from('users').select('*')
|
|
56
|
+
*
|
|
57
|
+
* // Auth
|
|
58
|
+
* await supabase.signInWithPassword('user@example.com', 'password')
|
|
59
|
+
*
|
|
60
|
+
* // Realtime
|
|
61
|
+
* supabase.subscribe('changes', 'users', (payload) => {
|
|
62
|
+
* console.log('Change:', payload)
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare class SupabaseClient extends Client<SupabaseClientState, SupabaseClientOptions> {
|
|
67
|
+
static shortcut: "clients.supabase";
|
|
68
|
+
static description: string;
|
|
69
|
+
static stateSchema: z.ZodObject<{
|
|
70
|
+
connected: z.ZodDefault<z.ZodBoolean>;
|
|
71
|
+
authenticated: z.ZodDefault<z.ZodBoolean>;
|
|
72
|
+
userId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
73
|
+
userEmail: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
74
|
+
realtimeChannels: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
75
|
+
lastError: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
76
|
+
}, z.core.$loose>;
|
|
77
|
+
static optionsSchema: z.ZodObject<{
|
|
78
|
+
name: z.ZodOptional<z.ZodString>;
|
|
79
|
+
_cacheKey: z.ZodOptional<z.ZodString>;
|
|
80
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
81
|
+
json: z.ZodOptional<z.ZodBoolean>;
|
|
82
|
+
supabaseUrl: z.ZodString;
|
|
83
|
+
supabaseKey: z.ZodString;
|
|
84
|
+
clientOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
static eventsSchema: z.ZodObject<{
|
|
87
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
88
|
+
failure: z.ZodTuple<[z.ZodAny], null>;
|
|
89
|
+
authStateChange: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
90
|
+
realtimeMessage: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
91
|
+
realtimeStatus: z.ZodTuple<[z.ZodString, z.ZodString], null>;
|
|
92
|
+
error: z.ZodTuple<[z.ZodAny], null>;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
private _sdk;
|
|
95
|
+
private _channels;
|
|
96
|
+
constructor(options: SupabaseClientOptions, context: ContainerContext);
|
|
97
|
+
/** Returns the raw Supabase SDK client for full access to all SDK methods. */
|
|
98
|
+
get sdk(): SupabaseSDKClient<any, any>;
|
|
99
|
+
/**
|
|
100
|
+
* Start a query on a Postgres table or view.
|
|
101
|
+
* @param table - The table or view name to query
|
|
102
|
+
*/
|
|
103
|
+
from(table: string): import("@supabase/postgrest-js").PostgrestQueryBuilder<any, any, any, string, unknown>;
|
|
104
|
+
/**
|
|
105
|
+
* Call a Postgres function (RPC).
|
|
106
|
+
* @param fn - The function name
|
|
107
|
+
* @param params - Arguments to pass to the function
|
|
108
|
+
* @param options - Optional settings (head, get, count)
|
|
109
|
+
*/
|
|
110
|
+
rpc(fn: string, params?: Record<string, unknown>, options?: {
|
|
111
|
+
head?: boolean;
|
|
112
|
+
get?: boolean;
|
|
113
|
+
count?: "exact" | "planned" | "estimated";
|
|
114
|
+
}): import("@supabase/postgrest-js").PostgrestFilterBuilder<any, any, any, any, string, null, "RPC">;
|
|
115
|
+
/** Sign in with email and password. */
|
|
116
|
+
signInWithPassword(email: string, password: string): Promise<import("@supabase/auth-js").AuthTokenResponsePassword>;
|
|
117
|
+
/** Create a new user account with email and password. */
|
|
118
|
+
signUp(email: string, password: string): Promise<import("@supabase/auth-js").AuthResponse>;
|
|
119
|
+
/** Sign the current user out. */
|
|
120
|
+
signOut(): Promise<{
|
|
121
|
+
error: import("@supabase/auth-js").AuthError | null;
|
|
122
|
+
}>;
|
|
123
|
+
/** Get the current session, if any. */
|
|
124
|
+
getSession(): Promise<{
|
|
125
|
+
data: {
|
|
126
|
+
session: import("@supabase/auth-js").Session;
|
|
127
|
+
};
|
|
128
|
+
error: null;
|
|
129
|
+
} | {
|
|
130
|
+
data: {
|
|
131
|
+
session: null;
|
|
132
|
+
};
|
|
133
|
+
error: import("@supabase/auth-js").AuthError;
|
|
134
|
+
} | {
|
|
135
|
+
data: {
|
|
136
|
+
session: null;
|
|
137
|
+
};
|
|
138
|
+
error: null;
|
|
139
|
+
}>;
|
|
140
|
+
/** Get the current user, if any. */
|
|
141
|
+
getUser(): Promise<import("@supabase/auth-js").UserResponse>;
|
|
142
|
+
/** Returns the Supabase Storage client for managing buckets and files. */
|
|
143
|
+
get storage(): import("@supabase/storage-js").StorageClient;
|
|
144
|
+
/** Returns the Supabase Functions client. */
|
|
145
|
+
get functions(): import("@supabase/functions-js").FunctionsClient;
|
|
146
|
+
/** Invoke a Supabase Edge Function by name. */
|
|
147
|
+
invoke(name: string, body?: any): Promise<import("@supabase/functions-js").FunctionsResponse<any>>;
|
|
148
|
+
/**
|
|
149
|
+
* Subscribe to realtime changes on a Postgres table.
|
|
150
|
+
* @param channelName - A name for this subscription channel
|
|
151
|
+
* @param table - The table to listen to
|
|
152
|
+
* @param callback - Called with the payload on each change
|
|
153
|
+
* @param event - The event type to listen for (default: all changes)
|
|
154
|
+
*/
|
|
155
|
+
subscribe(channelName: string, table: string, callback: (payload: any) => void, event?: "INSERT" | "UPDATE" | "DELETE" | "*"): RealtimeChannel;
|
|
156
|
+
/**
|
|
157
|
+
* Unsubscribe and remove a realtime channel by name.
|
|
158
|
+
* @param channelName - The channel name to remove
|
|
159
|
+
*/
|
|
160
|
+
unsubscribe(channelName: string): Promise<void>;
|
|
161
|
+
/** Unsubscribe and remove all realtime channels. */
|
|
162
|
+
unsubscribeAll(): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Connect is a no-op since the Supabase SDK initializes on construction.
|
|
165
|
+
* The client is ready to use immediately after creation.
|
|
166
|
+
*/
|
|
167
|
+
connect(): Promise<this>;
|
|
168
|
+
/**
|
|
169
|
+
* Disconnect by signing out and removing all realtime channels.
|
|
170
|
+
*/
|
|
171
|
+
disconnect(): Promise<void>;
|
|
172
|
+
private _syncChannelState;
|
|
173
|
+
private _setError;
|
|
174
|
+
}
|
|
175
|
+
export default SupabaseClient;
|
|
176
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/clients/supabase/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACP,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,EAEL,KAAK,cAAc,IAAI,iBAAiB,EAExC,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAU,gBAAgB;QACxB,QAAQ,EAAE,OAAO,cAAc,CAAC;KACjC;CACF;AAMD,eAAO,MAAM,2BAA2B;;;;;;;;iBAaa,CAAC;AAEtD,eAAO,MAAM,yBAAyB;;;;;;;iBAwBF,CAAC;AAErC,eAAO,MAAM,0BAA0B;;;;;;;iBAsBF,CAAC;AAEtC,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAM5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,cAAe,SAAQ,MAAM,CACxC,mBAAmB,EACnB,qBAAqB,CACtB;IACC,OAAgB,QAAQ,EAAG,kBAAkB,CAAU;IACvD,OAAgB,WAAW,SAC6E;IAExG,OAAgB,WAAW;;;;;;;sBAA6B;IACxD,OAAgB,aAAa;;;;;;;;sBAA+B;IAC5D,OAAgB,YAAY;;;;;;;sBAA8B;IAI1D,OAAO,CAAC,IAAI,CAA+B;IAC3C,OAAO,CAAC,SAAS,CAAsC;gBAE3C,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,gBAAgB;I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AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Client } from '../client.js';
|
|
3
|
+
import type { ContainerContext } from '../container.js';
|
|
4
|
+
import { WebSocketClientStateSchema, WebSocketClientOptionsSchema } from '../schemas/base.js';
|
|
5
|
+
export type WebSocketClientState = z.infer<typeof WebSocketClientStateSchema>;
|
|
6
|
+
export type WebSocketClientOptions = z.infer<typeof WebSocketClientOptionsSchema>;
|
|
7
|
+
declare module '../client' {
|
|
8
|
+
interface AvailableClients {
|
|
9
|
+
websocket: typeof WebSocketClient;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* WebSocket client that bridges raw WebSocket events to Luca's Helper event bus,
|
|
14
|
+
* providing a clean interface for sending/receiving messages, tracking connection
|
|
15
|
+
* state, and optional auto-reconnection with exponential backoff.
|
|
16
|
+
*
|
|
17
|
+
* Supports ask/reply semantics when paired with the Luca WebSocket server.
|
|
18
|
+
* The client can `ask(type, data)` the server and await a typed response.
|
|
19
|
+
* Incoming messages with a `requestId` are treated as asks from the server
|
|
20
|
+
* and can be answered with `send({ replyTo: requestId, data })`. Requests
|
|
21
|
+
* time out if no reply arrives within the configurable window.
|
|
22
|
+
*
|
|
23
|
+
* Events emitted:
|
|
24
|
+
* - `open` — connection established
|
|
25
|
+
* - `message` — message received (JSON-parsed when possible)
|
|
26
|
+
* - `close` — connection closed (with code and reason)
|
|
27
|
+
* - `error` — connection error
|
|
28
|
+
* - `reconnecting` — attempting reconnection (with attempt number)
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const ws = container.client('websocket', {
|
|
33
|
+
* baseURL: 'ws://localhost:8080',
|
|
34
|
+
* reconnect: true,
|
|
35
|
+
* maxReconnectAttempts: 5
|
|
36
|
+
* })
|
|
37
|
+
* ws.on('message', (data) => console.log('Received:', data))
|
|
38
|
+
* await ws.connect()
|
|
39
|
+
* await ws.send({ type: 'hello' })
|
|
40
|
+
*
|
|
41
|
+
* // ask/reply: request data from the server
|
|
42
|
+
* const result = await ws.ask('getUser', { id: 42 })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export interface PendingRequest<T = any> {
|
|
46
|
+
resolve: (value: T) => void;
|
|
47
|
+
reject: (reason: any) => void;
|
|
48
|
+
timer: ReturnType<typeof setTimeout>;
|
|
49
|
+
}
|
|
50
|
+
export declare class WebSocketClient<T extends WebSocketClientState = WebSocketClientState, K extends WebSocketClientOptions = WebSocketClientOptions> extends Client<T, K> {
|
|
51
|
+
ws: WebSocket;
|
|
52
|
+
_intentionalClose: boolean;
|
|
53
|
+
_pending: Map<string, PendingRequest<any>>;
|
|
54
|
+
static shortcut: "clients.websocket";
|
|
55
|
+
static stateSchema: z.ZodObject<{
|
|
56
|
+
connected: z.ZodDefault<z.ZodBoolean>;
|
|
57
|
+
connectionError: z.ZodOptional<z.ZodAny>;
|
|
58
|
+
reconnectAttempts: z.ZodDefault<z.ZodNumber>;
|
|
59
|
+
}, z.core.$loose>;
|
|
60
|
+
static optionsSchema: z.ZodObject<{
|
|
61
|
+
name: z.ZodOptional<z.ZodString>;
|
|
62
|
+
_cacheKey: z.ZodOptional<z.ZodString>;
|
|
63
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
64
|
+
json: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
reconnect: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
reconnectInterval: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
maxReconnectAttempts: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
static eventsSchema: z.ZodObject<{
|
|
70
|
+
stateChange: z.ZodTuple<[z.ZodAny], null>;
|
|
71
|
+
failure: z.ZodTuple<[z.ZodAny], null>;
|
|
72
|
+
message: z.ZodTuple<[z.ZodAny], null>;
|
|
73
|
+
open: z.ZodTuple<[], null>;
|
|
74
|
+
close: z.ZodTuple<[z.ZodOptional<z.ZodNumber>, z.ZodOptional<z.ZodString>], null>;
|
|
75
|
+
error: z.ZodTuple<[z.ZodAny], null>;
|
|
76
|
+
reconnecting: z.ZodTuple<[z.ZodNumber], null>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
constructor(options?: K, context?: ContainerContext);
|
|
79
|
+
get initialState(): T;
|
|
80
|
+
/**
|
|
81
|
+
* Establish a WebSocket connection to the configured baseURL.
|
|
82
|
+
* Wires all raw WebSocket events (open, message, close, error) to the
|
|
83
|
+
* Helper event bus and updates connection state accordingly.
|
|
84
|
+
* Resolves once the connection is open; rejects on error.
|
|
85
|
+
*/
|
|
86
|
+
connect(): Promise<this>;
|
|
87
|
+
/**
|
|
88
|
+
* Send data over the WebSocket connection. Automatically JSON-serializes
|
|
89
|
+
* the payload. If not currently connected, attempts to connect first.
|
|
90
|
+
* @param data - The data to send (will be JSON.stringify'd)
|
|
91
|
+
*/
|
|
92
|
+
send(data: any): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Send a request and wait for a correlated response. The message is sent
|
|
95
|
+
* with a unique `requestId`; the remote side is expected to reply with a
|
|
96
|
+
* message containing `replyTo` set to that same ID.
|
|
97
|
+
*
|
|
98
|
+
* @param type - A string identifying the request type
|
|
99
|
+
* @param data - Optional payload to include with the request
|
|
100
|
+
* @param timeout - How long to wait for a response (default 10 000 ms)
|
|
101
|
+
* @returns The `data` field of the response message
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const result = await ws.ask('getUser', { id: 42 })
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
ask<R = any>(type: string, data?: any, timeout?: number): Promise<R>;
|
|
109
|
+
/** @internal Resolve a pending ask() if the incoming message has a replyTo field. Returns true if handled. */
|
|
110
|
+
_handleReply(message: any): boolean;
|
|
111
|
+
/** @internal Reject all pending ask() calls — used on disconnect. */
|
|
112
|
+
_rejectAllPending(reason: string): void;
|
|
113
|
+
/**
|
|
114
|
+
* Gracefully close the WebSocket connection. Suppresses auto-reconnect
|
|
115
|
+
* and updates connection state to disconnected.
|
|
116
|
+
*/
|
|
117
|
+
disconnect(): Promise<this>;
|
|
118
|
+
/** Whether the client is in an error state. */
|
|
119
|
+
get hasError(): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Attempt to reconnect if the reconnect option is enabled and we haven't
|
|
122
|
+
* exceeded maxReconnectAttempts. Uses exponential backoff capped at 30s.
|
|
123
|
+
*/
|
|
124
|
+
private maybeReconnect;
|
|
125
|
+
}
|
|
126
|
+
export default WebSocketClient;
|
|
127
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/clients/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EACL,0BAA0B,EAAE,4BAA4B,EACzD,MAAM,oBAAoB,CAAA;AAE3B,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAC7E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAA;AAEjF,OAAO,QAAQ,WAAW,CAAC;IACzB,UAAU,gBAAgB;QACxB,SAAS,EAAE,OAAO,eAAe,CAAA;KAClC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,G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