@geminixiang/mikan 1.0.0-beta.2 → 1.0.0-beta.21
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/CHANGELOG.md +388 -0
- package/README.md +49 -16
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js.map +1 -1
- package/dist/adapters/buffered-responder.d.ts +60 -0
- package/dist/adapters/buffered-responder.d.ts.map +1 -0
- package/dist/adapters/buffered-responder.js +201 -0
- package/dist/adapters/buffered-responder.js.map +1 -0
- package/dist/adapters/discord/bot.d.ts +1 -0
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +36 -67
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/discord/context.d.ts.map +1 -1
- package/dist/adapters/discord/context.js +44 -204
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/github/bot.d.ts +86 -0
- package/dist/adapters/github/bot.d.ts.map +1 -0
- package/dist/adapters/github/bot.js +640 -0
- package/dist/adapters/github/bot.js.map +1 -0
- package/dist/adapters/github/client.d.ts +122 -0
- package/dist/adapters/github/client.d.ts.map +1 -0
- package/dist/adapters/github/client.js +314 -0
- package/dist/adapters/github/client.js.map +1 -0
- package/dist/adapters/github/cloudbuild.d.ts +24 -0
- package/dist/adapters/github/cloudbuild.d.ts.map +1 -0
- package/dist/adapters/github/cloudbuild.js +71 -0
- package/dist/adapters/github/cloudbuild.js.map +1 -0
- package/dist/adapters/github/context.d.ts +9 -0
- package/dist/adapters/github/context.d.ts.map +1 -0
- package/dist/adapters/github/context.js +103 -0
- package/dist/adapters/github/context.js.map +1 -0
- package/dist/adapters/github/gcp-auth.d.ts +31 -0
- package/dist/adapters/github/gcp-auth.d.ts.map +1 -0
- package/dist/adapters/github/gcp-auth.js +196 -0
- package/dist/adapters/github/gcp-auth.js.map +1 -0
- package/dist/adapters/github/github-ops.d.ts +90 -0
- package/dist/adapters/github/github-ops.d.ts.map +1 -0
- package/dist/adapters/github/github-ops.js +405 -0
- package/dist/adapters/github/github-ops.js.map +1 -0
- package/dist/adapters/github/ids.d.ts +34 -0
- package/dist/adapters/github/ids.d.ts.map +1 -0
- package/dist/adapters/github/ids.js +53 -0
- package/dist/adapters/github/ids.js.map +1 -0
- package/dist/adapters/github/repo.d.ts +32 -0
- package/dist/adapters/github/repo.d.ts.map +1 -0
- package/dist/adapters/github/repo.js +141 -0
- package/dist/adapters/github/repo.js.map +1 -0
- package/dist/adapters/github/tool-pack.d.ts +14 -0
- package/dist/adapters/github/tool-pack.d.ts.map +1 -0
- package/dist/adapters/github/tool-pack.js +56 -0
- package/dist/adapters/github/tool-pack.js.map +1 -0
- package/dist/adapters/github/tools/checks.d.ts +24 -0
- package/dist/adapters/github/tools/checks.d.ts.map +1 -0
- package/dist/adapters/github/tools/checks.js +105 -0
- package/dist/adapters/github/tools/checks.js.map +1 -0
- package/dist/adapters/github/tools/issue.d.ts +22 -0
- package/dist/adapters/github/tools/issue.d.ts.map +1 -0
- package/dist/adapters/github/tools/issue.js +48 -0
- package/dist/adapters/github/tools/issue.js.map +1 -0
- package/dist/adapters/github/tools/pr.d.ts +22 -0
- package/dist/adapters/github/tools/pr.d.ts.map +1 -0
- package/dist/adapters/github/tools/pr.js +48 -0
- package/dist/adapters/github/tools/pr.js.map +1 -0
- package/dist/adapters/github/tools/read.d.ts +22 -0
- package/dist/adapters/github/tools/read.d.ts.map +1 -0
- package/dist/adapters/github/tools/read.js +141 -0
- package/dist/adapters/github/tools/read.js.map +1 -0
- package/dist/adapters/github/tools/review-reply.d.ts +19 -0
- package/dist/adapters/github/tools/review-reply.d.ts.map +1 -0
- package/dist/adapters/github/tools/review-reply.js +38 -0
- package/dist/adapters/github/tools/review-reply.js.map +1 -0
- package/dist/adapters/github/tools/sync.d.ts +17 -0
- package/dist/adapters/github/tools/sync.d.ts.map +1 -0
- package/dist/adapters/github/tools/sync.js +34 -0
- package/dist/adapters/github/tools/sync.js.map +1 -0
- package/dist/adapters/github/types.d.ts +350 -0
- package/dist/adapters/github/types.d.ts.map +1 -0
- package/dist/adapters/github/types.js +2 -0
- package/dist/adapters/github/types.js.map +1 -0
- package/dist/adapters/intake.d.ts +16 -5
- package/dist/adapters/intake.d.ts.map +1 -1
- package/dist/adapters/intake.js +79 -22
- package/dist/adapters/intake.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +8 -6
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +82 -134
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/context.d.ts.map +1 -1
- package/dist/adapters/slack/context.js +3 -14
- package/dist/adapters/slack/context.js.map +1 -1
- package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
- package/dist/adapters/slack/response-lifecycle.js +14 -17
- package/dist/adapters/slack/response-lifecycle.js.map +1 -1
- package/dist/adapters/slack/session.d.ts.map +1 -1
- package/dist/adapters/slack/session.js +5 -8
- package/dist/adapters/slack/session.js.map +1 -1
- package/dist/adapters/streaming.d.ts +4 -0
- package/dist/adapters/streaming.d.ts.map +1 -1
- package/dist/adapters/streaming.js +11 -0
- package/dist/adapters/streaming.js.map +1 -1
- package/dist/adapters/telegram/bot.d.ts +1 -2
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +27 -62
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +37 -174
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/adapters/types.d.ts +28 -2
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/adapters/types.js.map +1 -1
- package/dist/agent.d.ts +37 -14
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +359 -229
- package/dist/agent.js.map +1 -1
- package/dist/cli/arg-grammar.d.ts +25 -0
- package/dist/cli/arg-grammar.d.ts.map +1 -0
- package/dist/cli/arg-grammar.js +59 -0
- package/dist/cli/arg-grammar.js.map +1 -0
- package/dist/cli/boot.d.ts +16 -0
- package/dist/cli/boot.d.ts.map +1 -0
- package/dist/cli/boot.js +119 -0
- package/dist/cli/boot.js.map +1 -0
- package/dist/cli/download.d.ts.map +1 -0
- package/dist/cli/download.js.map +1 -0
- package/dist/cli/ext-git.d.ts +22 -0
- package/dist/cli/ext-git.d.ts.map +1 -0
- package/dist/cli/ext-git.js +76 -0
- package/dist/cli/ext-git.js.map +1 -0
- package/dist/cli/ext.d.ts +2 -0
- package/dist/cli/ext.d.ts.map +1 -0
- package/dist/cli/ext.js +215 -0
- package/dist/cli/ext.js.map +1 -0
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +2 -1
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/auto-reply.d.ts.map +1 -1
- package/dist/commands/auto-reply.js +2 -6
- package/dist/commands/auto-reply.js.map +1 -1
- package/dist/commands/extensions.d.ts.map +1 -1
- package/dist/commands/extensions.js +18 -8
- package/dist/commands/extensions.js.map +1 -1
- package/dist/commands/login.d.ts +2 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +35 -3
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/manifest.d.ts +72 -0
- package/dist/commands/manifest.d.ts.map +1 -0
- package/dist/commands/manifest.js +121 -0
- package/dist/commands/manifest.js.map +1 -0
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +11 -9
- package/dist/commands/model.js.map +1 -1
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +2 -1
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/sandbox.d.ts.map +1 -1
- package/dist/commands/sandbox.js +23 -17
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/text.d.ts +2 -0
- package/dist/commands/text.d.ts.map +1 -0
- package/dist/commands/text.js +16 -0
- package/dist/commands/text.js.map +1 -0
- package/dist/commands/types.d.ts +14 -1
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js.map +1 -1
- package/dist/config.d.ts +1 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +98 -95
- package/dist/config.js.map +1 -1
- package/dist/env-manifest.d.ts +35 -0
- package/dist/env-manifest.d.ts.map +1 -0
- package/dist/env-manifest.js +225 -0
- package/dist/env-manifest.js.map +1 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +9 -73
- package/dist/events.js.map +1 -1
- package/dist/execution-resolver.d.ts +4 -2
- package/dist/execution-resolver.d.ts.map +1 -1
- package/dist/execution-resolver.js +54 -41
- package/dist/execution-resolver.js.map +1 -1
- package/dist/harness/event-format.d.ts +66 -0
- package/dist/harness/event-format.d.ts.map +1 -0
- package/dist/harness/event-format.js +112 -0
- package/dist/harness/event-format.js.map +1 -0
- package/dist/harness/extensions/loader.d.ts +44 -11
- package/dist/harness/extensions/loader.d.ts.map +1 -1
- package/dist/harness/extensions/loader.js +273 -84
- package/dist/harness/extensions/loader.js.map +1 -1
- package/dist/harness/extensions/registry.d.ts +48 -1
- package/dist/harness/extensions/registry.d.ts.map +1 -1
- package/dist/harness/extensions/registry.js +146 -0
- package/dist/harness/extensions/registry.js.map +1 -1
- package/dist/harness/extensions/types.d.ts +165 -22
- package/dist/harness/extensions/types.d.ts.map +1 -1
- package/dist/harness/extensions/types.js.map +1 -1
- package/dist/harness/index.d.ts +6 -5
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +3 -2
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/models.d.ts +5 -0
- package/dist/harness/models.d.ts.map +1 -1
- package/dist/harness/models.js +10 -0
- package/dist/harness/models.js.map +1 -1
- package/dist/harness/runner.d.ts +37 -2
- package/dist/harness/runner.d.ts.map +1 -1
- package/dist/harness/runner.js +107 -23
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/session-store.d.ts +4 -1
- package/dist/harness/session-store.d.ts.map +1 -1
- package/dist/harness/session-store.js +11 -2
- package/dist/harness/session-store.js.map +1 -1
- package/dist/harness/subagent-runner.d.ts +34 -0
- package/dist/harness/subagent-runner.d.ts.map +1 -0
- package/dist/harness/subagent-runner.js +339 -0
- package/dist/harness/subagent-runner.js.map +1 -0
- package/dist/harness/types.d.ts +53 -0
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.js +260 -109
- package/dist/main.js.map +1 -1
- package/dist/observability/instrument.js +6 -4
- package/dist/observability/instrument.js.map +1 -1
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +3 -2
- package/dist/observability/sentry.js.map +1 -1
- package/dist/provisioner.d.ts.map +1 -1
- package/dist/provisioner.js +2 -5
- package/dist/provisioner.js.map +1 -1
- package/dist/runtime/conversation-runtime.d.ts +1 -1
- package/dist/runtime/conversation-runtime.d.ts.map +1 -1
- package/dist/runtime/conversation-runtime.js +276 -43
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/types.d.ts +36 -5
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/sandbox/cloudflare.d.ts +3 -0
- package/dist/sandbox/cloudflare.d.ts.map +1 -1
- package/dist/sandbox/cloudflare.js +10 -0
- package/dist/sandbox/cloudflare.js.map +1 -1
- package/dist/sandbox/container.d.ts +4 -0
- package/dist/sandbox/container.d.ts.map +1 -1
- package/dist/sandbox/container.js +11 -2
- package/dist/sandbox/container.js.map +1 -1
- package/dist/sandbox/firecracker.d.ts +3 -0
- package/dist/sandbox/firecracker.d.ts.map +1 -1
- package/dist/sandbox/firecracker.js +10 -1
- package/dist/sandbox/firecracker.js.map +1 -1
- package/dist/sandbox/gondolin-bootstrap.d.ts +26 -0
- package/dist/sandbox/gondolin-bootstrap.d.ts.map +1 -0
- package/dist/sandbox/gondolin-bootstrap.js +27 -0
- package/dist/sandbox/gondolin-bootstrap.js.map +1 -0
- package/dist/sandbox/gondolin-contract.d.ts +125 -0
- package/dist/sandbox/gondolin-contract.d.ts.map +1 -0
- package/dist/sandbox/gondolin-contract.js +155 -0
- package/dist/sandbox/gondolin-contract.js.map +1 -0
- package/dist/sandbox/gondolin-fleet.d.ts +104 -0
- package/dist/sandbox/gondolin-fleet.d.ts.map +1 -0
- package/dist/sandbox/gondolin-fleet.js +330 -0
- package/dist/sandbox/gondolin-fleet.js.map +1 -0
- package/dist/sandbox/gondolin-gateway.d.ts +86 -0
- package/dist/sandbox/gondolin-gateway.d.ts.map +1 -0
- package/dist/sandbox/gondolin-gateway.js +407 -0
- package/dist/sandbox/gondolin-gateway.js.map +1 -0
- package/dist/sandbox/gondolin-inventory.d.ts +75 -0
- package/dist/sandbox/gondolin-inventory.d.ts.map +1 -0
- package/dist/sandbox/gondolin-inventory.js +257 -0
- package/dist/sandbox/gondolin-inventory.js.map +1 -0
- package/dist/sandbox/gondolin-join.d.ts +62 -0
- package/dist/sandbox/gondolin-join.d.ts.map +1 -0
- package/dist/sandbox/gondolin-join.js +261 -0
- package/dist/sandbox/gondolin-join.js.map +1 -0
- package/dist/sandbox/gondolin-nfs-advisory.d.ts +15 -0
- package/dist/sandbox/gondolin-nfs-advisory.d.ts.map +1 -0
- package/dist/sandbox/gondolin-nfs-advisory.js +60 -0
- package/dist/sandbox/gondolin-nfs-advisory.js.map +1 -0
- package/dist/sandbox/gondolin-placement.d.ts +30 -0
- package/dist/sandbox/gondolin-placement.d.ts.map +1 -0
- package/dist/sandbox/gondolin-placement.js +77 -0
- package/dist/sandbox/gondolin-placement.js.map +1 -0
- package/dist/sandbox/gondolin-recovery.d.ts +33 -0
- package/dist/sandbox/gondolin-recovery.d.ts.map +1 -0
- package/dist/sandbox/gondolin-recovery.js +39 -0
- package/dist/sandbox/gondolin-recovery.js.map +1 -0
- package/dist/sandbox/gondolin-remote.d.ts +70 -0
- package/dist/sandbox/gondolin-remote.d.ts.map +1 -0
- package/dist/sandbox/gondolin-remote.js +325 -0
- package/dist/sandbox/gondolin-remote.js.map +1 -0
- package/dist/sandbox/gondolin-worker-client.d.ts +135 -0
- package/dist/sandbox/gondolin-worker-client.d.ts.map +1 -0
- package/dist/sandbox/gondolin-worker-client.js +323 -0
- package/dist/sandbox/gondolin-worker-client.js.map +1 -0
- package/dist/sandbox/gondolin-worker-main.d.ts +2 -0
- package/dist/sandbox/gondolin-worker-main.d.ts.map +1 -0
- package/dist/sandbox/gondolin-worker-main.js +22 -0
- package/dist/sandbox/gondolin-worker-main.js.map +1 -0
- package/dist/sandbox/gondolin-worker.d.ts +17 -0
- package/dist/sandbox/gondolin-worker.d.ts.map +1 -0
- package/dist/sandbox/gondolin-worker.js +201 -0
- package/dist/sandbox/gondolin-worker.js.map +1 -0
- package/dist/sandbox/gondolin.d.ts +53 -0
- package/dist/sandbox/gondolin.d.ts.map +1 -0
- package/dist/sandbox/gondolin.js +429 -0
- package/dist/sandbox/gondolin.js.map +1 -0
- package/dist/sandbox/host.d.ts +3 -0
- package/dist/sandbox/host.d.ts.map +1 -1
- package/dist/sandbox/host.js +14 -0
- package/dist/sandbox/host.js.map +1 -1
- package/dist/sandbox/identity.d.ts +21 -0
- package/dist/sandbox/identity.d.ts.map +1 -0
- package/dist/sandbox/identity.js +36 -0
- package/dist/sandbox/identity.js.map +1 -0
- package/dist/sandbox/index.d.ts +13 -4
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +19 -3
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/types.d.ts +31 -1
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sandbox/utils.d.ts +12 -0
- package/dist/sandbox/utils.d.ts.map +1 -1
- package/dist/sandbox/utils.js +38 -0
- package/dist/sandbox/utils.js.map +1 -1
- package/dist/sessions/chat-history-sync.d.ts +32 -0
- package/dist/sessions/chat-history-sync.d.ts.map +1 -0
- package/dist/sessions/{agent-memory-file-manager.js → chat-history-sync.js} +40 -113
- package/dist/sessions/chat-history-sync.js.map +1 -0
- package/dist/sessions/conversation-log.d.ts +13 -0
- package/dist/sessions/conversation-log.d.ts.map +1 -0
- package/dist/sessions/conversation-log.js +47 -0
- package/dist/sessions/conversation-log.js.map +1 -0
- package/dist/sessions/history-line.d.ts +20 -0
- package/dist/sessions/history-line.d.ts.map +1 -0
- package/dist/sessions/history-line.js +24 -0
- package/dist/sessions/history-line.js.map +1 -0
- package/dist/sessions/policy.d.ts.map +1 -1
- package/dist/sessions/policy.js +5 -3
- package/dist/sessions/policy.js.map +1 -1
- package/dist/sessions/rotation.d.ts +2 -0
- package/dist/sessions/rotation.d.ts.map +1 -0
- package/dist/sessions/rotation.js +39 -0
- package/dist/sessions/rotation.js.map +1 -0
- package/dist/sessions/session-key.d.ts +31 -0
- package/dist/sessions/session-key.d.ts.map +1 -0
- package/dist/sessions/session-key.js +44 -0
- package/dist/sessions/session-key.js.map +1 -0
- package/dist/sessions/store.d.ts.map +1 -1
- package/dist/sessions/store.js +6 -12
- package/dist/sessions/store.js.map +1 -1
- package/dist/sessions/types.d.ts +2 -2
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/settings-mutation.d.ts +23 -0
- package/dist/settings-mutation.d.ts.map +1 -0
- package/dist/settings-mutation.js +42 -0
- package/dist/settings-mutation.js.map +1 -0
- package/dist/tools/bash.d.ts +3 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +24 -17
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/edit.d.ts.map +1 -1
- package/dist/tools/edit.js +9 -12
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/event.d.ts +1 -1
- package/dist/tools/event.d.ts.map +1 -1
- package/dist/tools/event.js +53 -43
- package/dist/tools/event.js.map +1 -1
- package/dist/tools/generate-image.d.ts +17 -0
- package/dist/tools/generate-image.d.ts.map +1 -0
- package/dist/tools/generate-image.js +63 -0
- package/dist/tools/generate-image.js.map +1 -0
- package/dist/tools/host-fn-tool.d.ts +21 -0
- package/dist/tools/host-fn-tool.d.ts.map +1 -0
- package/dist/tools/host-fn-tool.js +32 -0
- package/dist/tools/host-fn-tool.js.map +1 -0
- package/dist/tools/index.d.ts +17 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +28 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/react.d.ts +15 -0
- package/dist/tools/react.d.ts.map +1 -0
- package/dist/tools/react.js +29 -0
- package/dist/tools/react.js.map +1 -0
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +7 -26
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/sandbox.d.ts +2 -2
- package/dist/tools/sandbox.d.ts.map +1 -1
- package/dist/tools/sandbox.js +13 -9
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/subagent-slots.d.ts +28 -0
- package/dist/tools/subagent-slots.d.ts.map +1 -0
- package/dist/tools/subagent-slots.js +57 -0
- package/dist/tools/subagent-slots.js.map +1 -0
- package/dist/tools/subagent.d.ts +74 -0
- package/dist/tools/subagent.d.ts.map +1 -0
- package/dist/tools/subagent.js +335 -0
- package/dist/tools/subagent.js.map +1 -0
- package/dist/tools/types.d.ts +40 -6
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/write.d.ts.map +1 -1
- package/dist/tools/write.js +1 -8
- package/dist/tools/write.js.map +1 -1
- package/dist/trigger.d.ts.map +1 -1
- package/dist/trigger.js +1 -2
- package/dist/trigger.js.map +1 -1
- package/dist/types.d.ts +144 -31
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/date.d.ts +1 -1
- package/dist/utils/date.js +1 -1
- package/dist/utils/date.js.map +1 -1
- package/dist/vault/disabled.d.ts +9 -0
- package/dist/vault/disabled.d.ts.map +1 -0
- package/dist/vault/disabled.js +22 -0
- package/dist/vault/disabled.js.map +1 -0
- package/dist/vault/index.d.ts +0 -2
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/index.js +1 -32
- package/dist/vault/index.js.map +1 -1
- package/dist/vault/injection.d.ts +20 -0
- package/dist/vault/injection.d.ts.map +1 -0
- package/dist/vault/injection.js +27 -0
- package/dist/vault/injection.js.map +1 -0
- package/dist/vault/policy.d.ts +20 -0
- package/dist/vault/policy.d.ts.map +1 -0
- package/dist/vault/policy.js +20 -0
- package/dist/vault/policy.js.map +1 -0
- package/dist/vault/types.d.ts +0 -2
- package/dist/vault/types.d.ts.map +1 -1
- package/dist/vault/types.js.map +1 -1
- package/dist/web/admin/portal.d.ts +27 -0
- package/dist/web/admin/portal.d.ts.map +1 -1
- package/dist/web/admin/portal.js +117 -154
- package/dist/web/admin/portal.js.map +1 -1
- package/dist/web/admin/types.d.ts +6 -0
- package/dist/web/admin/types.d.ts.map +1 -1
- package/dist/web/admin/types.js.map +1 -1
- package/dist/web/agent-events/portal.d.ts.map +1 -1
- package/dist/web/agent-events/portal.js +2 -1
- package/dist/web/agent-events/portal.js.map +1 -1
- package/dist/web/login/oauth.d.ts +2 -3
- package/dist/web/login/oauth.d.ts.map +1 -1
- package/dist/web/login/oauth.js +0 -31
- package/dist/web/login/oauth.js.map +1 -1
- package/dist/web/login/portal.js +1 -1
- package/dist/web/login/portal.js.map +1 -1
- package/dist/web/login/types.d.ts +0 -11
- package/dist/web/login/types.d.ts.map +1 -1
- package/dist/web/login/types.js.map +1 -1
- package/dist/web/portal-shell.d.ts +4 -0
- package/dist/web/portal-shell.d.ts.map +1 -0
- package/dist/{portal-shell.js → web/portal-shell.js} +2 -2
- package/dist/web/portal-shell.js.map +1 -0
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +7 -0
- package/dist/web/server.js.map +1 -1
- package/dist/web/session-view/command.d.ts.map +1 -1
- package/dist/web/session-view/command.js +4 -1
- package/dist/web/session-view/command.js.map +1 -1
- package/dist/web/session-view/portal.d.ts.map +1 -1
- package/dist/web/session-view/portal.js +4 -3
- package/dist/web/session-view/portal.js.map +1 -1
- package/dist/web/session-view/service.d.ts.map +1 -1
- package/dist/web/session-view/service.js +2 -1
- package/dist/web/session-view/service.js.map +1 -1
- package/dist/web/session-view/types.d.ts +2 -1
- package/dist/web/session-view/types.d.ts.map +1 -1
- package/dist/web/session-view/types.js.map +1 -1
- package/package.json +7 -4
- package/dist/download.d.ts.map +0 -1
- package/dist/download.js.map +0 -1
- package/dist/model-registry.d.ts +0 -4
- package/dist/model-registry.d.ts.map +0 -1
- package/dist/model-registry.js +0 -7
- package/dist/model-registry.js.map +0 -1
- package/dist/portal-shell.d.ts +0 -4
- package/dist/portal-shell.d.ts.map +0 -1
- package/dist/portal-shell.js.map +0 -1
- package/dist/runtime/agent-run-controller.d.ts +0 -31
- package/dist/runtime/agent-run-controller.d.ts.map +0 -1
- package/dist/runtime/agent-run-controller.js +0 -195
- package/dist/runtime/agent-run-controller.js.map +0 -1
- package/dist/sessions/agent-memory-file-manager.d.ts +0 -19
- package/dist/sessions/agent-memory-file-manager.d.ts.map +0 -1
- package/dist/sessions/agent-memory-file-manager.js.map +0 -1
- package/dist/vault/routing.d.ts +0 -3
- package/dist/vault/routing.d.ts.map +0 -1
- package/dist/vault/routing.js +0 -13
- package/dist/vault/routing.js.map +0 -1
- /package/dist/{download.d.ts → cli/download.d.ts} +0 -0
- /package/dist/{download.js → cli/download.js} +0 -0
package/dist/tools/event.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, readdir, readFile, rm, stat } from "node:fs/promises";
|
|
2
2
|
import { basename, join } from "node:path";
|
|
3
3
|
import { Type } from "@sinclair/typebox";
|
|
4
|
+
import { buildEventPayload, EventTypeSchema, parseEventPayload } from "../harness/event-format.js";
|
|
4
5
|
import * as log from "../log.js";
|
|
5
6
|
import { atomicWritePrivateFile } from "../utils/fs-atomic.js";
|
|
6
7
|
const eventSchema = Type.Object({
|
|
@@ -20,7 +21,7 @@ const eventSchema = Type.Object({
|
|
|
20
21
|
label: Type.Optional(Type.String({
|
|
21
22
|
description: "Brief description of the event you're scheduling (shown to user)",
|
|
22
23
|
})),
|
|
23
|
-
type: Type.Optional(
|
|
24
|
+
type: Type.Optional(EventTypeSchema),
|
|
24
25
|
text: Type.Optional(Type.String({
|
|
25
26
|
description: "A self-contained task for the future run. Include the necessary context, tone, and constraints in the text itself because events do not inherit normal conversation history.",
|
|
26
27
|
})),
|
|
@@ -52,17 +53,42 @@ export class HostEventStore {
|
|
|
52
53
|
const entries = await readdir(this.eventsDir, { withFileTypes: true });
|
|
53
54
|
const events = await Promise.all(entries
|
|
54
55
|
.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
|
|
55
|
-
.map(async (entry) =>
|
|
56
|
-
|
|
56
|
+
.map(async (entry) => {
|
|
57
|
+
try {
|
|
58
|
+
return await this.read(entry.name);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Keep unparseable files visible (payload: null) so consumers can
|
|
62
|
+
// surface and delete them; skip files that vanished mid-listing.
|
|
63
|
+
try {
|
|
64
|
+
const fileStat = await stat(join(this.eventsDir, entry.name));
|
|
65
|
+
return {
|
|
66
|
+
filename: entry.name,
|
|
67
|
+
payload: null,
|
|
68
|
+
size: fileStat.size,
|
|
69
|
+
mtimeMs: fileStat.mtimeMs,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
return events
|
|
78
|
+
.filter((event) => event !== null)
|
|
79
|
+
.toSorted((a, b) => a.filename.localeCompare(b.filename));
|
|
57
80
|
}
|
|
58
81
|
async read(filename) {
|
|
59
82
|
const safeFilename = validateEventFilename(filename);
|
|
60
83
|
const filePath = join(this.eventsDir, safeFilename);
|
|
61
84
|
const [raw, fileStat] = await Promise.all([readFile(filePath, "utf-8"), stat(filePath)]);
|
|
62
|
-
|
|
85
|
+
// Validation (shape, per-type fields, channelId alias) is owned by the
|
|
86
|
+
// event-format module; files that fail it surface as payload:null in
|
|
87
|
+
// list() and as errors here.
|
|
88
|
+
const payload = parseEventPayload(raw, safeFilename);
|
|
63
89
|
return {
|
|
64
90
|
filename: safeFilename,
|
|
65
|
-
payload
|
|
91
|
+
payload,
|
|
66
92
|
size: fileStat.size,
|
|
67
93
|
mtimeMs: fileStat.mtimeMs,
|
|
68
94
|
};
|
|
@@ -107,7 +133,7 @@ export function createEventTool(eventStore) {
|
|
|
107
133
|
const conversationId = eventContext.conversationId;
|
|
108
134
|
const scopedEvents = params.scope === "all"
|
|
109
135
|
? events
|
|
110
|
-
: events.filter((event) => event.payload
|
|
136
|
+
: events.filter((event) => event.payload?.conversationId === conversationId);
|
|
111
137
|
return {
|
|
112
138
|
content: [
|
|
113
139
|
{
|
|
@@ -138,7 +164,7 @@ export function createEventTool(eventStore) {
|
|
|
138
164
|
details: undefined,
|
|
139
165
|
};
|
|
140
166
|
}
|
|
141
|
-
const payload =
|
|
167
|
+
const payload = buildToolEventPayload(params, eventContext);
|
|
142
168
|
const filename = action === "update"
|
|
143
169
|
? requireFilename(params)
|
|
144
170
|
: `${sanitizeFileSegment(params.filenamePrefix || payload.type || "event")}-${Date.now()}.json`;
|
|
@@ -166,63 +192,47 @@ export function createEventTool(eventStore) {
|
|
|
166
192
|
},
|
|
167
193
|
};
|
|
168
194
|
}
|
|
169
|
-
function
|
|
195
|
+
function buildToolEventPayload(params, context) {
|
|
170
196
|
if (!params.type) {
|
|
171
197
|
throw new Error("`type` is required for create and update actions");
|
|
172
198
|
}
|
|
173
199
|
if (!params.text) {
|
|
174
200
|
throw new Error("`text` is required for create and update actions");
|
|
175
201
|
}
|
|
176
|
-
|
|
202
|
+
// Per-type field rules live in the event-format module. No sessionKey or
|
|
203
|
+
// threadTs in the payload: reminders should fire as top-level messages,
|
|
204
|
+
// not buried in old threads.
|
|
205
|
+
const payload = buildEventPayload({
|
|
206
|
+
type: params.type,
|
|
177
207
|
platform: context.platform,
|
|
178
208
|
conversationId: context.conversationId,
|
|
179
209
|
conversationKind: context.conversationKind,
|
|
180
210
|
userId: context.userId,
|
|
181
211
|
text: params.text,
|
|
182
|
-
|
|
183
|
-
if (params.type === "immediate") {
|
|
184
|
-
return {
|
|
185
|
-
...base,
|
|
186
|
-
type: "immediate",
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
if (params.type === "one-shot") {
|
|
190
|
-
if (!params.at) {
|
|
191
|
-
throw new Error("`at` is required for one-shot events");
|
|
192
|
-
}
|
|
193
|
-
const atTime = new Date(params.at).getTime();
|
|
194
|
-
if (Number.isNaN(atTime)) {
|
|
195
|
-
throw new Error("`at` must be a valid ISO 8601 timestamp with UTC offset");
|
|
196
|
-
}
|
|
197
|
-
if (atTime <= Date.now()) {
|
|
198
|
-
throw new Error(`\`at\` must be in the future; got ${params.at} (now=${new Date().toISOString()}). Check the timezone offset.`);
|
|
199
|
-
}
|
|
200
|
-
// No sessionKey or threadTs: reminders should fire as top-level messages, not buried in old threads
|
|
201
|
-
return { ...base, type: "one-shot", at: params.at };
|
|
202
|
-
}
|
|
203
|
-
if (!params.schedule) {
|
|
204
|
-
throw new Error("`schedule` is required for periodic events");
|
|
205
|
-
}
|
|
206
|
-
if (!params.timezone) {
|
|
207
|
-
throw new Error("`timezone` is required for periodic events");
|
|
208
|
-
}
|
|
209
|
-
return {
|
|
210
|
-
...base,
|
|
211
|
-
type: "periodic",
|
|
212
|
+
at: params.at,
|
|
212
213
|
schedule: params.schedule,
|
|
213
214
|
timezone: params.timezone,
|
|
214
|
-
};
|
|
215
|
+
});
|
|
216
|
+
// Tool-side write policy, not format knowledge: a reminder in the past
|
|
217
|
+
// would be deleted unfired by the watcher, so reject it here.
|
|
218
|
+
if (payload.type === "one-shot" && new Date(payload.at).getTime() <= Date.now()) {
|
|
219
|
+
throw new Error(`\`at\` must be in the future; got ${payload.at} (now=${new Date().toISOString()}). Check the timezone offset.`);
|
|
220
|
+
}
|
|
221
|
+
return payload;
|
|
215
222
|
}
|
|
216
223
|
function formatEventWriteResult(action, filename, payload) {
|
|
217
224
|
const scheduledVerb = action === "update" ? "Updated" : "Scheduled";
|
|
218
225
|
const immediateVerb = action === "update" ? "Updated" : "Queued";
|
|
226
|
+
const target = payload.platform
|
|
227
|
+
? `${payload.platform}/${payload.conversationId}`
|
|
228
|
+
: payload.conversationId;
|
|
219
229
|
switch (payload.type) {
|
|
220
230
|
case "periodic":
|
|
221
|
-
return `${scheduledVerb} periodic event ${filename} for ${
|
|
231
|
+
return `${scheduledVerb} periodic event ${filename} for ${target} (${payload.schedule} ${payload.timezone})`;
|
|
222
232
|
case "one-shot":
|
|
223
|
-
return `${scheduledVerb} one-shot event ${filename} for ${
|
|
233
|
+
return `${scheduledVerb} one-shot event ${filename} for ${target} at ${payload.at}`;
|
|
224
234
|
case "immediate":
|
|
225
|
-
return `${immediateVerb} immediate event ${filename} for ${
|
|
235
|
+
return `${immediateVerb} immediate event ${filename} for ${target}`;
|
|
226
236
|
}
|
|
227
237
|
}
|
|
228
238
|
function requireFilename(params) {
|
package/dist/tools/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/tools/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,MAAM,EAAE,IAAI,CAAC,QAAQ,CACnB,IAAI,CAAC,K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,OAAO,CAAC,cAAc,OAAO,OAAO,CAAC,EAAE,EAAE,CAAC;QAC1H,KAAK,WAAW;YACd,OAAO,GAAG,aAAa,oBAAoB,QAAQ,QAAQ,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAC5G,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,MAAuB;IAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChC,IACE,CAAC,OAAO;QACR,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC;QAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtB,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAC1B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,MAAM,SAAS,GAAG,KAAK;SACpB,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3B,OAAO,SAAS,IAAI,OAAO,CAAC;AAC9B,CAAC","sourcesContent":["import { mkdir, readdir, readFile, rm, stat } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Type } from \"@sinclair/typebox\";\nimport type { ConversationKind } from \"../adapter.js\";\nimport * as log from \"../log.js\";\nimport { atomicWritePrivateFile } from \"../utils/fs-atomic.js\";\n\nconst eventSchema = Type.Object({\n action: Type.Optional(\n Type.Union(\n [\n Type.Literal(\"create\"),\n Type.Literal(\"list\"),\n Type.Literal(\"read\"),\n Type.Literal(\"update\"),\n Type.Literal(\"delete\"),\n ],\n { description: \"CRUD action. Defaults to create for backward compatibility.\" },\n ),\n ),\n filename: Type.Optional(\n Type.String({\n description: \"Event filename for read, update, or delete actions\",\n }),\n ),\n scope: Type.Optional(\n Type.Union([Type.Literal(\"conversation\"), Type.Literal(\"all\")], {\n description:\n \"List scope. Defaults to conversation, which only shows events for the current conversation. Use all only when the user explicitly asks for all events.\",\n }),\n ),\n label: Type.Optional(\n Type.String({\n description: \"Brief description of the event you're scheduling (shown to user)\",\n }),\n ),\n type: Type.Optional(\n Type.Union([Type.Literal(\"immediate\"), Type.Literal(\"one-shot\"), Type.Literal(\"periodic\")]),\n ),\n text: Type.Optional(\n Type.String({\n description:\n \"A self-contained task for the future run. Include the necessary context, tone, and constraints in the text itself because events do not inherit normal conversation history.\",\n }),\n ),\n at: Type.Optional(\n Type.String({\n description: \"ISO 8601 timestamp with offset, required for one-shot events\",\n }),\n ),\n schedule: Type.Optional(\n Type.String({\n description: \"Cron schedule, required for periodic events\",\n }),\n ),\n timezone: Type.Optional(\n Type.String({\n description: \"IANA timezone, required for periodic events\",\n }),\n ),\n filenamePrefix: Type.Optional(\n Type.String({\n description: \"Optional filename prefix for the event file\",\n }),\n ),\n});\n\ninterface EventToolContext {\n platform: string;\n conversationId: string;\n conversationKind: ConversationKind;\n userId: string;\n}\n\ntype EventToolParams = {\n action?: \"create\" | \"list\" | \"read\" | \"update\" | \"delete\";\n filename?: string;\n scope?: \"conversation\" | \"all\";\n label?: string;\n type?: \"immediate\" | \"one-shot\" | \"periodic\";\n text?: string;\n at?: string;\n schedule?: string;\n timezone?: string;\n filenamePrefix?: string;\n};\n\nexport type { EventPayload, EventStore } from \"./types.js\";\nimport type { EventPayload, EventStore } from \"./types.js\";\n\nexport class HostEventStore implements EventStore {\n constructor(private readonly eventsDir: string) {}\n\n static fromWorkspaceDir(workspaceDir: string): HostEventStore {\n return new HostEventStore(join(workspaceDir, \"events\"));\n }\n\n async write(filename: string, payload: EventPayload): Promise<{ path: string; size: number }> {\n return this.writePayload(filename, payload);\n }\n\n async list(): Promise<\n Array<{ filename: string; payload: EventPayload; size: number; mtimeMs: number }>\n > {\n await mkdir(this.eventsDir, { recursive: true });\n const entries = await readdir(this.eventsDir, { withFileTypes: true });\n const events = await Promise.all(\n entries\n .filter((entry) => entry.isFile() && entry.name.endsWith(\".json\"))\n .map(async (entry) => this.read(entry.name)),\n );\n return events.toSorted((a, b) => a.filename.localeCompare(b.filename));\n }\n\n async read(\n filename: string,\n ): Promise<{ filename: string; payload: EventPayload; size: number; mtimeMs: number }> {\n const safeFilename = validateEventFilename(filename);\n const filePath = join(this.eventsDir, safeFilename);\n const [raw, fileStat] = await Promise.all([readFile(filePath, \"utf-8\"), stat(filePath)]);\n const parsed = JSON.parse(raw) as EventPayload;\n return {\n filename: safeFilename,\n payload: parsed,\n size: fileStat.size,\n mtimeMs: fileStat.mtimeMs,\n };\n }\n\n async update(filename: string, payload: EventPayload): Promise<{ path: string; size: number }> {\n return this.writePayload(filename, payload, true);\n }\n\n async delete(filename: string): Promise<{ deleted: boolean }> {\n const safeFilename = validateEventFilename(filename);\n await rm(join(this.eventsDir, safeFilename), { force: true });\n return { deleted: true };\n }\n\n private async writePayload(\n filename: string,\n payload: EventPayload,\n requireExisting = false,\n ): Promise<{ path: string; size: number }> {\n await mkdir(this.eventsDir, { recursive: true });\n const safeFilename = validateEventFilename(filename);\n const filePath = join(this.eventsDir, safeFilename);\n if (requireExisting) {\n await stat(filePath);\n }\n atomicWritePrivateFile(filePath, JSON.stringify(payload) + \"\\n\");\n const fileStat = await stat(filePath);\n return { path: filePath, size: fileStat.size };\n }\n}\n\nexport function createEventTool(eventStore: EventStore): {\n tool: AgentTool<typeof eventSchema>;\n setEventContext: (context: EventToolContext) => void;\n} {\n let eventContext: EventToolContext | null = null;\n\n const tool: AgentTool<typeof eventSchema> = {\n name: \"event\",\n label: \"event\",\n description:\n \"CRUD tool for scheduled events. Create immediate, one-shot, or periodic events for the current conversation. List defaults to events for the current conversation only; use scope=all only when the user explicitly asks to list all events. Event text must be self-contained because events do not inherit normal conversation history.\",\n parameters: eventSchema,\n execute: async (_toolCallId: string, params: EventToolParams, signal?: AbortSignal) => {\n if (signal?.aborted) {\n throw new Error(\"Operation aborted\");\n }\n\n if (!eventContext) {\n throw new Error(\"Event context not configured\");\n }\n\n const action = params.action ?? \"create\";\n\n if (action === \"list\") {\n const events = await eventStore.list();\n const conversationId = eventContext.conversationId;\n const scopedEvents =\n params.scope === \"all\"\n ? events\n : events.filter((event) => event.payload.conversationId === conversationId);\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(\n {\n scope: params.scope ?? \"conversation\",\n conversationId: params.scope === \"all\" ? undefined : conversationId,\n events: scopedEvents,\n },\n null,\n 2,\n ),\n },\n ],\n details: undefined,\n };\n }\n\n if (action === \"read\") {\n const filename = requireFilename(params);\n const event = await eventStore.read(filename);\n return {\n content: [{ type: \"text\", text: JSON.stringify(event, null, 2) }],\n details: undefined,\n };\n }\n\n if (action === \"delete\") {\n const filename = requireFilename(params);\n await eventStore.delete(filename);\n return {\n content: [{ type: \"text\", text: `Deleted event ${filename}` }],\n details: undefined,\n };\n }\n\n const payload = buildEventPayload(params, eventContext);\n const filename =\n action === \"update\"\n ? requireFilename(params)\n : `${sanitizeFileSegment(params.filenamePrefix || payload.type || \"event\")}-${Date.now()}.json`;\n\n log.logInfo(\n `${action === \"update\" ? \"Updating\" : \"Writing\"} event file via control plane store: ${filename} (type=${payload.type}, platform=${payload.platform}, conversation=${payload.conversationId})`,\n );\n\n try {\n const result =\n action === \"update\"\n ? await eventStore.update(filename, payload)\n : await eventStore.write(filename, payload);\n log.logInfo(\n `${action === \"update\" ? \"Updated\" : \"Wrote\"} event file via control plane store: ${result.path} (${result.size} bytes)`,\n );\n } catch (err) {\n log.logWarning(\n `Failed to ${action === \"update\" ? \"update\" : \"write\"} event file via control plane store: ${filename}`,\n String(err),\n );\n throw err;\n }\n\n return {\n content: [{ type: \"text\", text: formatEventWriteResult(action, filename, payload) }],\n details: undefined,\n };\n },\n };\n\n return {\n tool,\n setEventContext: (context: EventToolContext) => {\n eventContext = context;\n },\n };\n}\n\nfunction buildEventPayload(params: EventToolParams, context: EventToolContext): EventPayload {\n if (!params.type) {\n throw new Error(\"`type` is required for create and update actions\");\n }\n if (!params.text) {\n throw new Error(\"`text` is required for create and update actions\");\n }\n\n const base = {\n platform: context.platform,\n conversationId: context.conversationId,\n conversationKind: context.conversationKind,\n userId: context.userId,\n text: params.text,\n };\n\n if (params.type === \"immediate\") {\n return {\n ...base,\n type: \"immediate\",\n };\n }\n\n if (params.type === \"one-shot\") {\n if (!params.at) {\n throw new Error(\"`at` is required for one-shot events\");\n }\n\n const atTime = new Date(params.at).getTime();\n if (Number.isNaN(atTime)) {\n throw new Error(\"`at` must be a valid ISO 8601 timestamp with UTC offset\");\n }\n if (atTime <= Date.now()) {\n throw new Error(\n `\\`at\\` must be in the future; got ${params.at} (now=${new Date().toISOString()}). Check the timezone offset.`,\n );\n }\n\n // No sessionKey or threadTs: reminders should fire as top-level messages, not buried in old threads\n return { ...base, type: \"one-shot\", at: params.at };\n }\n\n if (!params.schedule) {\n throw new Error(\"`schedule` is required for periodic events\");\n }\n if (!params.timezone) {\n throw new Error(\"`timezone` is required for periodic events\");\n }\n return {\n ...base,\n type: \"periodic\",\n schedule: params.schedule,\n timezone: params.timezone,\n };\n}\n\nfunction formatEventWriteResult(\n action: \"create\" | \"update\",\n filename: string,\n payload: EventPayload,\n): string {\n const scheduledVerb = action === \"update\" ? \"Updated\" : \"Scheduled\";\n const immediateVerb = action === \"update\" ? \"Updated\" : \"Queued\";\n switch (payload.type) {\n case \"periodic\":\n return `${scheduledVerb} periodic event ${filename} for ${payload.platform}/${payload.conversationId} (${payload.schedule} ${payload.timezone})`;\n case \"one-shot\":\n return `${scheduledVerb} one-shot event ${filename} for ${payload.platform}/${payload.conversationId} at ${payload.at}`;\n case \"immediate\":\n return `${immediateVerb} immediate event ${filename} for ${payload.platform}/${payload.conversationId}`;\n }\n}\n\nfunction requireFilename(params: EventToolParams): string {\n if (!params.filename) {\n throw new Error(\"`filename` is required for read, update, and delete actions\");\n }\n return validateEventFilename(params.filename);\n}\n\nfunction validateEventFilename(filename: string): string {\n const trimmed = filename.trim();\n if (\n !trimmed ||\n trimmed !== basename(trimmed) ||\n trimmed.includes(\"..\") ||\n !trimmed.endsWith(\".json\")\n ) {\n throw new Error(\"Invalid event filename\");\n }\n return trimmed;\n}\n\nfunction sanitizeFileSegment(value: string): string {\n const sanitized = value\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n return sanitized || \"event\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/tools/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACnG,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,MAAM,EAAE,IAAI,CAAC,QAAQ,CACnB,IAAI,CAAC,KAAK,CACR;QACE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,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AC,QAAQ,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChC,IACE,CAAC,OAAO;QACR,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC;QAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtB,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAC1B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,MAAM,SAAS,GAAG,KAAK;SACpB,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3B,OAAO,SAAS,IAAI,OAAO,CAAC;AAC9B,CAAC","sourcesContent":["import { mkdir, readdir, readFile, rm, stat } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Type } from \"@sinclair/typebox\";\nimport type { ConversationKind } from \"../adapter.js\";\nimport { buildEventPayload, EventTypeSchema, parseEventPayload } from \"../harness/event-format.js\";\nimport * as log from \"../log.js\";\nimport { atomicWritePrivateFile } from \"../utils/fs-atomic.js\";\n\nconst eventSchema = Type.Object({\n action: Type.Optional(\n Type.Union(\n [\n Type.Literal(\"create\"),\n Type.Literal(\"list\"),\n Type.Literal(\"read\"),\n Type.Literal(\"update\"),\n Type.Literal(\"delete\"),\n ],\n { description: \"CRUD action. Defaults to create for backward compatibility.\" },\n ),\n ),\n filename: Type.Optional(\n Type.String({\n description: \"Event filename for read, update, or delete actions\",\n }),\n ),\n scope: Type.Optional(\n Type.Union([Type.Literal(\"conversation\"), Type.Literal(\"all\")], {\n description:\n \"List scope. Defaults to conversation, which only shows events for the current conversation. Use all only when the user explicitly asks for all events.\",\n }),\n ),\n label: Type.Optional(\n Type.String({\n description: \"Brief description of the event you're scheduling (shown to user)\",\n }),\n ),\n type: Type.Optional(EventTypeSchema),\n text: Type.Optional(\n Type.String({\n description:\n \"A self-contained task for the future run. Include the necessary context, tone, and constraints in the text itself because events do not inherit normal conversation history.\",\n }),\n ),\n at: Type.Optional(\n Type.String({\n description: \"ISO 8601 timestamp with offset, required for one-shot events\",\n }),\n ),\n schedule: Type.Optional(\n Type.String({\n description: \"Cron schedule, required for periodic events\",\n }),\n ),\n timezone: Type.Optional(\n Type.String({\n description: \"IANA timezone, required for periodic events\",\n }),\n ),\n filenamePrefix: Type.Optional(\n Type.String({\n description: \"Optional filename prefix for the event file\",\n }),\n ),\n});\n\ninterface EventToolContext {\n platform: string;\n conversationId: string;\n conversationKind: ConversationKind;\n userId: string;\n}\n\ntype EventToolParams = {\n action?: \"create\" | \"list\" | \"read\" | \"update\" | \"delete\";\n filename?: string;\n scope?: \"conversation\" | \"all\";\n label?: string;\n type?: \"immediate\" | \"one-shot\" | \"periodic\";\n text?: string;\n at?: string;\n schedule?: string;\n timezone?: string;\n filenamePrefix?: string;\n};\n\nexport type { EventPayload, EventStore } from \"./types.js\";\nimport type { EventPayload, EventStore } from \"./types.js\";\n\nexport class HostEventStore implements EventStore {\n constructor(private readonly eventsDir: string) {}\n\n static fromWorkspaceDir(workspaceDir: string): HostEventStore {\n return new HostEventStore(join(workspaceDir, \"events\"));\n }\n\n async write(filename: string, payload: EventPayload): Promise<{ path: string; size: number }> {\n return this.writePayload(filename, payload);\n }\n\n async list(): Promise<\n Array<{ filename: string; payload: EventPayload | null; size: number; mtimeMs: number }>\n > {\n await mkdir(this.eventsDir, { recursive: true });\n const entries = await readdir(this.eventsDir, { withFileTypes: true });\n const events = await Promise.all(\n entries\n .filter((entry) => entry.isFile() && entry.name.endsWith(\".json\"))\n .map(async (entry) => {\n try {\n return await this.read(entry.name);\n } catch {\n // Keep unparseable files visible (payload: null) so consumers can\n // surface and delete them; skip files that vanished mid-listing.\n try {\n const fileStat = await stat(join(this.eventsDir, entry.name));\n return {\n filename: entry.name,\n payload: null,\n size: fileStat.size,\n mtimeMs: fileStat.mtimeMs,\n };\n } catch {\n return null;\n }\n }\n }),\n );\n return events\n .filter((event) => event !== null)\n .toSorted((a, b) => a.filename.localeCompare(b.filename));\n }\n\n async read(\n filename: string,\n ): Promise<{ filename: string; payload: EventPayload; size: number; mtimeMs: number }> {\n const safeFilename = validateEventFilename(filename);\n const filePath = join(this.eventsDir, safeFilename);\n const [raw, fileStat] = await Promise.all([readFile(filePath, \"utf-8\"), stat(filePath)]);\n // Validation (shape, per-type fields, channelId alias) is owned by the\n // event-format module; files that fail it surface as payload:null in\n // list() and as errors here.\n const payload = parseEventPayload(raw, safeFilename);\n return {\n filename: safeFilename,\n payload,\n size: fileStat.size,\n mtimeMs: fileStat.mtimeMs,\n };\n }\n\n async update(filename: string, payload: EventPayload): Promise<{ path: string; size: number }> {\n return this.writePayload(filename, payload, true);\n }\n\n async delete(filename: string): Promise<{ deleted: boolean }> {\n const safeFilename = validateEventFilename(filename);\n await rm(join(this.eventsDir, safeFilename), { force: true });\n return { deleted: true };\n }\n\n private async writePayload(\n filename: string,\n payload: EventPayload,\n requireExisting = false,\n ): Promise<{ path: string; size: number }> {\n await mkdir(this.eventsDir, { recursive: true });\n const safeFilename = validateEventFilename(filename);\n const filePath = join(this.eventsDir, safeFilename);\n if (requireExisting) {\n await stat(filePath);\n }\n atomicWritePrivateFile(filePath, JSON.stringify(payload) + \"\\n\");\n const fileStat = await stat(filePath);\n return { path: filePath, size: fileStat.size };\n }\n}\n\nexport function createEventTool(eventStore: EventStore): {\n tool: AgentTool<typeof eventSchema>;\n setEventContext: (context: EventToolContext) => void;\n} {\n let eventContext: EventToolContext | null = null;\n\n const tool: AgentTool<typeof eventSchema> = {\n name: \"event\",\n label: \"event\",\n description:\n \"CRUD tool for scheduled events. Create immediate, one-shot, or periodic events for the current conversation. List defaults to events for the current conversation only; use scope=all only when the user explicitly asks to list all events. Event text must be self-contained because events do not inherit normal conversation history.\",\n parameters: eventSchema,\n execute: async (_toolCallId: string, params: EventToolParams, signal?: AbortSignal) => {\n if (signal?.aborted) {\n throw new Error(\"Operation aborted\");\n }\n\n if (!eventContext) {\n throw new Error(\"Event context not configured\");\n }\n\n const action = params.action ?? \"create\";\n\n if (action === \"list\") {\n const events = await eventStore.list();\n const conversationId = eventContext.conversationId;\n const scopedEvents =\n params.scope === \"all\"\n ? events\n : events.filter((event) => event.payload?.conversationId === conversationId);\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(\n {\n scope: params.scope ?? \"conversation\",\n conversationId: params.scope === \"all\" ? undefined : conversationId,\n events: scopedEvents,\n },\n null,\n 2,\n ),\n },\n ],\n details: undefined,\n };\n }\n\n if (action === \"read\") {\n const filename = requireFilename(params);\n const event = await eventStore.read(filename);\n return {\n content: [{ type: \"text\", text: JSON.stringify(event, null, 2) }],\n details: undefined,\n };\n }\n\n if (action === \"delete\") {\n const filename = requireFilename(params);\n await eventStore.delete(filename);\n return {\n content: [{ type: \"text\", text: `Deleted event ${filename}` }],\n details: undefined,\n };\n }\n\n const payload = buildToolEventPayload(params, eventContext);\n const filename =\n action === \"update\"\n ? requireFilename(params)\n : `${sanitizeFileSegment(params.filenamePrefix || payload.type || \"event\")}-${Date.now()}.json`;\n\n log.logInfo(\n `${action === \"update\" ? \"Updating\" : \"Writing\"} event file via control plane store: ${filename} (type=${payload.type}, platform=${payload.platform}, conversation=${payload.conversationId})`,\n );\n\n try {\n const result =\n action === \"update\"\n ? await eventStore.update(filename, payload)\n : await eventStore.write(filename, payload);\n log.logInfo(\n `${action === \"update\" ? \"Updated\" : \"Wrote\"} event file via control plane store: ${result.path} (${result.size} bytes)`,\n );\n } catch (err) {\n log.logWarning(\n `Failed to ${action === \"update\" ? \"update\" : \"write\"} event file via control plane store: ${filename}`,\n String(err),\n );\n throw err;\n }\n\n return {\n content: [{ type: \"text\", text: formatEventWriteResult(action, filename, payload) }],\n details: undefined,\n };\n },\n };\n\n return {\n tool,\n setEventContext: (context: EventToolContext) => {\n eventContext = context;\n },\n };\n}\n\nfunction buildToolEventPayload(params: EventToolParams, context: EventToolContext): EventPayload {\n if (!params.type) {\n throw new Error(\"`type` is required for create and update actions\");\n }\n if (!params.text) {\n throw new Error(\"`text` is required for create and update actions\");\n }\n\n // Per-type field rules live in the event-format module. No sessionKey or\n // threadTs in the payload: reminders should fire as top-level messages,\n // not buried in old threads.\n const payload = buildEventPayload({\n type: params.type,\n platform: context.platform,\n conversationId: context.conversationId,\n conversationKind: context.conversationKind,\n userId: context.userId,\n text: params.text,\n at: params.at,\n schedule: params.schedule,\n timezone: params.timezone,\n });\n\n // Tool-side write policy, not format knowledge: a reminder in the past\n // would be deleted unfired by the watcher, so reject it here.\n if (payload.type === \"one-shot\" && new Date(payload.at).getTime() <= Date.now()) {\n throw new Error(\n `\\`at\\` must be in the future; got ${payload.at} (now=${new Date().toISOString()}). Check the timezone offset.`,\n );\n }\n\n return payload;\n}\n\nfunction formatEventWriteResult(\n action: \"create\" | \"update\",\n filename: string,\n payload: EventPayload,\n): string {\n const scheduledVerb = action === \"update\" ? \"Updated\" : \"Scheduled\";\n const immediateVerb = action === \"update\" ? \"Updated\" : \"Queued\";\n const target = payload.platform\n ? `${payload.platform}/${payload.conversationId}`\n : payload.conversationId;\n switch (payload.type) {\n case \"periodic\":\n return `${scheduledVerb} periodic event ${filename} for ${target} (${payload.schedule} ${payload.timezone})`;\n case \"one-shot\":\n return `${scheduledVerb} one-shot event ${filename} for ${target} at ${payload.at}`;\n case \"immediate\":\n return `${immediateVerb} immediate event ${filename} for ${target}`;\n }\n}\n\nfunction requireFilename(params: EventToolParams): string {\n if (!params.filename) {\n throw new Error(\"`filename` is required for read, update, and delete actions\");\n }\n return validateEventFilename(params.filename);\n}\n\nfunction validateEventFilename(filename: string): string {\n const trimmed = filename.trim();\n if (\n !trimmed ||\n trimmed !== basename(trimmed) ||\n trimmed.includes(\"..\") ||\n !trimmed.endsWith(\".json\")\n ) {\n throw new Error(\"Invalid event filename\");\n }\n return trimmed;\n}\n\nfunction sanitizeFileSegment(value: string): string {\n const sanitized = value\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n return sanitized || \"event\";\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
|
+
declare const schema: import("@sinclair/typebox").TObject<{
|
|
4
|
+
prompt: import("@sinclair/typebox").TString;
|
|
5
|
+
size: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
|
+
quality: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function createGenerateImageTool(options: {
|
|
9
|
+
model: Model<Api>;
|
|
10
|
+
getApiKey: () => Promise<string | undefined>;
|
|
11
|
+
workspaceDir: string;
|
|
12
|
+
}): {
|
|
13
|
+
tool: AgentTool<typeof schema>;
|
|
14
|
+
setUploadFunction: (fn: (filePath: string, title?: string) => Promise<void>) => void;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=generate-image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-image.d.ts","sourceRoot":"","sources":["../../src/tools/generate-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAMxD,QAAA,MAAM,MAAM;;;;EAMV,CAAC;AAOH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG;IACF,IAAI,EAAE,SAAS,CAAC,OAAO,MAAM,CAAC,CAAC;IAC/B,iBAAiB,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;CACtF,CA2DA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { writeFile } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { randomUUID } from "crypto";
|
|
5
|
+
const schema = Type.Object({
|
|
6
|
+
prompt: Type.String({ description: "Description of the image to generate" }),
|
|
7
|
+
size: Type.Optional(Type.String({ description: "Requested image size, for example 1024x1024" })),
|
|
8
|
+
quality: Type.Optional(Type.String({ description: "Requested image quality, for example low, medium, or high" })),
|
|
9
|
+
});
|
|
10
|
+
export function createGenerateImageTool(options) {
|
|
11
|
+
let uploadFn = null;
|
|
12
|
+
return {
|
|
13
|
+
tool: {
|
|
14
|
+
name: "generate_image",
|
|
15
|
+
label: "generate image",
|
|
16
|
+
description: "Generate an image with the configured model provider and attach it to the response.",
|
|
17
|
+
parameters: schema,
|
|
18
|
+
execute: async (_toolCallId, params, signal) => {
|
|
19
|
+
if (!uploadFn)
|
|
20
|
+
throw new Error("Upload function not configured");
|
|
21
|
+
if (!options.model.baseUrl)
|
|
22
|
+
throw new Error("Image generation requires a configured model baseUrl");
|
|
23
|
+
const apiKey = await options.getApiKey();
|
|
24
|
+
if (!apiKey)
|
|
25
|
+
throw new Error(`No API key configured for ${options.model.provider}`);
|
|
26
|
+
const response = await fetch(`${options.model.baseUrl.replace(/\/$/, "")}/images/generations`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
signal,
|
|
29
|
+
headers: {
|
|
30
|
+
...options.model.headers,
|
|
31
|
+
Authorization: `Bearer ${apiKey}`,
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
model: options.model.id,
|
|
36
|
+
prompt: params.prompt,
|
|
37
|
+
...(params.size ? { size: params.size } : {}),
|
|
38
|
+
...(params.quality ? { quality: params.quality } : {}),
|
|
39
|
+
response_format: "b64_json",
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
const body = (await response.json());
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(body.error?.message ?? `Image generation failed with HTTP ${response.status}`);
|
|
45
|
+
}
|
|
46
|
+
const encoded = body.data?.[0]?.b64_json;
|
|
47
|
+
if (!encoded)
|
|
48
|
+
throw new Error("Image generation response contained no image");
|
|
49
|
+
const fileName = `generated-${randomUUID()}.png`;
|
|
50
|
+
await writeFile(join(options.workspaceDir, fileName), Buffer.from(encoded, "base64"));
|
|
51
|
+
await uploadFn(fileName, fileName);
|
|
52
|
+
return {
|
|
53
|
+
content: [{ type: "text", text: `Generated and attached image: ${fileName}` }],
|
|
54
|
+
details: { fileName },
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
setUploadFunction: (fn) => {
|
|
59
|
+
uploadFn = fn;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=generate-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-image.js","sourceRoot":"","sources":["../../src/tools/generate-image.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAA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CAAC,CAAC;gBACtF,MAAM,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAEnC,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,iCAAiC,QAAQ,EAAE,EAAE,CAAC;oBACvF,OAAO,EAAE,EAAE,QAAQ,EAAE;iBACtB,CAAC;YACJ,CAAC;SACF;QACD,iBAAiB,EAAE,CAAC,EAAE,EAAE,EAAE;YACxB,QAAQ,GAAG,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { Type } from \"@sinclair/typebox\";\nimport { writeFile } from \"fs/promises\";\nimport { join } from \"path\";\nimport { randomUUID } from \"crypto\";\n\nconst schema = Type.Object({\n prompt: Type.String({ description: \"Description of the image to generate\" }),\n size: Type.Optional(Type.String({ description: \"Requested image size, for example 1024x1024\" })),\n quality: Type.Optional(\n Type.String({ description: \"Requested image quality, for example low, medium, or high\" }),\n ),\n});\n\ninterface ImageResponse {\n data?: Array<{ b64_json?: string }>;\n error?: { message?: string };\n}\n\nexport function createGenerateImageTool(options: {\n model: Model<Api>;\n getApiKey: () => Promise<string | undefined>;\n workspaceDir: string;\n}): {\n tool: AgentTool<typeof schema>;\n setUploadFunction: (fn: (filePath: string, title?: string) => Promise<void>) => void;\n} {\n let uploadFn: ((filePath: string, title?: string) => Promise<void>) | null = null;\n\n return {\n tool: {\n name: \"generate_image\",\n label: \"generate image\",\n description:\n \"Generate an image with the configured model provider and attach it to the response.\",\n parameters: schema,\n execute: async (_toolCallId, params, signal) => {\n if (!uploadFn) throw new Error(\"Upload function not configured\");\n if (!options.model.baseUrl)\n throw new Error(\"Image generation requires a configured model baseUrl\");\n const apiKey = await options.getApiKey();\n if (!apiKey) throw new Error(`No API key configured for ${options.model.provider}`);\n\n const response = await fetch(\n `${options.model.baseUrl.replace(/\\/$/, \"\")}/images/generations`,\n {\n method: \"POST\",\n signal,\n headers: {\n ...options.model.headers,\n Authorization: `Bearer ${apiKey}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n model: options.model.id,\n prompt: params.prompt,\n ...(params.size ? { size: params.size } : {}),\n ...(params.quality ? { quality: params.quality } : {}),\n response_format: \"b64_json\",\n }),\n },\n );\n const body = (await response.json()) as ImageResponse;\n if (!response.ok) {\n throw new Error(\n body.error?.message ?? `Image generation failed with HTTP ${response.status}`,\n );\n }\n const encoded = body.data?.[0]?.b64_json;\n if (!encoded) throw new Error(\"Image generation response contained no image\");\n\n const fileName = `generated-${randomUUID()}.png`;\n await writeFile(join(options.workspaceDir, fileName), Buffer.from(encoded, \"base64\"));\n await uploadFn(fileName, fileName);\n\n return {\n content: [{ type: \"text\" as const, text: `Generated and attached image: ${fileName}` }],\n details: { fileName },\n };\n },\n },\n setUploadFunction: (fn) => {\n uploadFn = fn;\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { Static, TSchema } from "@sinclair/typebox";
|
|
3
|
+
/**
|
|
4
|
+
* A host-backed tool whose implementation is injected per run: a pack's
|
|
5
|
+
* bindRun binds the function for the current conversation (or null to
|
|
6
|
+
* disable the tool). Owns the choreography every such tool used to repeat
|
|
7
|
+
* by hand — the holder + setter pair, the disabled-tool error, and the
|
|
8
|
+
* abort guard — so a tool module only states its schema and its run body.
|
|
9
|
+
*/
|
|
10
|
+
export declare function defineHostFnTool<TFn, TParams extends TSchema>(definition: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
parameters: TParams;
|
|
14
|
+
/** Error thrown when the tool executes with no bound implementation. */
|
|
15
|
+
unavailable: string;
|
|
16
|
+
run: (fn: TFn, args: Static<TParams>, signal?: AbortSignal) => ReturnType<AgentTool<TParams>["execute"]>;
|
|
17
|
+
}): {
|
|
18
|
+
tool: AgentTool<TParams>;
|
|
19
|
+
setFn: (fn: TFn | null) => void;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=host-fn-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-fn-tool.d.ts","sourceRoot":"","sources":["../../src/tools/host-fn-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,SAAS,OAAO,EAAE,UAAU,EAAE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,CACH,EAAE,EAAE,GAAG,EACP,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,EACrB,MAAM,CAAC,EAAE,WAAW,KACjB,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;CAChD,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAAC,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,GAAG,IAAI,KAAK,IAAI,CAAA;CAAE,CAyBhE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host-backed tool whose implementation is injected per run: a pack's
|
|
3
|
+
* bindRun binds the function for the current conversation (or null to
|
|
4
|
+
* disable the tool). Owns the choreography every such tool used to repeat
|
|
5
|
+
* by hand — the holder + setter pair, the disabled-tool error, and the
|
|
6
|
+
* abort guard — so a tool module only states its schema and its run body.
|
|
7
|
+
*/
|
|
8
|
+
export function defineHostFnTool(definition) {
|
|
9
|
+
let bound = null;
|
|
10
|
+
const tool = {
|
|
11
|
+
name: definition.name,
|
|
12
|
+
label: definition.name,
|
|
13
|
+
description: definition.description,
|
|
14
|
+
parameters: definition.parameters,
|
|
15
|
+
execute: async (_toolCallId, args, signal) => {
|
|
16
|
+
if (!bound) {
|
|
17
|
+
throw new Error(definition.unavailable);
|
|
18
|
+
}
|
|
19
|
+
if (signal?.aborted) {
|
|
20
|
+
throw new Error("Operation aborted");
|
|
21
|
+
}
|
|
22
|
+
return definition.run(bound, args, signal);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
tool,
|
|
27
|
+
setFn: (fn) => {
|
|
28
|
+
bound = fn;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=host-fn-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-fn-tool.js","sourceRoot":"","sources":["../../src/tools/host-fn-tool.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAA+B,UAW9D;IACC,IAAI,KAAK,GAAe,IAAI,CAAC;IAE7B,MAAM,IAAI,GAAuB;QAC/B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,IAAI;QACtB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YAC1C,CAAC;YACD,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YACvC,CAAC;YACD,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,IAAuB,EAAE,MAAM,CAAC,CAAC;QAChE,CAAC;KACF,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE;YACZ,KAAK,GAAG,EAAE,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { Static, TSchema } from \"@sinclair/typebox\";\n\n/**\n * A host-backed tool whose implementation is injected per run: a pack's\n * bindRun binds the function for the current conversation (or null to\n * disable the tool). Owns the choreography every such tool used to repeat\n * by hand — the holder + setter pair, the disabled-tool error, and the\n * abort guard — so a tool module only states its schema and its run body.\n */\nexport function defineHostFnTool<TFn, TParams extends TSchema>(definition: {\n name: string;\n description: string;\n parameters: TParams;\n /** Error thrown when the tool executes with no bound implementation. */\n unavailable: string;\n run: (\n fn: TFn,\n args: Static<TParams>,\n signal?: AbortSignal,\n ) => ReturnType<AgentTool<TParams>[\"execute\"]>;\n}): { tool: AgentTool<TParams>; setFn: (fn: TFn | null) => void } {\n let bound: TFn | null = null;\n\n const tool: AgentTool<TParams> = {\n name: definition.name,\n label: definition.name,\n description: definition.description,\n parameters: definition.parameters,\n execute: async (_toolCallId, args, signal) => {\n if (!bound) {\n throw new Error(definition.unavailable);\n }\n if (signal?.aborted) {\n throw new Error(\"Operation aborted\");\n }\n return definition.run(bound, args as Static<TParams>, signal);\n },\n };\n\n return {\n tool,\n setFn: (fn) => {\n bound = fn;\n },\n };\n}\n"]}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
3
|
import type { TSchema } from "@sinclair/typebox";
|
|
3
4
|
import type { ConversationKind } from "../adapter.js";
|
|
4
|
-
import type { DockerContainerManager } from "../provisioner.js";
|
|
5
5
|
import type { Executor, SandboxConfig } from "../sandbox/index.js";
|
|
6
|
+
import type { SandboxResourceController } from "../types.js";
|
|
7
|
+
import type { PlatformToolPackFactory } from "./types.js";
|
|
8
|
+
export { createSubagentTool } from "./subagent.js";
|
|
9
|
+
export { DEFAULT_GLOBAL_SUBAGENT_SLOTS, SubagentSlotPool } from "./subagent-slots.js";
|
|
6
10
|
export declare function createMikanTools(executor: Executor, workspaceDir: string, sandboxController?: {
|
|
7
11
|
sandbox: SandboxConfig;
|
|
8
|
-
|
|
12
|
+
resourceController?: Pick<SandboxResourceController, "getLimitStatus" | "setLimits">;
|
|
13
|
+
},
|
|
14
|
+
/** Platform capability pack factories (e.g. GitHub PR/CI); instantiated
|
|
15
|
+
* here so each runner owns its packs' bind state. Not core tools. */
|
|
16
|
+
platformToolPackFactories?: readonly PlatformToolPackFactory[], imageGeneration?: {
|
|
17
|
+
model: Model<Api>;
|
|
18
|
+
getApiKey: () => Promise<string | undefined>;
|
|
9
19
|
}): {
|
|
10
20
|
tools: AgentTool<TSchema>[];
|
|
11
21
|
setUploadFunction: (fn: (filePath: string, title?: string) => Promise<void>) => void;
|
|
22
|
+
setReactFunction: (fn: ((emoji: string) => Promise<void>) | null) => void;
|
|
23
|
+
bindPlatformToolPacks: (ctx: {
|
|
24
|
+
conversationId: string;
|
|
25
|
+
platformName: string;
|
|
26
|
+
}) => void;
|
|
12
27
|
setEventContext: (context: {
|
|
13
28
|
platform: string;
|
|
14
29
|
conversationId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mapp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E,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1E,qBAAqB,EAAE,CAAC,GAAG,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACvF,eAAe,EAAE,CAAC,OAAO,EAAE;QACzB,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,EAAE,MAAM,CAAC;QACvB,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,MAAM,EAAE,MAAM,CAAC;KAChB,KAAK,IAAI,CAAC;IACX,iBAAiB,EAAE,CAAC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAClF,CAwCA"}
|
package/dist/tools/index.js
CHANGED
|
@@ -2,24 +2,49 @@ import { createAttachTool } from "../adapters/slack/tools/attach.js";
|
|
|
2
2
|
import { createBashTool } from "./bash.js";
|
|
3
3
|
import { createEditTool } from "./edit.js";
|
|
4
4
|
import { createEventTool, HostEventStore } from "./event.js";
|
|
5
|
+
import { createGenerateImageTool } from "./generate-image.js";
|
|
6
|
+
import { createReactTool } from "./react.js";
|
|
5
7
|
import { createReadTool } from "./read.js";
|
|
6
8
|
import { createSandboxTool } from "./sandbox.js";
|
|
7
9
|
import { createWriteTool } from "./write.js";
|
|
8
|
-
export
|
|
10
|
+
export { createSubagentTool } from "./subagent.js";
|
|
11
|
+
export { DEFAULT_GLOBAL_SUBAGENT_SLOTS, SubagentSlotPool } from "./subagent-slots.js";
|
|
12
|
+
export function createMikanTools(executor, workspaceDir, sandboxController,
|
|
13
|
+
/** Platform capability pack factories (e.g. GitHub PR/CI); instantiated
|
|
14
|
+
* here so each runner owns its packs' bind state. Not core tools. */
|
|
15
|
+
platformToolPackFactories = [], imageGeneration) {
|
|
9
16
|
const { tool: attachTool, setUploadFunction } = createAttachTool();
|
|
17
|
+
const imageTool = imageGeneration
|
|
18
|
+
? createGenerateImageTool({ ...imageGeneration, workspaceDir })
|
|
19
|
+
: undefined;
|
|
20
|
+
const { tool: reactTool, setReactFunction } = createReactTool();
|
|
10
21
|
const { tool: eventTool, setEventContext } = createEventTool(HostEventStore.fromWorkspaceDir(workspaceDir));
|
|
11
22
|
const { tool: sandboxTool, setSandboxContext } = createSandboxTool(sandboxController ?? { sandbox: executor.getSandboxConfig() });
|
|
23
|
+
const platformToolPacks = platformToolPackFactories.map((createPack) => createPack());
|
|
24
|
+
const packTools = platformToolPacks.flatMap((pack) => pack.tools);
|
|
12
25
|
return {
|
|
13
26
|
tools: [
|
|
14
27
|
createReadTool(executor),
|
|
15
|
-
createBashTool(executor),
|
|
28
|
+
createBashTool(executor, { hostWorkspaceRoot: workspaceDir }),
|
|
16
29
|
createEditTool(executor),
|
|
17
30
|
createWriteTool(executor),
|
|
18
31
|
eventTool,
|
|
19
32
|
sandboxTool,
|
|
20
33
|
attachTool,
|
|
34
|
+
...(imageTool ? [imageTool.tool] : []),
|
|
35
|
+
reactTool,
|
|
36
|
+
...packTools,
|
|
21
37
|
],
|
|
22
|
-
setUploadFunction
|
|
38
|
+
setUploadFunction: (fn) => {
|
|
39
|
+
setUploadFunction(fn);
|
|
40
|
+
imageTool?.setUploadFunction(fn);
|
|
41
|
+
},
|
|
42
|
+
setReactFunction,
|
|
43
|
+
bindPlatformToolPacks: (ctx) => {
|
|
44
|
+
for (const pack of platformToolPacks) {
|
|
45
|
+
pack.bindRun(ctx);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
23
48
|
setEventContext,
|
|
24
49
|
setSandboxContext,
|
|
25
50
|
};
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAI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AE,QAAQ,CAAC,gBAAgB,EAAE,EAAE,CAC9D,CAAC;IACF,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC;IACtF,MAAM,SAAS,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClE,OAAO;QACL,KAAK,EAAE;YACL,cAAc,CAAC,QAAQ,CAAC;YACxB,cAAc,CAAC,QAAQ,EAAE,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;YAC7D,cAAc,CAAC,QAAQ,CAAC;YACxB,eAAe,CAAC,QAAQ,CAAC;YACzB,SAAS;YACT,WAAW;YACX,UAAU;YACV,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACtC,SAAS;YACT,GAAG,SAAS;SACb;QACD,iBAAiB,EAAE,CAAC,EAAE,EAAE,EAAE;YACxB,iBAAiB,CAAC,EAAE,CAAC,CAAC;YACtB,SAAS,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC;QACnC,CAAC;QACD,gBAAgB;QAChB,qBAAqB,EAAE,CAAC,GAAG,EAAE,EAAE;YAC7B,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;gBACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QACD,eAAe;QACf,iBAAiB;KAClB,CAAC;AACJ,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport type { ConversationKind } from \"../adapter.js\";\nimport { createAttachTool } from \"../adapters/slack/tools/attach.js\";\nimport type { Executor, SandboxConfig } from \"../sandbox/index.js\";\nimport type { SandboxResourceController } from \"../types.js\";\nimport { createBashTool } from \"./bash.js\";\nimport { createEditTool } from \"./edit.js\";\nimport { createEventTool, HostEventStore } from \"./event.js\";\nimport { createGenerateImageTool } from \"./generate-image.js\";\nimport { createReactTool } from \"./react.js\";\nimport { createReadTool } from \"./read.js\";\nimport { createSandboxTool } from \"./sandbox.js\";\nimport type { PlatformToolPackFactory } from \"./types.js\";\nimport { createWriteTool } from \"./write.js\";\n\nexport { createSubagentTool } from \"./subagent.js\";\nexport { DEFAULT_GLOBAL_SUBAGENT_SLOTS, SubagentSlotPool } from \"./subagent-slots.js\";\n\nexport function createMikanTools(\n executor: Executor,\n workspaceDir: string,\n sandboxController?: {\n sandbox: SandboxConfig;\n resourceController?: Pick<SandboxResourceController, \"getLimitStatus\" | \"setLimits\">;\n },\n /** Platform capability pack factories (e.g. GitHub PR/CI); instantiated\n * here so each runner owns its packs' bind state. Not core tools. */\n platformToolPackFactories: readonly PlatformToolPackFactory[] = [],\n imageGeneration?: {\n model: Model<Api>;\n getApiKey: () => Promise<string | undefined>;\n },\n): {\n tools: AgentTool<TSchema>[];\n setUploadFunction: (fn: (filePath: string, title?: string) => Promise<void>) => void;\n setReactFunction: (fn: ((emoji: string) => Promise<void>) | null) => void;\n bindPlatformToolPacks: (ctx: { conversationId: string; platformName: string }) => void;\n setEventContext: (context: {\n platform: string;\n conversationId: string;\n conversationKind: ConversationKind;\n userId: string;\n }) => void;\n setSandboxContext: (context: { conversationId: string; userId: string }) => void;\n} {\n const { tool: attachTool, setUploadFunction } = createAttachTool();\n const imageTool = imageGeneration\n ? createGenerateImageTool({ ...imageGeneration, workspaceDir })\n : undefined;\n const { tool: reactTool, setReactFunction } = createReactTool();\n const { tool: eventTool, setEventContext } = createEventTool(\n HostEventStore.fromWorkspaceDir(workspaceDir),\n );\n const { tool: sandboxTool, setSandboxContext } = createSandboxTool(\n sandboxController ?? { sandbox: executor.getSandboxConfig() },\n );\n const platformToolPacks = platformToolPackFactories.map((createPack) => createPack());\n const packTools = platformToolPacks.flatMap((pack) => pack.tools);\n return {\n tools: [\n createReadTool(executor),\n createBashTool(executor, { hostWorkspaceRoot: workspaceDir }),\n createEditTool(executor),\n createWriteTool(executor),\n eventTool,\n sandboxTool,\n attachTool,\n ...(imageTool ? [imageTool.tool] : []),\n reactTool,\n ...packTools,\n ],\n setUploadFunction: (fn) => {\n setUploadFunction(fn);\n imageTool?.setUploadFunction(fn);\n },\n setReactFunction,\n bindPlatformToolPacks: (ctx) => {\n for (const pack of platformToolPacks) {\n pack.bindRun(ctx);\n }\n },\n setEventContext,\n setSandboxContext,\n };\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
declare const reactSchema: import("@sinclair/typebox").TObject<{
|
|
3
|
+
emoji: import("@sinclair/typebox").TString;
|
|
4
|
+
}>;
|
|
5
|
+
/**
|
|
6
|
+
* The `react` tool adds an emoji reaction to the message that triggered the
|
|
7
|
+
* current run. The channel and message timestamp are captured per run via
|
|
8
|
+
* {@link createReactTool}'s setter; the model only supplies the emoji.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createReactTool(): {
|
|
11
|
+
tool: AgentTool<typeof reactSchema>;
|
|
12
|
+
setReactFunction: (fn: ((emoji: string) => Promise<void>) | null) => void;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/tools/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAI/D,QAAA,MAAM,WAAW;;EAKf,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,eAAe,IAAI;IACjC,IAAI,EAAE,SAAS,CAAC,OAAO,WAAW,CAAC,CAAC;IACpC,gBAAgB,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3E,CAiBA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { defineHostFnTool } from "./host-fn-tool.js";
|
|
3
|
+
const reactSchema = Type.Object({
|
|
4
|
+
emoji: Type.String({
|
|
5
|
+
description: "Emoji to react with. Use a short name without colons (e.g. eyes, white_check_mark, +1) on Slack, or a Unicode emoji on Discord/Telegram.",
|
|
6
|
+
}),
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* The `react` tool adds an emoji reaction to the message that triggered the
|
|
10
|
+
* current run. The channel and message timestamp are captured per run via
|
|
11
|
+
* {@link createReactTool}'s setter; the model only supplies the emoji.
|
|
12
|
+
*/
|
|
13
|
+
export function createReactTool() {
|
|
14
|
+
const { tool, setFn } = defineHostFnTool({
|
|
15
|
+
name: "react",
|
|
16
|
+
description: "Add an emoji reaction to the message you are responding to. Useful for a lightweight acknowledgement (e.g. eyes to show you saw a request, white_check_mark when done) instead of a full reply.",
|
|
17
|
+
parameters: reactSchema,
|
|
18
|
+
unavailable: "Reactions are not supported in this conversation.",
|
|
19
|
+
run: async (reactFn, { emoji }) => {
|
|
20
|
+
await reactFn(emoji);
|
|
21
|
+
return {
|
|
22
|
+
content: [{ type: "text", text: `Reacted with :${emoji.replace(/^:|:$/g, "")}:` }],
|
|
23
|
+
details: undefined,
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return { tool, setReactFunction: setFn };
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/tools/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9B,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EACT,0IAA0I;KAC7I,CAAC;CACH,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAI7B,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,gBAAgB,CAAuD;QAC7F,IAAI,EAAE,OAAO;QACb,WAAW,EACT,iMAAiM;QACnM,UAAU,EAAE,WAAW;QACvB,WAAW,EAAE,mDAAmD;QAChE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;YAChC,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,iBAAiB,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;gBAC3F,OAAO,EAAE,SAAS;aACnB,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Type } from \"@sinclair/typebox\";\nimport { defineHostFnTool } from \"./host-fn-tool.js\";\n\nconst reactSchema = Type.Object({\n emoji: Type.String({\n description:\n \"Emoji to react with. Use a short name without colons (e.g. eyes, white_check_mark, +1) on Slack, or a Unicode emoji on Discord/Telegram.\",\n }),\n});\n\n/**\n * The `react` tool adds an emoji reaction to the message that triggered the\n * current run. The channel and message timestamp are captured per run via\n * {@link createReactTool}'s setter; the model only supplies the emoji.\n */\nexport function createReactTool(): {\n tool: AgentTool<typeof reactSchema>;\n setReactFunction: (fn: ((emoji: string) => Promise<void>) | null) => void;\n} {\n const { tool, setFn } = defineHostFnTool<(emoji: string) => Promise<void>, typeof reactSchema>({\n name: \"react\",\n description:\n \"Add an emoji reaction to the message you are responding to. Useful for a lightweight acknowledgement (e.g. eyes to show you saw a request, white_check_mark when done) instead of a full reply.\",\n parameters: reactSchema,\n unavailable: \"Reactions are not supported in this conversation.\",\n run: async (reactFn, { emoji }) => {\n await reactFn(emoji);\n return {\n content: [{ type: \"text\" as const, text: `Reacted with :${emoji.replace(/^:|:$/g, \"\")}:` }],\n details: undefined,\n };\n },\n });\n\n return { tool, setReactFunction: setFn };\n}\n"]}
|