@kvman/kvcoder 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/api.d.ts +386 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/artifacts/artifact-format.d.ts +9 -0
- package/dist/artifacts/artifact-format.d.ts.map +1 -0
- package/dist/artifacts/artifact-format.js +32 -0
- package/dist/artifacts/artifact-format.js.map +1 -0
- package/dist/artifacts/artifact-records.d.ts +12 -0
- package/dist/artifacts/artifact-records.d.ts.map +1 -0
- package/dist/artifacts/artifact-records.js +17 -0
- package/dist/artifacts/artifact-records.js.map +1 -0
- package/dist/artifacts/register-artifacts.d.ts +3 -0
- package/dist/artifacts/register-artifacts.d.ts.map +1 -0
- package/dist/artifacts/register-artifacts.js +37 -0
- package/dist/artifacts/register-artifacts.js.map +1 -0
- package/dist/calls/binary-checks.d.ts +8 -0
- package/dist/calls/binary-checks.d.ts.map +1 -0
- package/dist/calls/binary-checks.js +12 -0
- package/dist/calls/binary-checks.js.map +1 -0
- package/dist/calls/connector-help.d.ts +3 -0
- package/dist/calls/connector-help.d.ts.map +1 -0
- package/dist/calls/connector-help.js +73 -0
- package/dist/calls/connector-help.js.map +1 -0
- package/dist/calls/help-text.d.ts +19 -0
- package/dist/calls/help-text.d.ts.map +1 -0
- package/dist/calls/help-text.js +22 -0
- package/dist/calls/help-text.js.map +1 -0
- package/dist/calls/line-run.d.ts +33 -0
- package/dist/calls/line-run.d.ts.map +1 -0
- package/dist/calls/line-run.js +56 -0
- package/dist/calls/line-run.js.map +1 -0
- package/dist/calls/run-shell.d.ts +12 -0
- package/dist/calls/run-shell.d.ts.map +1 -0
- package/dist/calls/run-shell.js +88 -0
- package/dist/calls/run-shell.js.map +1 -0
- package/dist/calls/run-tool.d.ts +49 -0
- package/dist/calls/run-tool.d.ts.map +1 -0
- package/dist/calls/run-tool.js +66 -0
- package/dist/calls/run-tool.js.map +1 -0
- package/dist/calls/shell-command.d.ts +25 -0
- package/dist/calls/shell-command.d.ts.map +1 -0
- package/dist/calls/shell-command.js +31 -0
- package/dist/calls/shell-command.js.map +1 -0
- package/dist/calls/shell-program.d.ts +5 -0
- package/dist/calls/shell-program.d.ts.map +1 -0
- package/dist/calls/shell-program.js +8 -0
- package/dist/calls/shell-program.js.map +1 -0
- package/dist/connector-call.d.ts +66 -0
- package/dist/connector-call.d.ts.map +1 -0
- package/dist/connector-call.js +133 -0
- package/dist/connector-call.js.map +1 -0
- package/dist/connectors/artifact.d.ts +51 -0
- package/dist/connectors/artifact.d.ts.map +1 -0
- package/dist/connectors/artifact.js +101 -0
- package/dist/connectors/artifact.js.map +1 -0
- package/dist/connectors/ask.d.ts +58 -0
- package/dist/connectors/ask.d.ts.map +1 -0
- package/dist/connectors/ask.js +85 -0
- package/dist/connectors/ask.js.map +1 -0
- package/dist/connectors/background.d.ts +29 -0
- package/dist/connectors/background.d.ts.map +1 -0
- package/dist/connectors/background.js +56 -0
- package/dist/connectors/background.js.map +1 -0
- package/dist/connectors/binary.d.ts +5 -0
- package/dist/connectors/binary.d.ts.map +1 -0
- package/dist/connectors/binary.js +27 -0
- package/dist/connectors/binary.js.map +1 -0
- package/dist/connectors/builtin-connectors.d.ts +217 -0
- package/dist/connectors/builtin-connectors.d.ts.map +1 -0
- package/dist/connectors/builtin-connectors.js +49 -0
- package/dist/connectors/builtin-connectors.js.map +1 -0
- package/dist/connectors/connector-command.d.ts +26 -0
- package/dist/connectors/connector-command.d.ts.map +1 -0
- package/dist/connectors/connector-command.js +17 -0
- package/dist/connectors/connector-command.js.map +1 -0
- package/dist/connectors/delegate.d.ts +32 -0
- package/dist/connectors/delegate.d.ts.map +1 -0
- package/dist/connectors/delegate.js +82 -0
- package/dist/connectors/delegate.js.map +1 -0
- package/dist/connectors/fs.d.ts +60 -0
- package/dist/connectors/fs.d.ts.map +1 -0
- package/dist/connectors/fs.js +132 -0
- package/dist/connectors/fs.js.map +1 -0
- package/dist/connectors/mcp.d.ts +37 -0
- package/dist/connectors/mcp.d.ts.map +1 -0
- package/dist/connectors/mcp.js +69 -0
- package/dist/connectors/mcp.js.map +1 -0
- package/dist/connectors/payload-fields.d.ts +9 -0
- package/dist/connectors/payload-fields.d.ts.map +1 -0
- package/dist/connectors/payload-fields.js +13 -0
- package/dist/connectors/payload-fields.js.map +1 -0
- package/dist/connectors/shell.d.ts +19 -0
- package/dist/connectors/shell.d.ts.map +1 -0
- package/dist/connectors/shell.js +22 -0
- package/dist/connectors/shell.js.map +1 -0
- package/dist/delay.d.ts +3 -0
- package/dist/delay.d.ts.map +1 -0
- package/dist/delay.js +11 -0
- package/dist/delay.js.map +1 -0
- package/dist/delegate/approved-run.d.ts +13 -0
- package/dist/delegate/approved-run.d.ts.map +1 -0
- package/dist/delegate/approved-run.js +54 -0
- package/dist/delegate/approved-run.js.map +1 -0
- package/dist/delegate/programs.d.ts +32 -0
- package/dist/delegate/programs.d.ts.map +1 -0
- package/dist/delegate/programs.js +67 -0
- package/dist/delegate/programs.js.map +1 -0
- package/dist/delegate/register-worker-run.d.ts +9 -0
- package/dist/delegate/register-worker-run.d.ts.map +1 -0
- package/dist/delegate/register-worker-run.js +70 -0
- package/dist/delegate/register-worker-run.js.map +1 -0
- package/dist/delegate/run-program.d.ts +9 -0
- package/dist/delegate/run-program.d.ts.map +1 -0
- package/dist/delegate/run-program.js +59 -0
- package/dist/delegate/run-program.js.map +1 -0
- package/dist/delegate/runs.d.ts +27 -0
- package/dist/delegate/runs.d.ts.map +1 -0
- package/dist/delegate/runs.js +68 -0
- package/dist/delegate/runs.js.map +1 -0
- package/dist/delegate/workers.d.ts +266 -0
- package/dist/delegate/workers.d.ts.map +1 -0
- package/dist/delegate/workers.js +80 -0
- package/dist/delegate/workers.js.map +1 -0
- package/dist/docs.d.ts +14 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +59 -0
- package/dist/docs.js.map +1 -0
- package/dist/files/edit-text.d.ts +13 -0
- package/dist/files/edit-text.d.ts.map +1 -0
- package/dist/files/edit-text.js +46 -0
- package/dist/files/edit-text.js.map +1 -0
- package/dist/files/file-queue.d.ts +3 -0
- package/dist/files/file-queue.d.ts.map +1 -0
- package/dist/files/file-queue.js +17 -0
- package/dist/files/file-queue.js.map +1 -0
- package/dist/files/list-entries.d.ts +14 -0
- package/dist/files/list-entries.d.ts.map +1 -0
- package/dist/files/list-entries.js +40 -0
- package/dist/files/list-entries.js.map +1 -0
- package/dist/files/read-file.d.ts +17 -0
- package/dist/files/read-file.d.ts.map +1 -0
- package/dist/files/read-file.js +53 -0
- package/dist/files/read-file.js.map +1 -0
- package/dist/files/search-text.d.ts +14 -0
- package/dist/files/search-text.d.ts.map +1 -0
- package/dist/files/search-text.js +62 -0
- package/dist/files/search-text.js.map +1 -0
- package/dist/files/workspace-path.d.ts +5 -0
- package/dist/files/workspace-path.d.ts.map +1 -0
- package/dist/files/workspace-path.js +37 -0
- package/dist/files/workspace-path.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/job-rows.d.ts +24 -0
- package/dist/jobs/job-rows.d.ts.map +1 -0
- package/dist/jobs/job-rows.js +74 -0
- package/dist/jobs/job-rows.js.map +1 -0
- package/dist/jobs/process-handlers.d.ts +8 -0
- package/dist/jobs/process-handlers.d.ts.map +1 -0
- package/dist/jobs/process-handlers.js +43 -0
- package/dist/jobs/process-handlers.js.map +1 -0
- package/dist/jobs/process-records.d.ts +15 -0
- package/dist/jobs/process-records.d.ts.map +1 -0
- package/dist/jobs/process-records.js +30 -0
- package/dist/jobs/process-records.js.map +1 -0
- package/dist/jobs/process-report.d.ts +8 -0
- package/dist/jobs/process-report.d.ts.map +1 -0
- package/dist/jobs/process-report.js +44 -0
- package/dist/jobs/process-report.js.map +1 -0
- package/dist/jobs/process-run.d.ts +26 -0
- package/dist/jobs/process-run.d.ts.map +1 -0
- package/dist/jobs/process-run.js +70 -0
- package/dist/jobs/process-run.js.map +1 -0
- package/dist/jobs/process-text.d.ts +5 -0
- package/dist/jobs/process-text.d.ts.map +1 -0
- package/dist/jobs/process-text.js +11 -0
- package/dist/jobs/process-text.js.map +1 -0
- package/dist/jobs/register-jobs.d.ts +3 -0
- package/dist/jobs/register-jobs.d.ts.map +1 -0
- package/dist/jobs/register-jobs.js +61 -0
- package/dist/jobs/register-jobs.js.map +1 -0
- package/dist/mcp/command-transport.d.ts +17 -0
- package/dist/mcp/command-transport.d.ts.map +1 -0
- package/dist/mcp/command-transport.js +60 -0
- package/dist/mcp/command-transport.js.map +1 -0
- package/dist/mcp/connect.d.ts +12 -0
- package/dist/mcp/connect.d.ts.map +1 -0
- package/dist/mcp/connect.js +54 -0
- package/dist/mcp/connect.js.map +1 -0
- package/dist/mcp/oauth-provider.d.ts +25 -0
- package/dist/mcp/oauth-provider.d.ts.map +1 -0
- package/dist/mcp/oauth-provider.js +59 -0
- package/dist/mcp/oauth-provider.js.map +1 -0
- package/dist/mcp/register-mcp.d.ts +3 -0
- package/dist/mcp/register-mcp.d.ts.map +1 -0
- package/dist/mcp/register-mcp.js +61 -0
- package/dist/mcp/register-mcp.js.map +1 -0
- package/dist/mcp/secrets.d.ts +7 -0
- package/dist/mcp/secrets.d.ts.map +1 -0
- package/dist/mcp/secrets.js +20 -0
- package/dist/mcp/secrets.js.map +1 -0
- package/dist/mcp/servers.d.ts +33 -0
- package/dist/mcp/servers.d.ts.map +1 -0
- package/dist/mcp/servers.js +31 -0
- package/dist/mcp/servers.js.map +1 -0
- package/dist/mcp/sign-in-record.d.ts +10 -0
- package/dist/mcp/sign-in-record.d.ts.map +1 -0
- package/dist/mcp/sign-in-record.js +4 -0
- package/dist/mcp/sign-in-record.js.map +1 -0
- package/dist/mcp/sign-in.d.ts +12 -0
- package/dist/mcp/sign-in.d.ts.map +1 -0
- package/dist/mcp/sign-in.js +75 -0
- package/dist/mcp/sign-in.js.map +1 -0
- package/dist/mcp/tools.d.ts +19 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +31 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/messages/attachments.d.ts +8 -0
- package/dist/messages/attachments.d.ts.map +1 -0
- package/dist/messages/attachments.js +48 -0
- package/dist/messages/attachments.js.map +1 -0
- package/dist/messages/receive-message.d.ts +15 -0
- package/dist/messages/receive-message.d.ts.map +1 -0
- package/dist/messages/receive-message.js +60 -0
- package/dist/messages/receive-message.js.map +1 -0
- package/dist/messages/register-messages.d.ts +3 -0
- package/dist/messages/register-messages.d.ts.map +1 -0
- package/dist/messages/register-messages.js +63 -0
- package/dist/messages/register-messages.js.map +1 -0
- package/dist/problems.d.ts +8 -0
- package/dist/problems.d.ts.map +1 -0
- package/dist/problems.js +14 -0
- package/dist/problems.js.map +1 -0
- package/dist/prompt/build-prompt.d.ts +29 -0
- package/dist/prompt/build-prompt.d.ts.map +1 -0
- package/dist/prompt/build-prompt.js +60 -0
- package/dist/prompt/build-prompt.js.map +1 -0
- package/dist/prompt/register-prompt.d.ts +3 -0
- package/dist/prompt/register-prompt.d.ts.map +1 -0
- package/dist/prompt/register-prompt.js +29 -0
- package/dist/prompt/register-prompt.js.map +1 -0
- package/dist/prompt/session-prompt.d.ts +24 -0
- package/dist/prompt/session-prompt.d.ts.map +1 -0
- package/dist/prompt/session-prompt.js +50 -0
- package/dist/prompt/session-prompt.js.map +1 -0
- package/dist/prompt/working-method.d.ts +7 -0
- package/dist/prompt/working-method.d.ts.map +1 -0
- package/dist/prompt/working-method.js +51 -0
- package/dist/prompt/working-method.js.map +1 -0
- package/dist/register-settings.d.ts +142 -0
- package/dist/register-settings.d.ts.map +1 -0
- package/dist/register-settings.js +51 -0
- package/dist/register-settings.js.map +1 -0
- package/dist/registry/loaded.d.ts +32 -0
- package/dist/registry/loaded.d.ts.map +1 -0
- package/dist/registry/loaded.js +41 -0
- package/dist/registry/loaded.js.map +1 -0
- package/dist/registry/register-connectors.d.ts +32 -0
- package/dist/registry/register-connectors.d.ts.map +1 -0
- package/dist/registry/register-connectors.js +126 -0
- package/dist/registry/register-connectors.js.map +1 -0
- package/dist/registry/register-sections.d.ts +18 -0
- package/dist/registry/register-sections.d.ts.map +1 -0
- package/dist/registry/register-sections.js +99 -0
- package/dist/registry/register-sections.js.map +1 -0
- package/dist/registry/session-points.d.ts +11 -0
- package/dist/registry/session-points.d.ts.map +1 -0
- package/dist/registry/session-points.js +89 -0
- package/dist/registry/session-points.js.map +1 -0
- package/dist/result-text.d.ts +11 -0
- package/dist/result-text.d.ts.map +1 -0
- package/dist/result-text.js +21 -0
- package/dist/result-text.js.map +1 -0
- package/dist/schemas/records.d.ts +357 -0
- package/dist/schemas/records.d.ts.map +1 -0
- package/dist/schemas/records.js +159 -0
- package/dist/schemas/records.js.map +1 -0
- package/dist/schemas/registry.d.ts +160 -0
- package/dist/schemas/registry.d.ts.map +1 -0
- package/dist/schemas/registry.js +37 -0
- package/dist/schemas/registry.js.map +1 -0
- package/dist/sessions/new-session.d.ts +6 -0
- package/dist/sessions/new-session.d.ts.map +1 -0
- package/dist/sessions/new-session.js +52 -0
- package/dist/sessions/new-session.js.map +1 -0
- package/dist/sessions/register-fork-export.d.ts +5 -0
- package/dist/sessions/register-fork-export.d.ts.map +1 -0
- package/dist/sessions/register-fork-export.js +62 -0
- package/dist/sessions/register-fork-export.js.map +1 -0
- package/dist/sessions/register-lifecycle.d.ts +3 -0
- package/dist/sessions/register-lifecycle.d.ts.map +1 -0
- package/dist/sessions/register-lifecycle.js +59 -0
- package/dist/sessions/register-lifecycle.js.map +1 -0
- package/dist/sessions/register-sessions.d.ts +3 -0
- package/dist/sessions/register-sessions.d.ts.map +1 -0
- package/dist/sessions/register-sessions.js +93 -0
- package/dist/sessions/register-sessions.js.map +1 -0
- package/dist/sessions/session-lookup.d.ts +10 -0
- package/dist/sessions/session-lookup.d.ts.map +1 -0
- package/dist/sessions/session-lookup.js +25 -0
- package/dist/sessions/session-lookup.js.map +1 -0
- package/dist/sessions/session-view.d.ts +118 -0
- package/dist/sessions/session-view.d.ts.map +1 -0
- package/dist/sessions/session-view.js +105 -0
- package/dist/sessions/session-view.js.map +1 -0
- package/dist/store/collections.d.ts +471 -0
- package/dist/store/collections.d.ts.map +1 -0
- package/dist/store/collections.js +46 -0
- package/dist/store/collections.js.map +1 -0
- package/dist/turns/background.d.ts +6 -0
- package/dist/turns/background.d.ts.map +1 -0
- package/dist/turns/background.js +27 -0
- package/dist/turns/background.js.map +1 -0
- package/dist/turns/cancel-turn.d.ts +3 -0
- package/dist/turns/cancel-turn.d.ts.map +1 -0
- package/dist/turns/cancel-turn.js +31 -0
- package/dist/turns/cancel-turn.js.map +1 -0
- package/dist/turns/compaction.d.ts +12 -0
- package/dist/turns/compaction.d.ts.map +1 -0
- package/dist/turns/compaction.js +55 -0
- package/dist/turns/compaction.js.map +1 -0
- package/dist/turns/end-turn.d.ts +15 -0
- package/dist/turns/end-turn.d.ts.map +1 -0
- package/dist/turns/end-turn.js +67 -0
- package/dist/turns/end-turn.js.map +1 -0
- package/dist/turns/history.d.ts +28 -0
- package/dist/turns/history.d.ts.map +1 -0
- package/dist/turns/history.js +47 -0
- package/dist/turns/history.js.map +1 -0
- package/dist/turns/lost-reply.d.ts +31 -0
- package/dist/turns/lost-reply.d.ts.map +1 -0
- package/dist/turns/lost-reply.js +43 -0
- package/dist/turns/lost-reply.js.map +1 -0
- package/dist/turns/message-blocks.d.ts +9 -0
- package/dist/turns/message-blocks.d.ts.map +1 -0
- package/dist/turns/message-blocks.js +25 -0
- package/dist/turns/message-blocks.js.map +1 -0
- package/dist/turns/model-context.d.ts +81 -0
- package/dist/turns/model-context.d.ts.map +1 -0
- package/dist/turns/model-context.js +46 -0
- package/dist/turns/model-context.js.map +1 -0
- package/dist/turns/model-info.d.ts +7 -0
- package/dist/turns/model-info.d.ts.map +1 -0
- package/dist/turns/model-info.js +10 -0
- package/dist/turns/model-info.js.map +1 -0
- package/dist/turns/model-retry.d.ts +3 -0
- package/dist/turns/model-retry.d.ts.map +1 -0
- package/dist/turns/model-retry.js +23 -0
- package/dist/turns/model-retry.js.map +1 -0
- package/dist/turns/register-interruptions.d.ts +3 -0
- package/dist/turns/register-interruptions.d.ts.map +1 -0
- package/dist/turns/register-interruptions.js +31 -0
- package/dist/turns/register-interruptions.js.map +1 -0
- package/dist/turns/register-turns.d.ts +3 -0
- package/dist/turns/register-turns.d.ts.map +1 -0
- package/dist/turns/register-turns.js +66 -0
- package/dist/turns/register-turns.js.map +1 -0
- package/dist/turns/resolve.d.ts +7 -0
- package/dist/turns/resolve.d.ts.map +1 -0
- package/dist/turns/resolve.js +29 -0
- package/dist/turns/resolve.js.map +1 -0
- package/dist/turns/run-calls.d.ts +34 -0
- package/dist/turns/run-calls.d.ts.map +1 -0
- package/dist/turns/run-calls.js +99 -0
- package/dist/turns/run-calls.js.map +1 -0
- package/dist/turns/run-command.d.ts +26 -0
- package/dist/turns/run-command.d.ts.map +1 -0
- package/dist/turns/run-command.js +118 -0
- package/dist/turns/run-command.js.map +1 -0
- package/dist/turns/settle-calls.d.ts +17 -0
- package/dist/turns/settle-calls.d.ts.map +1 -0
- package/dist/turns/settle-calls.js +98 -0
- package/dist/turns/settle-calls.js.map +1 -0
- package/dist/turns/start-turn.d.ts +87 -0
- package/dist/turns/start-turn.d.ts.map +1 -0
- package/dist/turns/start-turn.js +40 -0
- package/dist/turns/start-turn.js.map +1 -0
- package/dist/turns/step.d.ts +8 -0
- package/dist/turns/step.d.ts.map +1 -0
- package/dist/turns/step.js +168 -0
- package/dist/turns/step.js.map +1 -0
- package/dist/ui/register-ui.d.ts +3 -0
- package/dist/ui/register-ui.d.ts.map +1 -0
- package/dist/ui/register-ui.js +75 -0
- package/dist/ui/register-ui.js.map +1 -0
- package/dist/web/components/call.css +2 -0
- package/dist/web/components/call.js +386 -0
- package/dist/web/components/connectors.css +2 -0
- package/dist/web/components/connectors.js +2403 -0
- package/dist/web/components/conversation.css +2 -0
- package/dist/web/components/conversation.js +4319 -0
- package/dist/web/components/mcp-sign-in.css +2 -0
- package/dist/web/components/mcp-sign-in.js +265 -0
- package/dist/web/components/model.css +2 -0
- package/dist/web/components/model.js +545 -0
- package/dist/web/components/question.css +2 -0
- package/dist/web/components/question.js +321 -0
- package/dist/web/components/sessions.css +2 -0
- package/dist/web/components/sessions.js +264 -0
- package/docs/connectors.md +86 -0
- package/docs/sections.md +27 -0
- package/locales/ar.json +418 -0
- package/locales/en.json +418 -0
- package/package.json +70 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z, type Json, type Problem } from '@kvman/sdk';
|
|
2
|
+
/** A JSON value as zod parses it. */
|
|
3
|
+
export type JsonValue = z.output<ReturnType<typeof z.json>>;
|
|
4
|
+
/** What a connector call returned, and whether it failed (exit code 1). */
|
|
5
|
+
export type CallResult = {
|
|
6
|
+
output: string;
|
|
7
|
+
exitCode: number;
|
|
8
|
+
};
|
|
9
|
+
/** The connectors kvcoder runs itself, in the order the prompt lists them. */
|
|
10
|
+
export declare const builtinConnectors: readonly ["shell", "fs", "artifact", "background", "ask", "delegate", "mcp"];
|
|
11
|
+
export type BuiltinConnector = (typeof builtinConnectors)[number];
|
|
12
|
+
/** A Problem as a connector call returns it. */
|
|
13
|
+
export declare function errorOutput(problem: Pick<Problem, 'code' | 'message'>): CallResult;
|
|
14
|
+
/** A connector command's JSON output, indented by 2 spaces. */
|
|
15
|
+
export declare function jsonOutput(value: unknown): CallResult;
|
|
16
|
+
export declare const noConnectorMessage: (connector: string, names: readonly string[]) => string;
|
|
17
|
+
/** A connector has no such command: the message names the ones it has, and cuts a long wrong name, which is usually a shell line (ADR 0012, 19). */
|
|
18
|
+
export declare function noCommandMessage(connector: string, command: string, commands: readonly string[]): string;
|
|
19
|
+
export type PayloadIssue = {
|
|
20
|
+
path: string;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
/** A payload's signature written from its JSON Schema, such as `{ a, b?, c: [{ x }] }`; `undefined` when the schema isn't an object with properties. */
|
|
24
|
+
export declare function payloadSignature(schema: Json | undefined): string | undefined;
|
|
25
|
+
/** An invalid payload as the model reads it: each problem, then the command's signature so one correction is enough (ADR 0012, 2 to 4). */
|
|
26
|
+
export declare function invalidPayloadOutput(call: {
|
|
27
|
+
connector: string;
|
|
28
|
+
command: string;
|
|
29
|
+
}, issues: readonly PayloadIssue[], schema: Json | undefined): CallResult;
|
|
30
|
+
/** One run of a connector's command: how to run it, and how to find its payload schema when the payload doesn't fit. */
|
|
31
|
+
export type CommandRun = {
|
|
32
|
+
connector: string;
|
|
33
|
+
command: string;
|
|
34
|
+
/** Where the payload sits in the job's input: `payload` for a built-in command, nothing for a registered one. */
|
|
35
|
+
payloadPath: string;
|
|
36
|
+
exec(): Promise<unknown>;
|
|
37
|
+
payloadSchema(): Promise<Json | undefined>;
|
|
38
|
+
/** Whether the calling job was cancelled, so its Problem is rethrown instead of returned. */
|
|
39
|
+
cancelled(): boolean;
|
|
40
|
+
};
|
|
41
|
+
/** Runs a connector's command: its output, or the failure the model reads. */
|
|
42
|
+
export declare function runCommand(run: CommandRun): Promise<{
|
|
43
|
+
ok: true;
|
|
44
|
+
value: unknown;
|
|
45
|
+
} | {
|
|
46
|
+
ok: false;
|
|
47
|
+
result: CallResult;
|
|
48
|
+
}>;
|
|
49
|
+
/** The test kernel `runConnector` needs: `@kvman/testkit`'s, with kvcoder loaded. */
|
|
50
|
+
export type ConnectorKernel = {
|
|
51
|
+
exec(name: string, input: Record<string, Json>, options?: {
|
|
52
|
+
as?: string;
|
|
53
|
+
workspaceId?: string;
|
|
54
|
+
}): Promise<unknown>;
|
|
55
|
+
};
|
|
56
|
+
/** A call as the `run` tool makes it, without its description. */
|
|
57
|
+
export type ConnectorCall = {
|
|
58
|
+
connector: string;
|
|
59
|
+
command: string;
|
|
60
|
+
payload?: Record<string, Json>;
|
|
61
|
+
};
|
|
62
|
+
/** Runs a call exactly as kvcoder does, for commands connectors and every connector's `help` (ADR 0009, 96; ADR 0011, 18). */
|
|
63
|
+
export declare function runConnector(kernel: ConnectorKernel, call: ConnectorCall, options?: {
|
|
64
|
+
workspaceId?: string;
|
|
65
|
+
}): Promise<CallResult>;
|
|
66
|
+
//# sourceMappingURL=connector-call.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-call.d.ts","sourceRoot":"","sources":["../src/connector-call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,CAAC,EAAE,KAAK,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAKtE,qCAAqC;AACrC,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAE5D,2EAA2E;AAC3E,MAAM,MAAM,UAAU,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D,8EAA8E;AAC9E,eAAO,MAAM,iBAAiB,8EAA+E,CAAC;AAE9G,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,UAAU,CAElF;AAED,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAErD;AAED,eAAO,MAAM,kBAAkB,GAAI,WAAW,MAAM,EAAE,OAAO,SAAS,MAAM,EAAE,KAAG,MAAwF,CAAC;AAI1K,oJAAoJ;AACpJ,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAGxG;AAED,MAA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AAA;CAAE,CAAC;AAErJ,kEAAkE;AAClE,MAAM,MAAM,aAAa,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;CAAE,CAAC;AAInG,8HAA8H;AAC9H,wBAAsB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CA4B5I"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ProblemError, z } from '@kvman/sdk';
|
|
2
|
+
/** The connectors kvcoder runs itself, in the order the prompt lists them. */
|
|
3
|
+
export const builtinConnectors = ['shell', 'fs', 'artifact', 'background', 'ask', 'delegate', 'mcp'];
|
|
4
|
+
/** A Problem as a connector call returns it. */
|
|
5
|
+
export function errorOutput(problem) {
|
|
6
|
+
return { output: `error ${problem.code}: ${problem.message}`, exitCode: 1 };
|
|
7
|
+
}
|
|
8
|
+
/** A connector command's JSON output, indented by 2 spaces. */
|
|
9
|
+
export function jsonOutput(value) {
|
|
10
|
+
return { output: JSON.stringify(value ?? null, null, 2), exitCode: 0 };
|
|
11
|
+
}
|
|
12
|
+
export const noConnectorMessage = (connector, names) => `There is no connector ${connector}. The connectors are: ${names.join(', ')}.`;
|
|
13
|
+
const shownCommandLength = 40;
|
|
14
|
+
/** A connector has no such command: the message names the ones it has, and cuts a long wrong name, which is usually a shell line (ADR 0012, 19). */
|
|
15
|
+
export function noCommandMessage(connector, command, commands) {
|
|
16
|
+
const shown = command.length > shownCommandLength ? `${command.slice(0, shownCommandLength)}…` : command;
|
|
17
|
+
return `${connector} has no command ${shown}. Its commands are: ${[...commands, 'help'].join(', ')}.`;
|
|
18
|
+
}
|
|
19
|
+
const field = z.lazy(() => z.looseObject({
|
|
20
|
+
type: z.string().optional(),
|
|
21
|
+
enum: z.array(z.json()).optional(),
|
|
22
|
+
properties: z.record(z.string(), field).optional(),
|
|
23
|
+
required: z.array(z.string()).optional(),
|
|
24
|
+
items: field.optional(),
|
|
25
|
+
}));
|
|
26
|
+
// The top of a payload's schema: an object with properties, as the kernel's `z.toJSONSchema` writes it.
|
|
27
|
+
const payloadObject = z.looseObject({ type: z.literal('object'), properties: z.record(z.string(), field), required: z.array(z.string()).optional() });
|
|
28
|
+
function objectSignature(schema) {
|
|
29
|
+
const entries = Object.entries(schema.properties ?? {});
|
|
30
|
+
if (entries.length === 0)
|
|
31
|
+
return '{}';
|
|
32
|
+
const required = new Set(schema.required ?? []);
|
|
33
|
+
return `{ ${entries.map(([name, child]) => fieldSignature(name, child, required.has(name))).join(', ')} }`;
|
|
34
|
+
}
|
|
35
|
+
function fieldSignature(name, schema, required) {
|
|
36
|
+
const mark = required ? '' : '?';
|
|
37
|
+
if (schema.properties !== undefined)
|
|
38
|
+
return `${name}${mark}: ${objectSignature(schema)}`;
|
|
39
|
+
if (schema.type === 'array' && schema.items?.properties !== undefined)
|
|
40
|
+
return `${name}${mark}: [${objectSignature(schema.items)}]`;
|
|
41
|
+
if (schema.enum !== undefined && schema.enum.length > 0 && schema.enum.every((value) => typeof value === 'string')) {
|
|
42
|
+
return `${name}${mark}: ${schema.enum.map((value) => JSON.stringify(value)).join(' | ')}`;
|
|
43
|
+
}
|
|
44
|
+
return `${name}${mark}`;
|
|
45
|
+
}
|
|
46
|
+
/** A payload's signature written from its JSON Schema, such as `{ a, b?, c: [{ x }] }`; `undefined` when the schema isn't an object with properties. */
|
|
47
|
+
export function payloadSignature(schema) {
|
|
48
|
+
if (schema === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
const parsed = payloadObject.safeParse(schema);
|
|
51
|
+
return parsed.success ? objectSignature(parsed.data) : undefined;
|
|
52
|
+
}
|
|
53
|
+
function withoutSchemaKey(schema) {
|
|
54
|
+
if (typeof schema !== 'object' || schema === null || Array.isArray(schema))
|
|
55
|
+
return schema;
|
|
56
|
+
return Object.fromEntries(Object.entries(schema).filter(([key]) => key !== '$schema'));
|
|
57
|
+
}
|
|
58
|
+
/** An invalid payload as the model reads it: each problem, then the command's signature so one correction is enough (ADR 0012, 2 to 4). */
|
|
59
|
+
export function invalidPayloadOutput(call, issues, schema) {
|
|
60
|
+
const problems = issues.map((issue) => `${issue.path === '' ? 'payload' : issue.path}: ${issue.message}`).join('; ');
|
|
61
|
+
let shape = '';
|
|
62
|
+
if (schema !== undefined) {
|
|
63
|
+
const signature = payloadSignature(schema);
|
|
64
|
+
shape = signature === undefined ? ` The payload of ${call.connector} ${call.command} is (JSON Schema):\n${JSON.stringify(withoutSchemaKey(schema))}` : ` The payload of ${call.connector} ${call.command} is\n${signature}`;
|
|
65
|
+
}
|
|
66
|
+
return errorOutput({ code: 'VALIDATION_FAILED', message: `${problems}.${shape}` });
|
|
67
|
+
}
|
|
68
|
+
const kernelIssuesSchema = z.object({ issues: z.array(z.object({ path: z.string(), message: z.string() })).min(1) });
|
|
69
|
+
// The kernel's issue paths start at the job's input; a built-in command's payload is the input's `payload` field.
|
|
70
|
+
function withoutPrefix(path, prefix) {
|
|
71
|
+
if (prefix === '')
|
|
72
|
+
return path;
|
|
73
|
+
if (path === prefix)
|
|
74
|
+
return '';
|
|
75
|
+
return path.startsWith(`${prefix}.`) ? path.slice(prefix.length + 1) : path;
|
|
76
|
+
}
|
|
77
|
+
/** Runs a connector's command: its output, or the failure the model reads. */
|
|
78
|
+
export async function runCommand(run) {
|
|
79
|
+
try {
|
|
80
|
+
return { ok: true, value: await run.exec() };
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (!(error instanceof ProblemError) || run.cancelled())
|
|
84
|
+
throw error;
|
|
85
|
+
const invalid = error.problem.code === 'VALIDATION_FAILED' ? kernelIssuesSchema.safeParse(error.problem.params) : undefined;
|
|
86
|
+
if (invalid?.success !== true)
|
|
87
|
+
return { ok: false, result: errorOutput(error.problem) };
|
|
88
|
+
const issues = invalid.data.issues.map((issue) => ({ path: withoutPrefix(issue.path, run.payloadPath), message: issue.message }));
|
|
89
|
+
return { ok: false, result: invalidPayloadOutput(run, issues, await run.payloadSchema()) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const connectorListSchema = z.array(z.object({ name: z.string(), kind: z.enum(['commands', 'binary']), commands: z.array(z.object({ name: z.string(), command: z.string() })).exactOptional() }));
|
|
93
|
+
const registrationSchema = z.object({ name: z.string(), input: z.json() });
|
|
94
|
+
const extensionsSchema = z.array(z.object({ commands: z.array(registrationSchema), queries: z.array(registrationSchema) }));
|
|
95
|
+
const helpSchema = z.object({ text: z.string() });
|
|
96
|
+
const insideTurn = (connector) => ({ output: `${connector} runs only inside a turn`, exitCode: 1 });
|
|
97
|
+
/** Runs a call exactly as kvcoder does, for commands connectors and every connector's `help` (ADR 0009, 96; ADR 0011, 18). */
|
|
98
|
+
export async function runConnector(kernel, call, options = {}) {
|
|
99
|
+
const as = { as: '@kvman/kvcoder', ...options };
|
|
100
|
+
const payload = call.payload ?? {};
|
|
101
|
+
if (call.command === 'help') {
|
|
102
|
+
const asked = typeof payload['command'] === 'string' ? { command: payload['command'] } : {};
|
|
103
|
+
try {
|
|
104
|
+
return { output: helpSchema.parse(await kernel.exec('kvcoder.connector.help.get', { connector: call.connector, ...asked }, as)).text, exitCode: 0 };
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error instanceof ProblemError)
|
|
108
|
+
return errorOutput(error.problem);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (builtinConnectors.some((name) => name === call.connector))
|
|
113
|
+
return insideTurn(call.connector);
|
|
114
|
+
const connectors = connectorListSchema.parse(await kernel.exec('kvcoder.connector.list', {}, as));
|
|
115
|
+
const connector = connectors.find((candidate) => candidate.name === call.connector);
|
|
116
|
+
if (connector === undefined)
|
|
117
|
+
return errorOutput({ code: 'VALIDATION_FAILED', message: noConnectorMessage(call.connector, [...builtinConnectors, ...connectors.map((candidate) => candidate.name)]) });
|
|
118
|
+
if (connector.kind === 'binary')
|
|
119
|
+
return insideTurn(call.connector);
|
|
120
|
+
const target = connector.commands?.find((candidate) => candidate.name === call.command);
|
|
121
|
+
if (target === undefined)
|
|
122
|
+
return errorOutput({ code: 'NOT_FOUND', message: noCommandMessage(call.connector, call.command, (connector.commands ?? []).map((candidate) => candidate.name)) });
|
|
123
|
+
const done = await runCommand({
|
|
124
|
+
connector: call.connector,
|
|
125
|
+
command: call.command,
|
|
126
|
+
payloadPath: '',
|
|
127
|
+
exec: () => kernel.exec(target.command, payload, as),
|
|
128
|
+
payloadSchema: async () => extensionsSchema.parse(await kernel.exec('kernel.extensions.list', {}, as)).flatMap((extension) => [...extension.commands, ...extension.queries]).find((registered) => registered.name === target.command)?.input,
|
|
129
|
+
cancelled: () => false,
|
|
130
|
+
});
|
|
131
|
+
return done.ok ? jsonOutput(done.value) : done.result;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=connector-call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-call.js","sourceRoot":"","sources":["../src/connector-call.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,CAAC,EAA2B,MAAM,YAAY,CAAC;AAWtE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAU,CAAC;AAI9G,gDAAgD;AAChD,MAAM,UAAU,WAAW,CAAC,OAA0C;IACpE,OAAO,EAAE,MAAM,EAAE,SAAS,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,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AE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK;QAC5O,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK;KACvB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z, type Ctx } from '@kvman/sdk';
|
|
2
|
+
import { artifactFormats } from '../artifacts/artifact-format.ts';
|
|
3
|
+
/** What the prompt's index says the connector is for. */
|
|
4
|
+
export declare const artifactDescription = "Show the person something to read or see: a plan, a report, a design, an HTML page, or the localhost address of an app you are running (format url). Use it for anything longer than a few lines instead of pasting it into a reply, and when you write a plan, keep it in the artifact `plan`. The panel runs the page of an HTML artifact in a sandbox where localStorage, sessionStorage, cookies, and indexedDB throw, so a page you show that way must work without them, keeping its state in memory or wrapping each use in try/catch; a url artifact is a normal page on its own address and can use them.";
|
|
5
|
+
export declare const artifactCommands: {
|
|
6
|
+
write: {
|
|
7
|
+
registration: string;
|
|
8
|
+
description: string;
|
|
9
|
+
payload: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
title: z.ZodString;
|
|
12
|
+
format: z.ZodExactOptional<z.ZodEnum<{
|
|
13
|
+
markdown: "markdown";
|
|
14
|
+
html: "html";
|
|
15
|
+
url: "url";
|
|
16
|
+
}>>;
|
|
17
|
+
content: z.ZodString;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
asks: false;
|
|
20
|
+
notes: string;
|
|
21
|
+
};
|
|
22
|
+
edit: {
|
|
23
|
+
registration: string;
|
|
24
|
+
description: string;
|
|
25
|
+
payload: z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
edits: z.ZodArray<z.ZodObject<{
|
|
28
|
+
oldText: z.ZodString;
|
|
29
|
+
newText: z.ZodString;
|
|
30
|
+
}, z.core.$strict>>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
asks: false;
|
|
33
|
+
};
|
|
34
|
+
get: {
|
|
35
|
+
registration: string;
|
|
36
|
+
description: string;
|
|
37
|
+
payload: z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
}, z.core.$strict>;
|
|
40
|
+
asks: false;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/** What the artifact card shows of a chat's artifact (ADR 0009, 177), or nothing when the chat has none by that id. */
|
|
44
|
+
export declare function artifactCard(ctx: Ctx, sessionId: string, id: string): Promise<{
|
|
45
|
+
id: string;
|
|
46
|
+
title: string;
|
|
47
|
+
format: (typeof artifactFormats)[number];
|
|
48
|
+
version: number;
|
|
49
|
+
} | undefined>;
|
|
50
|
+
export declare function registerArtifactConnector(ctx: Ctx): void;
|
|
51
|
+
//# sourceMappingURL=artifact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../../src/connectors/artifact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAA4B,MAAM,iCAAiC,CAAC;AAc5F,yDAAyD;AACzD,eAAO,MAAM,mBAAmB,ulBACsjB,CAAC;AAoBvlB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIe,CAAC;AAyC7C,uHAAuH;AACvH,wBAAsB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAGzL;AAID,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAyBxD"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { artifactFormats, contentFor, detectFormat } from "../artifacts/artifact-format.js";
|
|
3
|
+
import { artifactCountLimit, assertWithinLimit, chatIdOf } from "../artifacts/artifact-records.js";
|
|
4
|
+
import { applyEdits } from "../files/edit-text.js";
|
|
5
|
+
import { notFound, tooLarge } from "../problems.js";
|
|
6
|
+
import { kebab } from "../schemas/registry.js";
|
|
7
|
+
import { findSession, now } from "../sessions/session-lookup.js";
|
|
8
|
+
import { records, txRecords } from "../store/collections.js";
|
|
9
|
+
import { callInput } from "./connector-command.js";
|
|
10
|
+
import { edits } from "./payload-fields.js";
|
|
11
|
+
// The `artifact` connector (plan 08 §8.5, ADR 0009, 173 to 176): `write` creates or replaces the chat's document,
|
|
12
|
+
// `edit` replaces text in one, `get` reads one. No approval is asked, and the step runs the calls on one artifact one
|
|
13
|
+
// after another.
|
|
14
|
+
/** What the prompt's index says the connector is for. */
|
|
15
|
+
export const artifactDescription = 'Show the person something to read or see: a plan, a report, a design, an HTML page, or the localhost address of an app you are running (format url). Use it for anything longer than a few lines instead of pasting it into a reply, and when you write a plan, keep it in the artifact `plan`. The panel runs the page of an HTML artifact in a sandbox where localStorage, sessionStorage, cookies, and indexedDB throw, so a page you show that way must work without them, keeping its state in memory or wrapping each use in try/catch; a url artifact is a normal page on its own address and can use them.';
|
|
16
|
+
const idMessage = 'An artifact id is lowercase kebab case, such as plan or login-design, up to 50 characters.';
|
|
17
|
+
const artifactId = z.string().max(50, idMessage).regex(kebab, idMessage).describe('The name of the artifact within this chat, in lowercase kebab case, up to 50 characters, such as plan.');
|
|
18
|
+
const payloads = {
|
|
19
|
+
write: z.strictObject({
|
|
20
|
+
id: artifactId,
|
|
21
|
+
title: z.string().min(1).max(100).describe('The title the person sees, up to 100 characters.'),
|
|
22
|
+
format: z.enum(artifactFormats).describe('markdown, html, or url. Left out, a page that starts with <!doctype html or <html is html, a lone localhost address is url, and anything else markdown.').exactOptional(),
|
|
23
|
+
content: z.string().min(1).describe('The whole content, up to 64 KB.'),
|
|
24
|
+
}),
|
|
25
|
+
edit: z.strictObject({ id: artifactId, edits }),
|
|
26
|
+
get: z.strictObject({ id: artifactId }),
|
|
27
|
+
};
|
|
28
|
+
const writeNotes = 'The content is up to 64 KB, and a chat holds up to 20 artifacts. An "html" artifact is one self-contained page: its scripts run, but it can load nothing from the network (no external scripts, styles, images, or fonts: use inline CSS and JS, data: images, or inline SVG) and can\'t reach the rest of the app. A "url" artifact shows an app running on this machine, such as a dev server you started: its content is one http or https address on localhost or 127.0.0.1, shown in a scripts-only frame.';
|
|
29
|
+
export const artifactCommands = {
|
|
30
|
+
write: { registration: 'kvcoder.artifact.write', description: 'Creates an artifact, or replaces its title, format, and content.', payload: payloads.write, asks: false, notes: writeNotes },
|
|
31
|
+
edit: { registration: 'kvcoder.artifact.edit', description: 'Replaces exact pieces of text in an existing artifact; if one replacement fails, nothing changes.', payload: payloads.edit, asks: false },
|
|
32
|
+
get: { registration: 'kvcoder.artifact.content.get', description: 'Reads an artifact with its content.', payload: payloads.get, asks: false },
|
|
33
|
+
};
|
|
34
|
+
const missing = (id) => notFound(`The artifact ${id} doesn't exist.`, { id });
|
|
35
|
+
// An artifact belongs to its chat, so a subagent's belongs to the chat at its root.
|
|
36
|
+
const chatOf = async (ctx, sessionId) => chatIdOf(await findSession(ctx, sessionId));
|
|
37
|
+
function writeArtifact(ctx, chatId, input) {
|
|
38
|
+
const format = input.format ?? detectFormat(input.content);
|
|
39
|
+
return ctx.store.transaction((tx) => {
|
|
40
|
+
const content = contentFor(format, input.content);
|
|
41
|
+
assertWithinLimit(input.id, content);
|
|
42
|
+
const artifacts = txRecords(tx).artifacts;
|
|
43
|
+
const existing = artifacts.find({ sessionId: chatId, artifactId: input.id }, { limit: 1 })[0];
|
|
44
|
+
const stamp = now();
|
|
45
|
+
if (existing === undefined) {
|
|
46
|
+
if (artifacts.count({ sessionId: chatId }) >= artifactCountLimit)
|
|
47
|
+
throw tooLarge(`The chat holds at most ${artifactCountLimit} artifacts.`, artifactCountLimit);
|
|
48
|
+
artifacts.insert({ sessionId: chatId, artifactId: input.id, title: input.title, format, content, version: 1, createdAt: stamp, updatedAt: stamp });
|
|
49
|
+
return { id: input.id, version: 1, created: true, bytes: Buffer.byteLength(content) };
|
|
50
|
+
}
|
|
51
|
+
artifacts.update(existing.id, { title: input.title, format, content, version: existing.version + 1, updatedAt: stamp });
|
|
52
|
+
return { id: input.id, version: existing.version + 1, created: false, bytes: Buffer.byteLength(content) };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function editArtifact(ctx, chatId, input) {
|
|
56
|
+
return ctx.store.transaction((tx) => {
|
|
57
|
+
const artifacts = txRecords(tx).artifacts;
|
|
58
|
+
const existing = artifacts.find({ sessionId: chatId, artifactId: input.id }, { limit: 1 })[0];
|
|
59
|
+
if (existing === undefined)
|
|
60
|
+
throw missing(input.id);
|
|
61
|
+
const edited = applyEdits(existing.content, input.edits);
|
|
62
|
+
const text = contentFor(existing.format, edited.text);
|
|
63
|
+
assertWithinLimit(input.id, text);
|
|
64
|
+
artifacts.update(existing.id, { content: text, version: existing.version + 1, updatedAt: now() });
|
|
65
|
+
return { id: input.id, version: existing.version + 1, replacements: edited.replacements, firstChangedLine: edited.firstChangedLine };
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** What the artifact card shows of a chat's artifact (ADR 0009, 177), or nothing when the chat has none by that id. */
|
|
69
|
+
export async function artifactCard(ctx, sessionId, id) {
|
|
70
|
+
const found = (await records(ctx.store).artifacts.find({ sessionId: await chatOf(ctx, sessionId), artifactId: id }, { limit: 1 }))[0];
|
|
71
|
+
return found === undefined ? undefined : { id, title: found.title, format: found.format, version: found.version };
|
|
72
|
+
}
|
|
73
|
+
const commands = artifactCommands;
|
|
74
|
+
export function registerArtifactConnector(ctx) {
|
|
75
|
+
ctx.registerCommand('kvcoder.artifact.write', {
|
|
76
|
+
description: commands.write.description,
|
|
77
|
+
input: callInput(payloads.write),
|
|
78
|
+
output: z.object({ id: z.string(), version: z.number().int(), created: z.boolean(), bytes: z.number().int() }),
|
|
79
|
+
retries: 0,
|
|
80
|
+
handle: async ({ sessionId, payload }) => writeArtifact(ctx, await chatOf(ctx, sessionId), payload),
|
|
81
|
+
});
|
|
82
|
+
ctx.registerCommand('kvcoder.artifact.edit', {
|
|
83
|
+
description: commands.edit.description,
|
|
84
|
+
input: callInput(payloads.edit),
|
|
85
|
+
output: z.object({ id: z.string(), version: z.number().int(), replacements: z.number().int(), firstChangedLine: z.number().int() }),
|
|
86
|
+
retries: 0,
|
|
87
|
+
handle: async ({ sessionId, payload }) => editArtifact(ctx, await chatOf(ctx, sessionId), payload),
|
|
88
|
+
});
|
|
89
|
+
ctx.registerQuery('kvcoder.artifact.content.get', {
|
|
90
|
+
description: commands.get.description,
|
|
91
|
+
input: callInput(payloads.get),
|
|
92
|
+
output: z.object({ id: z.string(), title: z.string(), format: z.enum(artifactFormats), version: z.number().int(), content: z.string() }),
|
|
93
|
+
handle: async ({ sessionId, payload }) => {
|
|
94
|
+
const found = (await records(ctx.store).artifacts.find({ sessionId: await chatOf(ctx, sessionId), artifactId: payload.id }, { limit: 1 }))[0];
|
|
95
|
+
if (found === undefined)
|
|
96
|
+
throw missing(payload.id);
|
|
97
|
+
return { id: payload.id, title: found.title, format: found.format, version: found.version, content: found.content };
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=artifact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact.js","sourceRoot":"","sources":["../../src/connectors/artifact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,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,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;QACxI,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE;YACvC,MAAM,KAAK,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9I,IAAI,KAAK,KAAK,SAAS;gBAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACnD,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QACtH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z, type Ctx } from '@kvman/sdk';
|
|
2
|
+
import type { QuestionDoc } from '../schemas/records.ts';
|
|
3
|
+
/** What the prompt's index says the connector is for. */
|
|
4
|
+
export declare const askDescription = "Put a question to the person and wait for the answer. Use it when you need a decision, a missing detail, or a go-ahead before a risky step, instead of guessing.";
|
|
5
|
+
export declare const askCommands: {
|
|
6
|
+
text: {
|
|
7
|
+
registration: string;
|
|
8
|
+
description: string;
|
|
9
|
+
payload: z.ZodObject<{
|
|
10
|
+
prompt: z.ZodString;
|
|
11
|
+
placeholder: z.ZodExactOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
asks: false;
|
|
14
|
+
result: string;
|
|
15
|
+
};
|
|
16
|
+
choice: {
|
|
17
|
+
registration: string;
|
|
18
|
+
description: string;
|
|
19
|
+
payload: z.ZodObject<{
|
|
20
|
+
prompt: z.ZodString;
|
|
21
|
+
multiple: z.ZodBoolean;
|
|
22
|
+
options: z.ZodArray<z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
label: z.ZodString;
|
|
25
|
+
description: z.ZodExactOptional<z.ZodString>;
|
|
26
|
+
}, z.core.$strict>>;
|
|
27
|
+
other: z.ZodExactOptional<z.ZodBoolean>;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
asks: false;
|
|
30
|
+
result: string;
|
|
31
|
+
};
|
|
32
|
+
confirm: {
|
|
33
|
+
registration: string;
|
|
34
|
+
description: string;
|
|
35
|
+
payload: z.ZodObject<{
|
|
36
|
+
prompt: z.ZodString;
|
|
37
|
+
danger: z.ZodExactOptional<z.ZodBoolean>;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
asks: false;
|
|
40
|
+
result: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type QuestionKind = QuestionDoc['kind'];
|
|
44
|
+
/** The kinds of question the agent asks: the `ask` connector's commands. */
|
|
45
|
+
export declare const askKinds: readonly ["text", "choice", "confirm"];
|
|
46
|
+
export declare const isAskKind: (command: string) => command is (typeof askKinds)[number];
|
|
47
|
+
export declare function registerAskConnector(ctx: Ctx): void;
|
|
48
|
+
/** An answer checked against its question: the call's result, or an approval's decision. */
|
|
49
|
+
export declare function checkedAnswer(question: QuestionDoc, answer: unknown): {
|
|
50
|
+
kind: 'result';
|
|
51
|
+
text: string;
|
|
52
|
+
} | {
|
|
53
|
+
kind: 'approval';
|
|
54
|
+
approved: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** What a question, or an approval, dismissed by a message returns to the model (plan 08 §8.1). */
|
|
57
|
+
export declare function dismissedText(kind: QuestionKind): string;
|
|
58
|
+
//# sourceMappingURL=ask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../src/connectors/ask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOzD,yDAAyD;AACzD,eAAO,MAAM,cAAc,qKAAqK,CAAC;AAsBjM,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIoB,CAAC;AAE7C,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAE/C,4EAA4E;AAC5E,eAAO,MAAM,QAAQ,wCAAyC,CAAC;AAE/D,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,KAAG,OAAO,IAAI,CAAC,OAAO,QAAQ,EAAE,MAAM,CAA8C,CAAC;AAI9H,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAKnD;AAqBD,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAahJ;AAED,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { jsonOutput } from "../connector-call.js";
|
|
3
|
+
import { invalid } from "../problems.js";
|
|
4
|
+
import { callInput } from "./connector-command.js";
|
|
5
|
+
// The `ask` connector (plan 08 §8.5): a question suspends the turn until the person answers; the answer becomes the
|
|
6
|
+
// call's result, and a dismissal gives `{ "dismissed": true }`. Each command's check validates its payload as a kernel
|
|
7
|
+
// job, and the step then records the question (ADR 0011, 9). Answers are checked (ADR 0009, 102).
|
|
8
|
+
/** What the prompt's index says the connector is for. */
|
|
9
|
+
export const askDescription = 'Put a question to the person and wait for the answer. Use it when you need a decision, a missing detail, or a go-ahead before a risky step, instead of guessing.';
|
|
10
|
+
const prompt = z.string().min(1).describe('The question, as the person reads it.');
|
|
11
|
+
const payloads = {
|
|
12
|
+
text: z.strictObject({ prompt, placeholder: z.string().describe('A hint shown in the empty answer box.').exactOptional() }),
|
|
13
|
+
choice: z.strictObject({
|
|
14
|
+
prompt,
|
|
15
|
+
multiple: z.boolean().describe('true when the person may choose several options.'),
|
|
16
|
+
options: z
|
|
17
|
+
.array(z.strictObject({ id: z.string().min(1).describe('What the answer names the option by.'), label: z.string().min(1).describe('The option, as the person reads it.'), description: z.string().describe('A line that explains the option.').exactOptional() }))
|
|
18
|
+
.min(2)
|
|
19
|
+
.max(10)
|
|
20
|
+
.refine((options) => new Set(options.map((option) => option.id)).size === options.length, 'Option ids must differ.')
|
|
21
|
+
.describe('Two to ten options, the recommended one first.'),
|
|
22
|
+
other: z.boolean().describe('true lets the person write an answer of their own.').exactOptional(),
|
|
23
|
+
}),
|
|
24
|
+
confirm: z.strictObject({ prompt, danger: z.boolean().describe('true marks the confirmation as destructive.').exactOptional() }),
|
|
25
|
+
};
|
|
26
|
+
const dismissed = ', or { "dismissed": true }.';
|
|
27
|
+
export const askCommands = {
|
|
28
|
+
text: { registration: 'kvcoder.ask.text.check', description: 'Asks the person for a free answer and waits for it.', payload: payloads.text, asks: false, result: `the person's answer: { "text" }${dismissed}` },
|
|
29
|
+
choice: { registration: 'kvcoder.ask.choice.check', description: 'Asks the person to choose among options and waits for the answer.', payload: payloads.choice, asks: false, result: `the person's answer: { "selected": [ids], "other"? }${dismissed}` },
|
|
30
|
+
confirm: { registration: 'kvcoder.ask.confirm.check', description: 'Asks the person yes or no and waits for the answer.', payload: payloads.confirm, asks: false, result: `the person's answer: { "confirmed" }${dismissed}` },
|
|
31
|
+
};
|
|
32
|
+
/** The kinds of question the agent asks: the `ask` connector's commands. */
|
|
33
|
+
export const askKinds = ['text', 'choice', 'confirm'];
|
|
34
|
+
export const isAskKind = (command) => askKinds.some((kind) => kind === command);
|
|
35
|
+
const noOutput = z.object({});
|
|
36
|
+
export function registerAskConnector(ctx) {
|
|
37
|
+
for (const kind of askKinds) {
|
|
38
|
+
const command = askCommands[kind];
|
|
39
|
+
ctx.registerCommand(command.registration, { description: command.description, input: callInput(command.payload), output: noOutput, retries: 0, handle: () => ({}) });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const dismissedSchema = z.strictObject({ dismissed: z.literal(true) });
|
|
43
|
+
const answerSchemas = {
|
|
44
|
+
text: z.strictObject({ text: z.string() }),
|
|
45
|
+
choice: z.strictObject({ selected: z.array(z.string()), other: z.string().exactOptional() }),
|
|
46
|
+
confirm: z.strictObject({ confirmed: z.boolean() }),
|
|
47
|
+
approval: z.strictObject({ confirmed: z.boolean() }),
|
|
48
|
+
};
|
|
49
|
+
function checkChoice(question, answer) {
|
|
50
|
+
const parsed = payloads.choice.parse(question);
|
|
51
|
+
const ids = new Set(parsed.options.map((option) => option.id));
|
|
52
|
+
const unknown = answer.selected.find((id) => !ids.has(id));
|
|
53
|
+
if (unknown !== undefined)
|
|
54
|
+
throw invalid(`${unknown} isn't one of the options.`, { selected: unknown });
|
|
55
|
+
if (answer.other !== undefined && parsed.other !== true)
|
|
56
|
+
throw invalid('This question offers no other answer.');
|
|
57
|
+
const count = answer.selected.length + (answer.other === undefined ? 0 : 1);
|
|
58
|
+
if (!parsed.multiple && count !== 1)
|
|
59
|
+
throw invalid('Choose exactly one option.');
|
|
60
|
+
}
|
|
61
|
+
/** An answer checked against its question: the call's result, or an approval's decision. */
|
|
62
|
+
export function checkedAnswer(question, answer) {
|
|
63
|
+
const dismissed = dismissedSchema.safeParse(answer);
|
|
64
|
+
if (question.kind === 'approval') {
|
|
65
|
+
if (dismissed.success)
|
|
66
|
+
return { kind: 'approval', approved: false };
|
|
67
|
+
const parsed = answerSchemas.approval.safeParse(answer);
|
|
68
|
+
if (!parsed.success)
|
|
69
|
+
throw invalid('An approval is answered { confirmed } or { dismissed: true }.');
|
|
70
|
+
return { kind: 'approval', approved: parsed.data.confirmed };
|
|
71
|
+
}
|
|
72
|
+
if (dismissed.success)
|
|
73
|
+
return { kind: 'result', text: jsonOutput({ dismissed: true }).output };
|
|
74
|
+
const parsed = answerSchemas[question.kind].safeParse(answer);
|
|
75
|
+
if (!parsed.success)
|
|
76
|
+
throw invalid(`The answer doesn't fit a ${question.kind} question.`);
|
|
77
|
+
if ('selected' in parsed.data)
|
|
78
|
+
checkChoice(question.question, parsed.data);
|
|
79
|
+
return { kind: 'result', text: jsonOutput(parsed.data).output };
|
|
80
|
+
}
|
|
81
|
+
/** What a question, or an approval, dismissed by a message returns to the model (plan 08 §8.1). */
|
|
82
|
+
export function dismissedText(kind) {
|
|
83
|
+
return kind === 'approval' ? 'denied by the user' : 'dismissed by the user';
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=ask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.js","sourceRoot":"","sources":["../../src/connectors/ask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAkB,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAyB,MAAM,wBAAwB,CAAC;AAE1E,oHAAoH;AACpH,uHAAuH;AACvH,kGAAkG;AAElG,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG,kKAAkK,CAAC;AAEjM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,uCAAuC,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AAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;IAC/F,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9D,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,OAAO,CAAC,4BAA4B,QAAQ,CAAC,IAAI,YAAY,CAAC,CAAC;IAC1F,IAAI,UAAU,IAAI,MAAM,CAAC,IAAI;QAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AAClE,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,aAAa,CAAC,IAAkB;IAC9C,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,uBAAuB,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z, type Ctx } from '@kvman/sdk';
|
|
2
|
+
/** What the prompt's index says the connector is for. */
|
|
3
|
+
export declare const backgroundDescription = "Follow up on what you started with background set to true: a server or other long-running shell line, or a background subagent. Use it to see its status or output, or to stop it.";
|
|
4
|
+
export declare const backgroundCommands: {
|
|
5
|
+
list: {
|
|
6
|
+
registration: string;
|
|
7
|
+
description: string;
|
|
8
|
+
payload: z.ZodObject<{}, z.core.$strict>;
|
|
9
|
+
asks: false;
|
|
10
|
+
};
|
|
11
|
+
output: {
|
|
12
|
+
registration: string;
|
|
13
|
+
description: string;
|
|
14
|
+
payload: z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
asks: false;
|
|
18
|
+
};
|
|
19
|
+
stop: {
|
|
20
|
+
registration: string;
|
|
21
|
+
description: string;
|
|
22
|
+
payload: z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
asks: false;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare function registerBackgroundConnector(ctx: Ctx): void;
|
|
29
|
+
//# sourceMappingURL=background.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../src/connectors/background.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAOzC,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,uLAAuL,CAAC;AAM1N,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;CAIa,CAAC;AAsB7C,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAuB1D"}
|