@desplega.ai/agent-swarm 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-adapter-g909b5hw.js +16 -0
- package/dist/{acp-targets-swxq55dr.js → acp-targets-ny75x1qy.js} +7 -7
- package/dist/{actions-pb678g3e.js → actions-b9qgrmeq.js} +81 -21
- package/dist/{agent-fs-provision-dmhnc38q.js → agent-fs-provision-b5dhdsbd.js} +4 -4
- package/dist/{amp-adapter-3pa66q27.js → amp-adapter-vtax2c9s.js} +2 -2
- package/dist/{anthropic-messages-x2cp5fvf.js → anthropic-messages-r5xf5hqw.js} +10 -10
- package/dist/{app-17d12ev4.js → app-g2z15hax.js} +6 -3
- package/dist/{approval-notifications-h7vd9pmg.js → approval-notifications-yt13wp8r.js} +8 -5
- package/dist/{assistant-t7k39ree.js → assistant-2cgfxsgk.js} +23 -21
- package/dist/{boot-args-schema-0gqmkfbe.js → boot-args-schema-3gwy0f60.js} +1 -1
- package/dist/{boot-reembed-n6anc01d.js → boot-reembed-92g7s5zp.js} +1 -1
- package/dist/{boot-reembed-f064w382.js → boot-reembed-mywmyp4s.js} +1 -1
- package/dist/{boot-scrub-sweep-ejd5dnrz.js → boot-scrub-sweep-7dkdzqxx.js} +3 -3
- package/dist/{boot-seeds-f99fjs5q.js → boot-seeds-ce7rvgq1.js} +4 -4
- package/dist/{claude-adapter-gvznwxgc.js → claude-adapter-3m4q7735.js} +7 -7
- package/dist/{claude-managed-adapter-pbrbvc64.js → claude-managed-adapter-t8nfgcgz.js} +2 -2
- package/dist/{claude-managed-setup-kdxttvc3.js → claude-managed-setup-c217draw.js} +3 -3
- package/dist/{claude-sdk-session-0t2teq6n.js → claude-sdk-session-7fbqm51z.js} +7 -7
- package/dist/{cli-9a2rtd77.js → cli-1jykg0py.js} +6 -4
- package/dist/{cli-5ntc4we6.js → cli-2czxfnvj.js} +235 -2003
- package/dist/{cli-dd37e0cm.js → cli-2dq9yv8p.js} +1 -1
- package/dist/{cli-c07v0qfa.js → cli-2xs8tsf7.js} +69 -66
- package/dist/{cli-7fx9jyfs.js → cli-2yjj3e31.js} +64 -10
- package/dist/{cli-4ghh072d.js → cli-32djehja.js} +36 -36
- package/dist/{cli-cw7mc1je.js → cli-3j873zxq.js} +3 -3
- package/dist/cli-43ms35q9.js +270 -0
- package/dist/cli-47hz21se.js +25584 -0
- package/dist/{cli-n515ex5z.js → cli-4ymxrwg5.js} +16 -16
- package/dist/{cli-5gygrr67.js → cli-67mwzr35.js} +1 -1
- package/dist/{cli-5kcmxwxv.js → cli-6945ywhr.js} +1 -1
- package/dist/{cli-812paz57.js → cli-6ehs4mta.js} +18 -2
- package/dist/{cli-95930z69.js → cli-6ym4jhzp.js} +2 -2
- package/dist/{cli-zg3z63x3.js → cli-7mv4h3sn.js} +1 -1
- package/dist/{cli-eg437b5p.js → cli-7sf9sb0w.js} +2 -1
- package/dist/{cli-nr46j5pw.js → cli-8zh9nrew.js} +1 -1
- package/dist/{cli-wr1h0k28.js → cli-9w8712tq.js} +617 -278
- package/dist/{cli-ssvdrk4y.js → cli-b6px1k1q.js} +1 -1
- package/dist/{cli-7831nhaw.js → cli-b91nz213.js} +3 -3
- package/dist/{cli-7cgf614g.js → cli-bg63qmsx.js} +2 -2
- package/dist/{cli-me4maa4j.js → cli-bkjdknnp.js} +9 -5
- package/dist/{cli-rts1qvb4.js → cli-bnqncekd.js} +2 -2
- package/dist/{cli-25nstr34.js → cli-br0924pw.js} +1 -1
- package/dist/{cli-ymct0ycy.js → cli-ctx0b85j.js} +5222 -4978
- package/dist/{cli-kqh27v2y.js → cli-dgs10ttj.js} +1 -1
- package/dist/{cli-kmvcm34h.js → cli-f3jyzq4g.js} +2 -2
- package/dist/cli-f8x9drqr.js +84 -0
- package/dist/{cli-8axx8vnw.js → cli-f9gz2vyj.js} +5 -5
- package/dist/{cli-vvgaz8t6.js → cli-fh97xn30.js} +2 -2
- package/dist/{cli-8x8y70av.js → cli-fkef327x.js} +2 -2
- package/dist/{cli-js8zrfyg.js → cli-gfy38pvt.js} +2 -2
- package/dist/{cli-kaa4bd7x.js → cli-h9yqfzx9.js} +7 -6
- package/dist/{cli-svc803vq.js → cli-j7svy295.js} +11 -11
- package/dist/{cli-nhq5js1b.js → cli-jaw5v1sy.js} +3 -3
- package/dist/{cli-w7dxb2fj.js → cli-jkw6ptfw.js} +6 -6
- package/dist/{cli-1tvdx9t5.js → cli-jm0hvmz2.js} +1 -1
- package/dist/{cli-e9973bf0.js → cli-jwampxxq.js} +2 -2
- package/dist/{cli-dx439zpg.js → cli-kpgcm7xy.js} +13 -1
- package/dist/{cli-pz1c00aa.js → cli-kxx4k2jw.js} +2 -2
- package/dist/{cli-aa8s22gn.js → cli-m7c2380k.js} +191 -182
- package/dist/{cli-2kg31ted.js → cli-m7zvgt57.js} +11 -11
- package/dist/{cli-57pvhnyt.js → cli-mhapr559.js} +1 -1
- package/dist/{cli-gddgcnav.js → cli-mjw0yf82.js} +1 -1
- package/dist/{cli-h474mvp5.js → cli-mkwkwq81.js} +7 -4
- package/dist/{cli-jd3kxppb.js → cli-mw620q3n.js} +1 -1
- package/dist/{cli-spzkdgtg.js → cli-n3qe7tyr.js} +172 -168
- package/dist/{cli-3zxdz9r7.js → cli-nafvvsp8.js} +3 -3
- package/dist/{cli-fnh4b12r.js → cli-nbt14he0.js} +6 -6
- package/dist/{cli-7akn6ze9.js → cli-nh7x3133.js} +7 -28
- package/dist/{cli-faf46gdq.js → cli-p4kckx1z.js} +10 -10
- package/dist/{cli-k7pt28ad.js → cli-pb2ay3sh.js} +2 -2
- package/dist/{cli-pn1v1pb0.js → cli-psffsanb.js} +3 -2
- package/dist/{cli-2tnbc3gw.js → cli-pyjn0qhk.js} +2257 -61
- package/dist/{cli-fgphc007.js → cli-rq5rpv6k.js} +1 -1
- package/dist/{cli-vw5x18yj.js → cli-sn650d7x.js} +9 -9
- package/dist/{cli-mc1fx4xd.js → cli-td9tb872.js} +10 -10
- package/dist/{cli-6dp0jkfj.js → cli-tvc4jag9.js} +3 -3
- package/dist/{cli-a9hfzg2r.js → cli-ty3gha1p.js} +6 -6
- package/dist/{cli-pwsax0vp.js → cli-v57d7fmm.js} +1 -1
- package/dist/{cli-nmcpzbty.js → cli-vt89089n.js} +4 -4
- package/dist/{cli-sn4pc4qx.js → cli-vyff45ve.js} +2 -2
- package/dist/{cli-m1fbz2wj.js → cli-w4n323t3.js} +175 -16
- package/dist/{cli-g3zzby8t.js → cli-wn13hhdt.js} +5 -5
- package/dist/{cli-q8cfh1t9.js → cli-xag7btpe.js} +1 -1
- package/dist/{cli-c5cspahx.js → cli-y2ewxhth.js} +38 -13
- package/dist/{cli-k09cxm6m.js → cli-ysvspf5e.js} +2 -2
- package/dist/{cli-eepnpee7.js → cli-zh0e5x7p.js} +4 -4
- package/dist/{cli-bk9v1xrv.js → cli-zr6qy15y.js} +11 -11
- package/dist/cli.js +21 -20
- package/dist/{codex-adapter-44yq2fkn.js → codex-adapter-n656pvb8.js} +6 -6
- package/dist/{codex-hook-h1zb7cfk.js → codex-hook-59atdwd8.js} +1 -1
- package/dist/{codex-login-cdyrr5y1.js → codex-login-a239g1ah.js} +1 -1
- package/dist/{codex-session-runner-zbh26gbw.js → codex-session-runner-p0fbv5y9.js} +6 -6
- package/dist/{commands-54f02v5b.js → commands-gwea8z5p.js} +3 -3
- package/dist/{controller-9gpwcdek.js → controller-t67c3grh.js} +6 -3
- package/dist/{controllers-connect-61re6k1n.js → controllers-connect-ks155r0h.js} +22 -20
- package/dist/{cursor-adapter-7e4g81vd.js → cursor-adapter-ygwrtmkv.js} +1 -1
- package/dist/{db-dg2gc7fd.js → db-kpmx06s9.js} +8 -2
- package/dist/{db-wnh0qjy1.js → db-rb2xqdb1.js} +3 -3
- package/dist/{dispatcher-jrm24r43.js → dispatcher-31sm0ej2.js} +20 -18
- package/dist/{docker-9aq30pp2.js → docker-09tkkg0n.js} +42 -3
- package/dist/{dsh-adapter-1yqk267c.js → dsh-adapter-qyxh0w31.js} +1 -1
- package/dist/{easter-egg-3d-r4h9cs9m.js → easter-egg-3d-00wjscn6.js} +1 -1
- package/dist/{embedding-space-bafjr5f7.js → embedding-space-qhw4g68n.js} +6 -6
- package/dist/{embeddings-7xmgqe0e.js → embeddings-zdv9ke6x.js} +1 -1
- package/dist/{execute-d6jg5ns0.js → execute-zna8wwr7.js} +1 -1
- package/dist/{external-channel-frq1xvq2.js → external-channel-1ac6t56s.js} +2 -2
- package/dist/fx-adapter-sk7n0fzc.js +19 -0
- package/dist/{google-generative-ai-hh7strj3.js → google-generative-ai-maq6c9bf.js} +1 -1
- package/dist/{google-vertex-fy5bw2pm.js → google-vertex-2jgsw2nb.js} +1 -1
- package/dist/grok-adapter-sjbcm5ew.js +19 -0
- package/dist/handlers-yzy0c87x.js +35 -0
- package/dist/{heartbeat-6bpa611t.js → heartbeat-2f6z4kdx.js} +23 -21
- package/dist/{hook-w12k146y.js → hook-8y0gvtp1.js} +6 -6
- package/dist/{hook-hvm5nf46.js → hook-w1skzaqc.js} +5 -5
- package/dist/{http-43tthdvs.js → http-wghxvpef.js} +714 -145
- package/dist/{index-1f0vypbg.js → index-0h6qd4p1.js} +34 -24
- package/dist/index-25pvya7q.js +40 -0
- package/dist/index-2t4859r5.js +35 -0
- package/dist/{index-4b1q8kan.js → index-4k7m5dgj.js} +629 -354
- package/dist/index-620y7jzq.js +15 -0
- package/dist/{index-cret47a5.js → index-8p0j4h4j.js} +506 -43
- package/dist/{index-mhq4sh5w.js → index-8zn8nxn5.js} +1 -1
- package/dist/{index-m5gx1xd6.js → index-9myfj74s.js} +40 -40
- package/dist/{index-ftywhyr0.js → index-9zkchs9t.js} +221 -65
- package/dist/{index-bs7gw5fd.js → index-b5wgnm78.js} +44 -44
- package/dist/index-cxca2t8y.js +36 -0
- package/dist/{index-585gyczt.js → index-pe3d8jfy.js} +3 -3
- package/dist/{index-tx9mc2ap.js → index-rv89fvzf.js} +24 -22
- package/dist/{index-fn054vsf.js → index-s71ez27v.js} +1 -1
- package/dist/{keepalive-rk0j0jvh.js → keepalive-sh02349h.js} +3 -3
- package/dist/lead-gk4h5eg7.js +74 -0
- package/dist/{maintenance-g6z6kaxw.js → maintenance-yj0dcjja.js} +1 -1
- package/dist/{node-jftbyawr.js → node-dqm4xgxw.js} +1 -1
- package/dist/{oauth-refresh-sweep-2k3g2q4w.js → oauth-refresh-sweep-d9xedk66.js} +2 -2
- package/dist/{onboard-6fdbvh3v.js → onboard-dpgjn03r.js} +2 -2
- package/dist/{opencode-adapter-fdbsvts7.js → opencode-adapter-2d31cpjc.js} +6 -6
- package/dist/{otel-impl-rvwtc09q.js → otel-impl-1skarpfq.js} +1 -1
- package/dist/{pending-sqkrb836.js → pending-bfmxtx0g.js} +21 -19
- package/dist/{pi-mono-adapter-asqayqcg.js → pi-mono-adapter-gvppnasy.js} +40 -13
- package/dist/{pricing-refresh-f5tkgmw2.js → pricing-refresh-c6b325mk.js} +2 -2
- package/dist/{rbac-roles-06s555fa.js → rbac-roles-h80qbdbs.js} +3 -3
- package/dist/{rbac-roles-szxsg8t1.js → rbac-roles-zfcx68tx.js} +2 -2
- package/dist/{render-v2-103p266q.js → render-v2-nx20t3rb.js} +6 -3
- package/dist/{resume-v7kjewt9.js → resume-5ep8agan.js} +10 -7
- package/dist/{runtime-f1gmk0b7.js → runtime-r3pj4mce.js} +1 -1
- package/dist/{session-access-6shev8ts.js → session-access-n7p3m15b.js} +4 -4
- package/dist/{session-source-backfill-bd7spzjd.js → session-source-backfill-v8mt0zwn.js} +3 -3
- package/dist/{setup-kmxmztdb.js → setup-z1psaqhe.js} +1 -1
- package/dist/thread-buffer-a1re2r9r.js +38 -0
- package/dist/{virtual-modules-57eje5wy.js → virtual-modules-rrbjdpxn.js} +3 -3
- package/dist/{work-objects-zr47ygmf.js → work-objects-4aghh73z.js} +29 -23
- package/dist/worker-3dyyb8ev.js +74 -0
- package/dist/{worker-follow-up-grrr3fda.js → worker-follow-up-166zmex1.js} +20 -18
- package/openapi.json +1387 -13
- package/package.json +7 -6
- package/src/apps/catalog.generated.json +43 -3
- package/src/apps/page-validator.ts +27 -0
- package/src/be/db/model-profiles.ts +4 -1
- package/src/be/db/session-costs.ts +219 -0
- package/src/be/db/session-log-reasoning.ts +36 -0
- package/src/be/db/tasks/read.ts +7 -3
- package/src/be/db/tasks/write.ts +33 -1
- package/src/be/db.ts +200 -304
- package/src/be/key-window-usage.ts +385 -0
- package/src/be/migrations/303_task_ui_specs.sql +28 -0
- package/src/be/migrations/306_provider_account_telemetry.sql +1 -0
- package/src/be/migrations/307_session_cost_credential_attribution.sql +23 -0
- package/src/be/migrations/310_session_logs_reasoning.sql +12 -0
- package/src/be/runtime-pools/db.ts +3 -0
- package/src/be/seed-scripts/catalog/boot-triage.inline.ts +1 -0
- package/src/be/seed-scripts/catalog/boot-triage.ts +1 -0
- package/src/be/seed-scripts/catalog/wait-for-task.ts +5 -1
- package/src/be/seed-skills/index.ts +3 -0
- package/src/be/swarm-config-guard.ts +24 -1
- package/src/be/task-ui-spec.ts +158 -0
- package/src/commands/controller.ts +3 -0
- package/src/commands/credential-outcome-report.ts +13 -3
- package/src/commands/rate-limit-outcome.ts +6 -0
- package/src/commands/runner.ts +34 -53
- package/src/extensions/catalog.generated.json +3 -3
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/api-keys.ts +258 -30
- package/src/http/session-data.ts +74 -23
- package/src/http/sessions.ts +6 -2
- package/src/http/tasks.ts +105 -5
- package/src/integrations/chat-sdk/relay.ts +87 -0
- package/src/jira/outbound.ts +5 -3
- package/src/linear/outbound.ts +5 -1
- package/src/prompts/base-prompt.ts +8 -0
- package/src/prompts/session-templates.ts +19 -2
- package/src/providers/acp-targets.ts +1 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/claude-adapter.ts +27 -4
- package/src/providers/claude-flag-settings.ts +39 -1
- package/src/providers/codex-adapter.ts +85 -3
- package/src/providers/codex-app-server.ts +9 -5
- package/src/providers/codex-oauth/auth-json.ts +1 -0
- package/src/providers/pi-mono-adapter.ts +35 -2
- package/src/providers/pricing-sources.md +32 -0
- package/src/providers/types.ts +11 -0
- package/src/runtime-providers/docker.ts +65 -1
- package/src/scheduler/deferred-task-waits.ts +18 -5
- package/src/scripts-runtime/types/swarm-extension.d.ts +8 -8
- package/src/slack/actions.ts +56 -0
- package/src/slack/app.ts +22 -15
- package/src/slack/inbound-files.ts +2 -0
- package/src/slack/render-v2.ts +107 -23
- package/src/slack/responses.ts +3 -2
- package/src/slack/work-objects.ts +4 -1
- package/src/tasks/errors.ts +5 -0
- package/src/tests/acp-adapter.test.ts +4 -6
- package/src/tests/api-key-tracking.test.ts +0 -72
- package/src/tests/api-keys-status-model-limits.test.ts +93 -1
- package/src/tests/api-keys-validation.test.ts +42 -0
- package/src/tests/approval-card-resolution.test.ts +7 -1
- package/src/tests/approval-requests-notifications.test.ts +11 -1
- package/src/tests/apps-catalog-page-frame.test.ts +49 -0
- package/src/tests/apps-session-thread.test.ts +79 -0
- package/src/tests/base-prompt.test.ts +111 -5
- package/src/tests/chat-sdk-relay.test.ts +149 -1
- package/src/tests/claude-adapter-binary.test.ts +67 -6
- package/src/tests/claude-flag-settings.test.ts +29 -0
- package/src/tests/claude-sdk-lifecycle.test.ts +5 -0
- package/src/tests/codex-adapter.test.ts +340 -2
- package/src/tests/codex-app-server.test.ts +16 -0
- package/src/tests/codex-oauth.test.ts +3 -1
- package/src/tests/codex-rate-limits.test.ts +384 -0
- package/src/tests/credential-outcome-report.test.ts +20 -0
- package/src/tests/db-task-read-contract.test.ts +3 -0
- package/src/tests/db-task-write-contract.test.ts +4 -0
- package/src/tests/deferred-task-wake.test.ts +63 -1
- package/src/tests/docker-isolation-config-guard.test.ts +29 -0
- package/src/tests/docs-index-footprint.test.js +11 -3
- package/src/tests/e2e-visuals-comment.test.ts +82 -0
- package/src/tests/e2e-visuals-verify-pr.test.ts +138 -0
- package/src/tests/extensions-example-sql-admin-only.test.ts +7 -4
- package/src/tests/fixtures/ui-spec-slack/deploys.json +121 -0
- package/src/tests/fixtures/ui-spec-slack/incident.json +183 -0
- package/src/tests/fixtures/ui-spec-slack/three-charts-stale.json +196 -0
- package/src/tests/fixtures/ui-spec-slack/video-rejected-by-slack.json +183 -0
- package/src/tests/fixtures/ui-spec-slack/video.json +446 -0
- package/src/tests/gitleaks-download-retry.test.ts +85 -0
- package/src/tests/human-thread-routing.test.ts +187 -0
- package/src/tests/jira-outbound-sync.test.ts +33 -1
- package/src/tests/key-window-usage.test.ts +831 -0
- package/src/tests/linear-outbound-sync.test.ts +30 -1
- package/src/tests/pi-mono-adapter.test.ts +79 -0
- package/src/tests/preload-env.test.ts +2 -0
- package/src/tests/preload.ts +3 -1
- package/src/tests/prompt-template-session.test.ts +4 -3
- package/src/tests/provider-quota-persistence.test.ts +362 -0
- package/src/tests/rate-limit-event.test.ts +22 -0
- package/src/tests/reasoning-events.test.ts +164 -0
- package/src/tests/routing-affinity-inventory.test.ts +22 -0
- package/src/tests/runtime-providers-docker.test.ts +91 -0
- package/src/tests/script-connections.test.ts +5 -0
- package/src/tests/secret-canary-sweep.test.ts +41 -5
- package/src/tests/seed-scripts.test.ts +23 -0
- package/src/tests/session-cost-attribution.test.ts +748 -0
- package/src/tests/session-costs.test.ts +14 -15
- package/src/tests/session-logs.test.ts +83 -0
- package/src/tests/sessions-detail-batch.test.ts +7 -0
- package/src/tests/slack-render-v2.test.ts +357 -0
- package/src/tests/slack-start-reload-race.test.ts +67 -0
- package/src/tests/subscription-plans.test.ts +20 -1
- package/src/tests/task-ui-action-route.test.ts +191 -0
- package/src/tests/task-ui-actions.test.ts +195 -0
- package/src/tests/task-ui-spec-fallback.test.ts +65 -0
- package/src/tests/task-ui-spec.test.ts +368 -0
- package/src/tests/workflow-agent-task-retry.test.ts +34 -1
- package/src/tools/defer-task.ts +1 -1
- package/src/tools/store-progress.ts +69 -3
- package/src/types.ts +7 -2
- package/src/ui-spec/actions.ts +86 -0
- package/src/ui-spec/fallback.ts +19 -0
- package/src/ui-spec/slack.ts +17 -0
- package/src/ui-spec/validate.ts +169 -0
- package/src/utils/codex-rate-limits.ts +159 -0
- package/src/utils/credentials.ts +2 -0
- package/src/utils/error-tracker.ts +19 -0
- package/src/utils/provider-account-telemetry.ts +331 -0
- package/src/utils/reasoning-events.ts +107 -0
- package/src/utils/subscription-plans.ts +11 -59
- package/src/utils/task-ui-spec.ts +67 -0
- package/src/workflows/task-step-routing.ts +8 -3
- package/templates/extensions/sql-admin-only/README.md +2 -1
- package/templates/extensions/sql-admin-only/hooks.ts +7 -3
- package/templates/extensions/sql-admin-only/manifest.json +1 -1
- package/templates/skills/apps/SKILL.md +32 -5
- package/templates/skills/apps/content.md +32 -5
- package/templates/skills/ui-spec/config.json +14 -0
- package/templates/skills/ui-spec/content.md +127 -0
- package/dist/acp-adapter-jqn86aam.js +0 -16
- package/dist/cli-srtkr1h2.js +0 -12078
- package/dist/fx-adapter-0zrkfbkd.js +0 -19
- package/dist/grok-adapter-3db1c538.js +0 -19
- package/dist/handlers-k22n8mnn.js +0 -33
- package/dist/index-8xcyd3mc.js +0 -33
- package/dist/index-9sy2bh6n.js +0 -38
- package/dist/index-b24j7t2m.js +0 -12797
- package/dist/index-wjd56k1v.js +0 -34
- package/dist/lead-atxf3q6e.js +0 -72
- package/dist/thread-buffer-4yz236d0.js +0 -36
- package/dist/worker-p4hbtcy3.js +0 -72
- package/dist/{cli-j49yqpvh.js → cli-7evph51z.js} +3 -3
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
slackContextKey,
|
|
3
|
-
init_context_key,
|
|
4
2
|
encryptSecret,
|
|
5
3
|
decryptSecret,
|
|
6
4
|
getEncryptionKey,
|
|
7
5
|
init_crypto,
|
|
8
6
|
bindLoopPath,
|
|
9
7
|
init_event_loop_lag,
|
|
8
|
+
scrubJsonValue,
|
|
9
|
+
init_scrub_json,
|
|
10
10
|
getDbClient2,
|
|
11
|
+
slackContextKey,
|
|
12
|
+
init_context_key,
|
|
11
13
|
SLACK_REACTION_DEFAULTS,
|
|
12
14
|
SLACK_REACTION_CONFIG_KEYS,
|
|
13
15
|
reactionName,
|
|
@@ -56,15 +58,11 @@ import {
|
|
|
56
58
|
checkDependencies2,
|
|
57
59
|
emitBuiltInIntegrationConnectedOnce2,
|
|
58
60
|
init_db4
|
|
59
|
-
} from "./cli-
|
|
61
|
+
} from "./cli-ctx0b85j.js";
|
|
60
62
|
import {
|
|
61
63
|
getChannelBlockReason2,
|
|
62
64
|
init_external_channel
|
|
63
|
-
} from "./cli-
|
|
64
|
-
import {
|
|
65
|
-
workflowEventBus2,
|
|
66
|
-
init_event_bus
|
|
67
|
-
} from "./cli-q2d3e1k1.js";
|
|
65
|
+
} from "./cli-xag7btpe.js";
|
|
68
66
|
import {
|
|
69
67
|
require_dist6,
|
|
70
68
|
require_is_electron,
|
|
@@ -72,8 +70,15 @@ import {
|
|
|
72
70
|
require_dist7,
|
|
73
71
|
require_eventemitter3,
|
|
74
72
|
require_dist8,
|
|
75
|
-
require_src2
|
|
76
|
-
|
|
73
|
+
require_src2,
|
|
74
|
+
cardToBlockKit2,
|
|
75
|
+
cardToFallbackText2,
|
|
76
|
+
init_dist6
|
|
77
|
+
} from "./cli-47hz21se.js";
|
|
78
|
+
import {
|
|
79
|
+
workflowEventBus2,
|
|
80
|
+
init_event_bus
|
|
81
|
+
} from "./cli-q2d3e1k1.js";
|
|
77
82
|
import {
|
|
78
83
|
require_jsonwebtoken,
|
|
79
84
|
require_dist9,
|
|
@@ -90,7 +95,7 @@ import {
|
|
|
90
95
|
import {
|
|
91
96
|
isTerminalTaskStatus,
|
|
92
97
|
init_types5
|
|
93
|
-
} from "./cli-
|
|
98
|
+
} from "./cli-bkjdknnp.js";
|
|
94
99
|
import {
|
|
95
100
|
getGitHubLinkConfig,
|
|
96
101
|
init_github_host
|
|
@@ -98,7 +103,7 @@ import {
|
|
|
98
103
|
import {
|
|
99
104
|
taskAttachmentDisplayUrl,
|
|
100
105
|
init_task_attachment_links
|
|
101
|
-
} from "./cli-
|
|
106
|
+
} from "./cli-m7c2380k.js";
|
|
102
107
|
import {
|
|
103
108
|
getSlackConfiguration,
|
|
104
109
|
init_config4
|
|
@@ -110,8 +115,17 @@ import {
|
|
|
110
115
|
string2,
|
|
111
116
|
number2,
|
|
112
117
|
boolean,
|
|
118
|
+
_null,
|
|
119
|
+
any,
|
|
120
|
+
unknown,
|
|
121
|
+
array2,
|
|
113
122
|
object2,
|
|
114
|
-
|
|
123
|
+
strictObject2,
|
|
124
|
+
union3,
|
|
125
|
+
record2,
|
|
126
|
+
_enum2,
|
|
127
|
+
literal2,
|
|
128
|
+
lazy
|
|
115
129
|
} from "./cli-hg42n3hx.js";
|
|
116
130
|
import {
|
|
117
131
|
getAppUrl,
|
|
@@ -12369,7 +12383,7 @@ async function initOtel(serviceRole = process.env.AGENT_ROLE || "api") {
|
|
|
12369
12383
|
return;
|
|
12370
12384
|
initialized = true;
|
|
12371
12385
|
try {
|
|
12372
|
-
const impl = await import("./otel-impl-
|
|
12386
|
+
const impl = await import("./otel-impl-1skarpfq.js");
|
|
12373
12387
|
await impl.boot(serviceRole, {
|
|
12374
12388
|
exportConsoleLogs: serviceRole === "api" && isApiLogExportEnabled()
|
|
12375
12389
|
});
|
|
@@ -13212,6 +13226,2114 @@ var init_task_citations2 = __esm(() => {
|
|
|
13212
13226
|
});
|
|
13213
13227
|
});
|
|
13214
13228
|
|
|
13229
|
+
// src/be/task-ui-spec.ts
|
|
13230
|
+
function rowToTaskUiSpec(row) {
|
|
13231
|
+
const value = { spec: JSON.parse(row.spec), fallbackText: row.fallbackText };
|
|
13232
|
+
if (row.actions !== null)
|
|
13233
|
+
value.actions = JSON.parse(row.actions);
|
|
13234
|
+
return value;
|
|
13235
|
+
}
|
|
13236
|
+
async function getTaskUiSpec(taskId) {
|
|
13237
|
+
const row = await getDbClient2().get(`SELECT task_id AS taskId, spec, actions, fallback_text AS fallbackText
|
|
13238
|
+
FROM task_ui_specs WHERE task_id = ?`, [taskId]);
|
|
13239
|
+
return row ? rowToTaskUiSpec(row) : null;
|
|
13240
|
+
}
|
|
13241
|
+
async function getTaskUiSpecsForTasks(taskIds) {
|
|
13242
|
+
const ids = [...new Set(taskIds)];
|
|
13243
|
+
const byTask = new Map(ids.map((id) => [id, null]));
|
|
13244
|
+
for (let i = 0;i < ids.length; i += TASK_ID_CHUNK2) {
|
|
13245
|
+
const chunk = ids.slice(i, i + TASK_ID_CHUNK2);
|
|
13246
|
+
const rows = await getDbClient2().query(`SELECT task_id AS taskId, spec, actions, fallback_text AS fallbackText
|
|
13247
|
+
FROM task_ui_specs WHERE task_id IN (${chunk.map(() => "?").join(",")})`, chunk);
|
|
13248
|
+
for (const row of rows)
|
|
13249
|
+
byTask.set(row.taskId, rowToTaskUiSpec(row));
|
|
13250
|
+
}
|
|
13251
|
+
return byTask;
|
|
13252
|
+
}
|
|
13253
|
+
async function upsertTaskUiSpec(taskId, value, userId) {
|
|
13254
|
+
await getDbClient2().run(`INSERT INTO task_ui_specs (task_id, spec, actions, fallback_text, created_by, updated_by)
|
|
13255
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
13256
|
+
ON CONFLICT(task_id) DO UPDATE SET
|
|
13257
|
+
spec=excluded.spec, actions=excluded.actions, fallback_text=excluded.fallback_text,
|
|
13258
|
+
updated_by=excluded.updated_by, updated_at=strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`, [
|
|
13259
|
+
taskId,
|
|
13260
|
+
scrubJsonValue(value.spec),
|
|
13261
|
+
value.actions === undefined ? null : scrubJsonValue(value.actions),
|
|
13262
|
+
scrubSecrets(value.fallbackText),
|
|
13263
|
+
userId ?? null,
|
|
13264
|
+
userId ?? null
|
|
13265
|
+
]);
|
|
13266
|
+
}
|
|
13267
|
+
async function reserveTaskUiActionRun({
|
|
13268
|
+
taskId,
|
|
13269
|
+
actionId,
|
|
13270
|
+
surface,
|
|
13271
|
+
slackUserId,
|
|
13272
|
+
userId
|
|
13273
|
+
}) {
|
|
13274
|
+
const { changes } = await getDbClient2().run(`INSERT INTO task_ui_action_runs
|
|
13275
|
+
(task_id, action_id, surface, slack_user_id, created_by, updated_by)
|
|
13276
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
13277
|
+
ON CONFLICT(task_id, action_id) DO NOTHING`, [taskId, actionId, surface, slackUserId ?? null, userId ?? null, userId ?? null]);
|
|
13278
|
+
return changes === 1 ? "reserved" : "exists";
|
|
13279
|
+
}
|
|
13280
|
+
async function releaseTaskUiActionRun(taskId, actionId) {
|
|
13281
|
+
await getDbClient2().run(`DELETE FROM task_ui_action_runs
|
|
13282
|
+
WHERE task_id = ? AND action_id = ? AND result_task_id IS NULL`, [taskId, actionId]);
|
|
13283
|
+
}
|
|
13284
|
+
async function setTaskUiActionResult(taskId, actionId, resultTaskId) {
|
|
13285
|
+
await getDbClient2().run(`UPDATE task_ui_action_runs SET result_task_id = ?,
|
|
13286
|
+
updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
13287
|
+
WHERE task_id = ? AND action_id = ?`, [resultTaskId, taskId, actionId]);
|
|
13288
|
+
}
|
|
13289
|
+
async function hasTaskUiSpecCheckRefusal(taskId) {
|
|
13290
|
+
return Boolean(await getDbClient2().get("SELECT id FROM agent_log WHERE taskId = ? AND eventType = 'task_ui_spec_check_refused' LIMIT 1", [taskId]));
|
|
13291
|
+
}
|
|
13292
|
+
var TaskUiSpecSchema, TASK_ID_CHUNK2 = 500;
|
|
13293
|
+
var init_task_ui_spec = __esm(() => {
|
|
13294
|
+
init_zod();
|
|
13295
|
+
init_secret_scrubber();
|
|
13296
|
+
init_db4();
|
|
13297
|
+
init_scrub_json();
|
|
13298
|
+
TaskUiSpecSchema = object2({
|
|
13299
|
+
spec: object2({
|
|
13300
|
+
root: string2(),
|
|
13301
|
+
elements: record2(string2(), unknown()),
|
|
13302
|
+
state: record2(string2(), unknown()).optional()
|
|
13303
|
+
}),
|
|
13304
|
+
actions: record2(string2(), object2({ kind: literal2("follow_up"), prompt: string2() })).optional(),
|
|
13305
|
+
fallbackText: string2()
|
|
13306
|
+
});
|
|
13307
|
+
});
|
|
13308
|
+
|
|
13309
|
+
// node_modules/@json-render/core/dist/chunk-FVP4K5MD.mjs
|
|
13310
|
+
function unescapeJsonPointer(token) {
|
|
13311
|
+
return token.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
13312
|
+
}
|
|
13313
|
+
function parseJsonPointer(path) {
|
|
13314
|
+
const raw = path.startsWith("/") ? path.slice(1).split("/") : path.split("/");
|
|
13315
|
+
return raw.map(unescapeJsonPointer);
|
|
13316
|
+
}
|
|
13317
|
+
function getByPath(obj, path) {
|
|
13318
|
+
if (!path || path === "/") {
|
|
13319
|
+
return obj;
|
|
13320
|
+
}
|
|
13321
|
+
const segments = parseJsonPointer(path);
|
|
13322
|
+
let current = obj;
|
|
13323
|
+
for (const segment of segments) {
|
|
13324
|
+
if (current === null || current === undefined) {
|
|
13325
|
+
return;
|
|
13326
|
+
}
|
|
13327
|
+
if (Array.isArray(current)) {
|
|
13328
|
+
const index = parseInt(segment, 10);
|
|
13329
|
+
current = current[index];
|
|
13330
|
+
} else if (typeof current === "object" && Object.hasOwn(current, segment)) {
|
|
13331
|
+
current = current[segment];
|
|
13332
|
+
} else {
|
|
13333
|
+
return;
|
|
13334
|
+
}
|
|
13335
|
+
}
|
|
13336
|
+
return current;
|
|
13337
|
+
}
|
|
13338
|
+
function resolveRepeatStatePath(statePath, repeatBasePath) {
|
|
13339
|
+
if (typeof statePath === "string") {
|
|
13340
|
+
return statePath;
|
|
13341
|
+
}
|
|
13342
|
+
if (repeatBasePath == null) {
|
|
13343
|
+
return;
|
|
13344
|
+
}
|
|
13345
|
+
if (statePath.$item === "" || statePath.$item === "/") {
|
|
13346
|
+
return repeatBasePath;
|
|
13347
|
+
}
|
|
13348
|
+
return joinStatePath(repeatBasePath, statePath.$item);
|
|
13349
|
+
}
|
|
13350
|
+
function resolveRepeatItemStatePath(statePath, index) {
|
|
13351
|
+
return joinStatePath(statePath, String(index));
|
|
13352
|
+
}
|
|
13353
|
+
function joinStatePath(basePath, childPath) {
|
|
13354
|
+
const child = childPath.startsWith("/") ? childPath.slice(1) : childPath;
|
|
13355
|
+
if (basePath === "" || basePath === "/") {
|
|
13356
|
+
return `/${child}`;
|
|
13357
|
+
}
|
|
13358
|
+
return `${basePath}/${child}`;
|
|
13359
|
+
}
|
|
13360
|
+
var DynamicValueSchema, DynamicStringSchema, DynamicNumberSchema, DynamicBooleanSchema, SPEC_DATA_PART = "spec", SPEC_DATA_PART_TYPE;
|
|
13361
|
+
var init_chunk_FVP4K5MD = __esm(() => {
|
|
13362
|
+
init_zod();
|
|
13363
|
+
DynamicValueSchema = union3([
|
|
13364
|
+
string2(),
|
|
13365
|
+
number2(),
|
|
13366
|
+
boolean(),
|
|
13367
|
+
_null(),
|
|
13368
|
+
object2({ $state: string2() })
|
|
13369
|
+
]);
|
|
13370
|
+
DynamicStringSchema = union3([
|
|
13371
|
+
string2(),
|
|
13372
|
+
object2({ $state: string2() })
|
|
13373
|
+
]);
|
|
13374
|
+
DynamicNumberSchema = union3([
|
|
13375
|
+
number2(),
|
|
13376
|
+
object2({ $state: string2() })
|
|
13377
|
+
]);
|
|
13378
|
+
DynamicBooleanSchema = union3([
|
|
13379
|
+
boolean(),
|
|
13380
|
+
object2({ $state: string2() })
|
|
13381
|
+
]);
|
|
13382
|
+
SPEC_DATA_PART_TYPE = `data-${SPEC_DATA_PART}`;
|
|
13383
|
+
});
|
|
13384
|
+
|
|
13385
|
+
// node_modules/@json-render/core/dist/index.mjs
|
|
13386
|
+
function conditionUsesItemScope(condition) {
|
|
13387
|
+
if (condition === undefined || typeof condition === "boolean")
|
|
13388
|
+
return false;
|
|
13389
|
+
if (Array.isArray(condition))
|
|
13390
|
+
return condition.some(conditionUsesItemScope);
|
|
13391
|
+
if (typeof condition !== "object" || condition === null)
|
|
13392
|
+
return false;
|
|
13393
|
+
if ("$item" in condition || "$index" in condition)
|
|
13394
|
+
return true;
|
|
13395
|
+
if ("$and" in condition)
|
|
13396
|
+
return condition.$and.some(conditionUsesItemScope);
|
|
13397
|
+
if ("$or" in condition)
|
|
13398
|
+
return condition.$or.some(conditionUsesItemScope);
|
|
13399
|
+
return false;
|
|
13400
|
+
}
|
|
13401
|
+
function splitRepeatVisibility(condition) {
|
|
13402
|
+
if (condition === undefined || !conditionUsesItemScope(condition)) {
|
|
13403
|
+
return { container: condition, itemFilter: undefined };
|
|
13404
|
+
}
|
|
13405
|
+
const partition = (parts) => {
|
|
13406
|
+
const container = parts.filter((part) => !conditionUsesItemScope(part));
|
|
13407
|
+
const item = parts.filter((part) => conditionUsesItemScope(part));
|
|
13408
|
+
return {
|
|
13409
|
+
container: container.length > 0 ? { $and: container } : undefined,
|
|
13410
|
+
itemFilter: item.length > 0 ? { $and: item } : undefined
|
|
13411
|
+
};
|
|
13412
|
+
};
|
|
13413
|
+
if (Array.isArray(condition))
|
|
13414
|
+
return partition(condition);
|
|
13415
|
+
if (typeof condition === "object" && condition !== null && "$and" in condition) {
|
|
13416
|
+
return partition(condition.$and);
|
|
13417
|
+
}
|
|
13418
|
+
return { container: undefined, itemFilter: condition };
|
|
13419
|
+
}
|
|
13420
|
+
function resolveComparisonValue(value, ctx) {
|
|
13421
|
+
if (typeof value === "object" && value !== null) {
|
|
13422
|
+
if ("$state" in value && typeof value.$state === "string") {
|
|
13423
|
+
return getByPath(ctx.stateModel, value.$state);
|
|
13424
|
+
}
|
|
13425
|
+
}
|
|
13426
|
+
return value;
|
|
13427
|
+
}
|
|
13428
|
+
function isItemCondition(cond) {
|
|
13429
|
+
return "$item" in cond;
|
|
13430
|
+
}
|
|
13431
|
+
function isIndexCondition(cond) {
|
|
13432
|
+
return "$index" in cond;
|
|
13433
|
+
}
|
|
13434
|
+
function resolveConditionValue(cond, ctx) {
|
|
13435
|
+
if (isIndexCondition(cond)) {
|
|
13436
|
+
return ctx.repeatIndex;
|
|
13437
|
+
}
|
|
13438
|
+
if (isItemCondition(cond)) {
|
|
13439
|
+
if (ctx.repeatItem === undefined)
|
|
13440
|
+
return;
|
|
13441
|
+
return cond.$item === "" ? ctx.repeatItem : getByPath(ctx.repeatItem, cond.$item);
|
|
13442
|
+
}
|
|
13443
|
+
return getByPath(ctx.stateModel, cond.$state);
|
|
13444
|
+
}
|
|
13445
|
+
function evaluateCondition(cond, ctx) {
|
|
13446
|
+
const value = resolveConditionValue(cond, ctx);
|
|
13447
|
+
let result;
|
|
13448
|
+
if (cond.eq !== undefined) {
|
|
13449
|
+
const rhs = resolveComparisonValue(cond.eq, ctx);
|
|
13450
|
+
result = value === rhs;
|
|
13451
|
+
} else if (cond.neq !== undefined) {
|
|
13452
|
+
const rhs = resolveComparisonValue(cond.neq, ctx);
|
|
13453
|
+
result = value !== rhs;
|
|
13454
|
+
} else if (cond.gt !== undefined) {
|
|
13455
|
+
const rhs = resolveComparisonValue(cond.gt, ctx);
|
|
13456
|
+
result = typeof value === "number" && typeof rhs === "number" ? value > rhs : false;
|
|
13457
|
+
} else if (cond.gte !== undefined) {
|
|
13458
|
+
const rhs = resolveComparisonValue(cond.gte, ctx);
|
|
13459
|
+
result = typeof value === "number" && typeof rhs === "number" ? value >= rhs : false;
|
|
13460
|
+
} else if (cond.lt !== undefined) {
|
|
13461
|
+
const rhs = resolveComparisonValue(cond.lt, ctx);
|
|
13462
|
+
result = typeof value === "number" && typeof rhs === "number" ? value < rhs : false;
|
|
13463
|
+
} else if (cond.lte !== undefined) {
|
|
13464
|
+
const rhs = resolveComparisonValue(cond.lte, ctx);
|
|
13465
|
+
result = typeof value === "number" && typeof rhs === "number" ? value <= rhs : false;
|
|
13466
|
+
} else {
|
|
13467
|
+
result = Boolean(value);
|
|
13468
|
+
}
|
|
13469
|
+
return cond.not === true ? !result : result;
|
|
13470
|
+
}
|
|
13471
|
+
function isAndCondition(condition) {
|
|
13472
|
+
return typeof condition === "object" && condition !== null && !Array.isArray(condition) && "$and" in condition;
|
|
13473
|
+
}
|
|
13474
|
+
function isOrCondition(condition) {
|
|
13475
|
+
return typeof condition === "object" && condition !== null && !Array.isArray(condition) && "$or" in condition;
|
|
13476
|
+
}
|
|
13477
|
+
function evaluateVisibility(condition, ctx) {
|
|
13478
|
+
if (condition === undefined) {
|
|
13479
|
+
return true;
|
|
13480
|
+
}
|
|
13481
|
+
if (typeof condition === "boolean") {
|
|
13482
|
+
return condition;
|
|
13483
|
+
}
|
|
13484
|
+
if (Array.isArray(condition)) {
|
|
13485
|
+
return condition.every((c) => evaluateCondition(c, ctx));
|
|
13486
|
+
}
|
|
13487
|
+
if (isAndCondition(condition)) {
|
|
13488
|
+
return condition.$and.every((child) => evaluateVisibility(child, ctx));
|
|
13489
|
+
}
|
|
13490
|
+
if (isOrCondition(condition)) {
|
|
13491
|
+
return condition.$or.some((child) => evaluateVisibility(child, ctx));
|
|
13492
|
+
}
|
|
13493
|
+
return evaluateCondition(condition, ctx);
|
|
13494
|
+
}
|
|
13495
|
+
function findDirective(value, directives) {
|
|
13496
|
+
if (!directives || directives.size === 0)
|
|
13497
|
+
return;
|
|
13498
|
+
let match;
|
|
13499
|
+
for (const [key, def] of directives) {
|
|
13500
|
+
if (key in value) {
|
|
13501
|
+
if (match) {
|
|
13502
|
+
throw new Error(`Ambiguous directive: object has multiple directive keys ("${match.name}" and "${key}")`);
|
|
13503
|
+
}
|
|
13504
|
+
match = def;
|
|
13505
|
+
}
|
|
13506
|
+
}
|
|
13507
|
+
return match;
|
|
13508
|
+
}
|
|
13509
|
+
function isStateExpression(value) {
|
|
13510
|
+
return typeof value === "object" && value !== null && "$state" in value && typeof value.$state === "string";
|
|
13511
|
+
}
|
|
13512
|
+
function isItemExpression(value) {
|
|
13513
|
+
return typeof value === "object" && value !== null && "$item" in value && typeof value.$item === "string";
|
|
13514
|
+
}
|
|
13515
|
+
function isIndexExpression(value) {
|
|
13516
|
+
return typeof value === "object" && value !== null && "$index" in value && value.$index === true;
|
|
13517
|
+
}
|
|
13518
|
+
function isBindStateExpression(value) {
|
|
13519
|
+
return typeof value === "object" && value !== null && "$bindState" in value && typeof value.$bindState === "string";
|
|
13520
|
+
}
|
|
13521
|
+
function isBindItemExpression(value) {
|
|
13522
|
+
return typeof value === "object" && value !== null && "$bindItem" in value && typeof value.$bindItem === "string";
|
|
13523
|
+
}
|
|
13524
|
+
function isCondExpression(value) {
|
|
13525
|
+
return typeof value === "object" && value !== null && "$cond" in value && "$then" in value && "$else" in value;
|
|
13526
|
+
}
|
|
13527
|
+
function isComputedExpression(value) {
|
|
13528
|
+
return typeof value === "object" && value !== null && "$computed" in value && typeof value.$computed === "string";
|
|
13529
|
+
}
|
|
13530
|
+
function isTemplateExpression(value) {
|
|
13531
|
+
return typeof value === "object" && value !== null && "$template" in value && typeof value.$template === "string";
|
|
13532
|
+
}
|
|
13533
|
+
function resolveBindItemPath(itemPath, ctx) {
|
|
13534
|
+
if (ctx.repeatBasePath == null) {
|
|
13535
|
+
console.warn(`$bindItem used outside repeat scope: "${itemPath}"`);
|
|
13536
|
+
return;
|
|
13537
|
+
}
|
|
13538
|
+
if (itemPath === "")
|
|
13539
|
+
return ctx.repeatBasePath;
|
|
13540
|
+
return ctx.repeatBasePath + "/" + itemPath;
|
|
13541
|
+
}
|
|
13542
|
+
function resolvePropValue(value, ctx) {
|
|
13543
|
+
if (value === null || value === undefined) {
|
|
13544
|
+
return value;
|
|
13545
|
+
}
|
|
13546
|
+
if (isStateExpression(value)) {
|
|
13547
|
+
return getByPath(ctx.stateModel, value.$state);
|
|
13548
|
+
}
|
|
13549
|
+
if (isItemExpression(value)) {
|
|
13550
|
+
if (ctx.repeatItem === undefined)
|
|
13551
|
+
return;
|
|
13552
|
+
return value.$item === "" ? ctx.repeatItem : getByPath(ctx.repeatItem, value.$item);
|
|
13553
|
+
}
|
|
13554
|
+
if (isIndexExpression(value)) {
|
|
13555
|
+
return ctx.repeatIndex;
|
|
13556
|
+
}
|
|
13557
|
+
if (isBindStateExpression(value)) {
|
|
13558
|
+
return getByPath(ctx.stateModel, value.$bindState);
|
|
13559
|
+
}
|
|
13560
|
+
if (isBindItemExpression(value)) {
|
|
13561
|
+
const resolvedPath = resolveBindItemPath(value.$bindItem, ctx);
|
|
13562
|
+
if (resolvedPath === undefined)
|
|
13563
|
+
return;
|
|
13564
|
+
return getByPath(ctx.stateModel, resolvedPath);
|
|
13565
|
+
}
|
|
13566
|
+
if (isCondExpression(value)) {
|
|
13567
|
+
const result = evaluateVisibility(value.$cond, ctx);
|
|
13568
|
+
return resolvePropValue(result ? value.$then : value.$else, ctx);
|
|
13569
|
+
}
|
|
13570
|
+
if (isComputedExpression(value)) {
|
|
13571
|
+
const fn = ctx.functions?.[value.$computed];
|
|
13572
|
+
if (!fn) {
|
|
13573
|
+
if (!warnedComputedFns.has(value.$computed)) {
|
|
13574
|
+
if (warnedComputedFns.size < WARNED_COMPUTED_MAX) {
|
|
13575
|
+
warnedComputedFns.add(value.$computed);
|
|
13576
|
+
}
|
|
13577
|
+
console.warn(`Unknown $computed function: "${value.$computed}"`);
|
|
13578
|
+
}
|
|
13579
|
+
return;
|
|
13580
|
+
}
|
|
13581
|
+
const resolvedArgs = {};
|
|
13582
|
+
if (value.args) {
|
|
13583
|
+
for (const [key, arg] of Object.entries(value.args)) {
|
|
13584
|
+
resolvedArgs[key] = resolvePropValue(arg, ctx);
|
|
13585
|
+
}
|
|
13586
|
+
}
|
|
13587
|
+
return fn(resolvedArgs);
|
|
13588
|
+
}
|
|
13589
|
+
if (isTemplateExpression(value)) {
|
|
13590
|
+
return value.$template.replace(/\$\{([^}]+)\}/g, (_match, rawPath) => {
|
|
13591
|
+
if (rawPath.startsWith("/")) {
|
|
13592
|
+
const resolved2 = getByPath(ctx.stateModel, rawPath);
|
|
13593
|
+
return resolved2 != null ? String(resolved2) : "";
|
|
13594
|
+
}
|
|
13595
|
+
if (ctx.repeatItem !== undefined) {
|
|
13596
|
+
const fromItem = getByPath(ctx.repeatItem, rawPath);
|
|
13597
|
+
if (fromItem != null)
|
|
13598
|
+
return String(fromItem);
|
|
13599
|
+
}
|
|
13600
|
+
const resolved = getByPath(ctx.stateModel, "/" + rawPath);
|
|
13601
|
+
return resolved != null ? String(resolved) : "";
|
|
13602
|
+
});
|
|
13603
|
+
}
|
|
13604
|
+
if (Array.isArray(value)) {
|
|
13605
|
+
return value.map((item) => resolvePropValue(item, ctx));
|
|
13606
|
+
}
|
|
13607
|
+
if (typeof value === "object") {
|
|
13608
|
+
const directive = findDirective(value, ctx.directives);
|
|
13609
|
+
if (directive) {
|
|
13610
|
+
return directive.resolve(value, ctx);
|
|
13611
|
+
}
|
|
13612
|
+
const resolved = {};
|
|
13613
|
+
for (const [key, val] of Object.entries(value)) {
|
|
13614
|
+
resolved[key] = resolvePropValue(val, ctx);
|
|
13615
|
+
}
|
|
13616
|
+
return resolved;
|
|
13617
|
+
}
|
|
13618
|
+
return value;
|
|
13619
|
+
}
|
|
13620
|
+
function resolveElementProps(props, ctx) {
|
|
13621
|
+
const resolved = {};
|
|
13622
|
+
for (const [key, value] of Object.entries(props)) {
|
|
13623
|
+
resolved[key] = resolvePropValue(value, ctx);
|
|
13624
|
+
}
|
|
13625
|
+
return resolved;
|
|
13626
|
+
}
|
|
13627
|
+
function normalizeModes(config) {
|
|
13628
|
+
if (!config?.modes?.length)
|
|
13629
|
+
return DEFAULT_MODES;
|
|
13630
|
+
return config.modes;
|
|
13631
|
+
}
|
|
13632
|
+
function jsonPatchInstructions() {
|
|
13633
|
+
return [
|
|
13634
|
+
"PATCH MODE (RFC 6902 JSON Patch):",
|
|
13635
|
+
"Output one JSON object per line. Each line is a patch operation.",
|
|
13636
|
+
'- Add: {"op":"add","path":"/elements/new-key","value":{...}}',
|
|
13637
|
+
'- Replace: {"op":"replace","path":"/elements/existing-key","value":{...}}',
|
|
13638
|
+
'- Remove: {"op":"remove","path":"/elements/old-key"}',
|
|
13639
|
+
"Only output patches for what needs to change."
|
|
13640
|
+
].join(`
|
|
13641
|
+
`);
|
|
13642
|
+
}
|
|
13643
|
+
function jsonMergeInstructions() {
|
|
13644
|
+
return [
|
|
13645
|
+
"MERGE MODE (RFC 7396 JSON Merge Patch):",
|
|
13646
|
+
"Output a single JSON object on one line with __json_edit set to true.",
|
|
13647
|
+
"Include only the keys that changed. Unmentioned keys are preserved.",
|
|
13648
|
+
"Set a key to null to delete it.",
|
|
13649
|
+
"",
|
|
13650
|
+
"Example (update a title and add an element):",
|
|
13651
|
+
'{"__json_edit":true,"elements":{"main":{"props":{"title":"New Title"}},"new-el":{"type":"Card","props":{},"children":[]}}}',
|
|
13652
|
+
"",
|
|
13653
|
+
"Example (delete an element):",
|
|
13654
|
+
'{"__json_edit":true,"elements":{"old-widget":null}}'
|
|
13655
|
+
].join(`
|
|
13656
|
+
`);
|
|
13657
|
+
}
|
|
13658
|
+
function jsonDiffInstructions() {
|
|
13659
|
+
return [
|
|
13660
|
+
"DIFF MODE (unified diff):",
|
|
13661
|
+
"Output a unified diff inside a ```diff code fence.",
|
|
13662
|
+
"The diff applies against the JSON-serialized current spec.",
|
|
13663
|
+
"",
|
|
13664
|
+
"Example:",
|
|
13665
|
+
"```diff",
|
|
13666
|
+
"--- a/spec.json",
|
|
13667
|
+
"+++ b/spec.json",
|
|
13668
|
+
"@@ -3,1 +3,1 @@",
|
|
13669
|
+
'- "title": "Login"',
|
|
13670
|
+
'+ "title": "Welcome Back"',
|
|
13671
|
+
"```"
|
|
13672
|
+
].join(`
|
|
13673
|
+
`);
|
|
13674
|
+
}
|
|
13675
|
+
function yamlPatchInstructions() {
|
|
13676
|
+
return [
|
|
13677
|
+
"PATCH MODE (RFC 6902 JSON Patch):",
|
|
13678
|
+
"Output RFC 6902 JSON Patch lines inside a ```yaml-patch code fence.",
|
|
13679
|
+
"Each line is one JSON patch operation.",
|
|
13680
|
+
"",
|
|
13681
|
+
"Example:",
|
|
13682
|
+
"```yaml-patch",
|
|
13683
|
+
'{"op":"replace","path":"/elements/main/props/title","value":"New Title"}',
|
|
13684
|
+
'{"op":"add","path":"/elements/new-el","value":{"type":"Card","props":{},"children":[]}}',
|
|
13685
|
+
"```"
|
|
13686
|
+
].join(`
|
|
13687
|
+
`);
|
|
13688
|
+
}
|
|
13689
|
+
function yamlMergeInstructions() {
|
|
13690
|
+
return [
|
|
13691
|
+
"MERGE MODE (RFC 7396 JSON Merge Patch):",
|
|
13692
|
+
"Output only the changed parts in a ```yaml-edit code fence.",
|
|
13693
|
+
"Uses deep merge semantics: only keys you include are updated. Unmentioned elements and props are preserved.",
|
|
13694
|
+
"Set a key to null to delete it.",
|
|
13695
|
+
"",
|
|
13696
|
+
"Example edit (update title, add a new element):",
|
|
13697
|
+
"```yaml-edit",
|
|
13698
|
+
"elements:",
|
|
13699
|
+
" main:",
|
|
13700
|
+
" props:",
|
|
13701
|
+
" title: Updated Title",
|
|
13702
|
+
" new-chart:",
|
|
13703
|
+
" type: Card",
|
|
13704
|
+
" props: {}",
|
|
13705
|
+
" children: []",
|
|
13706
|
+
"```",
|
|
13707
|
+
"",
|
|
13708
|
+
"Example deletion:",
|
|
13709
|
+
"```yaml-edit",
|
|
13710
|
+
"elements:",
|
|
13711
|
+
" old-widget: null",
|
|
13712
|
+
"```"
|
|
13713
|
+
].join(`
|
|
13714
|
+
`);
|
|
13715
|
+
}
|
|
13716
|
+
function yamlDiffInstructions() {
|
|
13717
|
+
return [
|
|
13718
|
+
"DIFF MODE (unified diff):",
|
|
13719
|
+
"Output a unified diff inside a ```diff code fence.",
|
|
13720
|
+
"The diff applies against the YAML-serialized current spec.",
|
|
13721
|
+
"",
|
|
13722
|
+
"Example:",
|
|
13723
|
+
"```diff",
|
|
13724
|
+
"--- a/spec.yaml",
|
|
13725
|
+
"+++ b/spec.yaml",
|
|
13726
|
+
"@@ -6,1 +6,1 @@",
|
|
13727
|
+
"- title: Login",
|
|
13728
|
+
"+ title: Welcome Back",
|
|
13729
|
+
"```"
|
|
13730
|
+
].join(`
|
|
13731
|
+
`);
|
|
13732
|
+
}
|
|
13733
|
+
function modeSelectionGuidance(modes) {
|
|
13734
|
+
if (modes.length === 1)
|
|
13735
|
+
return "";
|
|
13736
|
+
const parts = ["Choose the best edit strategy for the requested change:"];
|
|
13737
|
+
if (modes.includes("patch")) {
|
|
13738
|
+
parts.push("- PATCH: best for precise, targeted single-field updates");
|
|
13739
|
+
}
|
|
13740
|
+
if (modes.includes("merge")) {
|
|
13741
|
+
parts.push("- MERGE: best for structural changes (add/remove elements, reparent children, update multiple props at once)");
|
|
13742
|
+
}
|
|
13743
|
+
if (modes.includes("diff")) {
|
|
13744
|
+
parts.push("- DIFF: best for small text-level changes when you can see the exact lines to change");
|
|
13745
|
+
}
|
|
13746
|
+
return parts.join(`
|
|
13747
|
+
`);
|
|
13748
|
+
}
|
|
13749
|
+
function buildEditInstructions(config, format) {
|
|
13750
|
+
const modes = normalizeModes(config);
|
|
13751
|
+
const sections = [];
|
|
13752
|
+
sections.push("EDITING EXISTING SPECS:");
|
|
13753
|
+
sections.push("");
|
|
13754
|
+
const guidance = modeSelectionGuidance(modes);
|
|
13755
|
+
if (guidance) {
|
|
13756
|
+
sections.push(guidance);
|
|
13757
|
+
sections.push("");
|
|
13758
|
+
}
|
|
13759
|
+
for (const mode of modes) {
|
|
13760
|
+
if (format === "json") {
|
|
13761
|
+
switch (mode) {
|
|
13762
|
+
case "patch":
|
|
13763
|
+
sections.push(jsonPatchInstructions());
|
|
13764
|
+
break;
|
|
13765
|
+
case "merge":
|
|
13766
|
+
sections.push(jsonMergeInstructions());
|
|
13767
|
+
break;
|
|
13768
|
+
case "diff":
|
|
13769
|
+
sections.push(jsonDiffInstructions());
|
|
13770
|
+
break;
|
|
13771
|
+
}
|
|
13772
|
+
} else {
|
|
13773
|
+
switch (mode) {
|
|
13774
|
+
case "patch":
|
|
13775
|
+
sections.push(yamlPatchInstructions());
|
|
13776
|
+
break;
|
|
13777
|
+
case "merge":
|
|
13778
|
+
sections.push(yamlMergeInstructions());
|
|
13779
|
+
break;
|
|
13780
|
+
case "diff":
|
|
13781
|
+
sections.push(yamlDiffInstructions());
|
|
13782
|
+
break;
|
|
13783
|
+
}
|
|
13784
|
+
}
|
|
13785
|
+
sections.push("");
|
|
13786
|
+
}
|
|
13787
|
+
return sections.join(`
|
|
13788
|
+
`);
|
|
13789
|
+
}
|
|
13790
|
+
function createBuilder() {
|
|
13791
|
+
return {
|
|
13792
|
+
string: () => ({ kind: "string" }),
|
|
13793
|
+
number: () => ({ kind: "number" }),
|
|
13794
|
+
boolean: () => ({ kind: "boolean" }),
|
|
13795
|
+
array: (item) => ({ kind: "array", inner: item }),
|
|
13796
|
+
object: (shape) => ({ kind: "object", inner: shape }),
|
|
13797
|
+
record: (value) => ({ kind: "record", inner: value }),
|
|
13798
|
+
any: () => ({ kind: "any" }),
|
|
13799
|
+
zod: () => ({ kind: "zod" }),
|
|
13800
|
+
ref: (path) => ({ kind: "ref", inner: path }),
|
|
13801
|
+
propsOf: (path) => ({ kind: "propsOf", inner: path }),
|
|
13802
|
+
map: (entryShape) => ({ kind: "map", inner: entryShape }),
|
|
13803
|
+
optional: () => ({ optional: true })
|
|
13804
|
+
};
|
|
13805
|
+
}
|
|
13806
|
+
function defineSchema(builder, options) {
|
|
13807
|
+
const s = createBuilder();
|
|
13808
|
+
const definition = builder(s);
|
|
13809
|
+
return {
|
|
13810
|
+
definition,
|
|
13811
|
+
promptTemplate: options?.promptTemplate,
|
|
13812
|
+
defaultRules: options?.defaultRules,
|
|
13813
|
+
builtInActions: options?.builtInActions,
|
|
13814
|
+
createCatalog(catalog) {
|
|
13815
|
+
return createCatalogFromSchema(this, catalog);
|
|
13816
|
+
}
|
|
13817
|
+
};
|
|
13818
|
+
}
|
|
13819
|
+
function createCatalogFromSchema(schema, catalogData) {
|
|
13820
|
+
const components = catalogData.components;
|
|
13821
|
+
const actions = catalogData.actions;
|
|
13822
|
+
const componentNames = components ? Object.keys(components) : [];
|
|
13823
|
+
const actionNames = actions ? Object.keys(actions) : [];
|
|
13824
|
+
const zodSchema = buildZodSchemaFromDefinition(schema.definition, catalogData);
|
|
13825
|
+
return {
|
|
13826
|
+
schema,
|
|
13827
|
+
data: catalogData,
|
|
13828
|
+
componentNames,
|
|
13829
|
+
actionNames,
|
|
13830
|
+
prompt(options = {}) {
|
|
13831
|
+
return generatePrompt(this, options);
|
|
13832
|
+
},
|
|
13833
|
+
jsonSchema(options = {}) {
|
|
13834
|
+
return zodToJsonSchema(zodSchema, options.strict ?? false);
|
|
13835
|
+
},
|
|
13836
|
+
validate(spec) {
|
|
13837
|
+
const result = zodSchema.safeParse(spec);
|
|
13838
|
+
if (result.success) {
|
|
13839
|
+
return {
|
|
13840
|
+
success: true,
|
|
13841
|
+
data: result.data
|
|
13842
|
+
};
|
|
13843
|
+
}
|
|
13844
|
+
return { success: false, error: result.error };
|
|
13845
|
+
},
|
|
13846
|
+
zodSchema() {
|
|
13847
|
+
return zodSchema;
|
|
13848
|
+
},
|
|
13849
|
+
get _specType() {
|
|
13850
|
+
throw new Error("_specType is only for type inference");
|
|
13851
|
+
}
|
|
13852
|
+
};
|
|
13853
|
+
}
|
|
13854
|
+
function buildZodSchemaFromDefinition(definition, catalogData) {
|
|
13855
|
+
return buildZodType(definition.spec, catalogData);
|
|
13856
|
+
}
|
|
13857
|
+
function buildZodType(schemaType, catalogData) {
|
|
13858
|
+
switch (schemaType.kind) {
|
|
13859
|
+
case "string":
|
|
13860
|
+
return string2();
|
|
13861
|
+
case "number":
|
|
13862
|
+
return number2();
|
|
13863
|
+
case "boolean":
|
|
13864
|
+
return boolean();
|
|
13865
|
+
case "any":
|
|
13866
|
+
return any();
|
|
13867
|
+
case "array": {
|
|
13868
|
+
const inner = buildZodType(schemaType.inner, catalogData);
|
|
13869
|
+
return array2(inner);
|
|
13870
|
+
}
|
|
13871
|
+
case "object": {
|
|
13872
|
+
const shape = schemaType.inner;
|
|
13873
|
+
const zodShape = {};
|
|
13874
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
13875
|
+
let zodType = buildZodType(value, catalogData);
|
|
13876
|
+
if (value.optional) {
|
|
13877
|
+
zodType = zodType.optional();
|
|
13878
|
+
}
|
|
13879
|
+
zodShape[key] = zodType;
|
|
13880
|
+
}
|
|
13881
|
+
return object2(zodShape);
|
|
13882
|
+
}
|
|
13883
|
+
case "record": {
|
|
13884
|
+
const inner = buildZodType(schemaType.inner, catalogData);
|
|
13885
|
+
return record2(string2(), inner);
|
|
13886
|
+
}
|
|
13887
|
+
case "ref": {
|
|
13888
|
+
const path = schemaType.inner;
|
|
13889
|
+
const keys = getKeysFromPath(path, catalogData);
|
|
13890
|
+
if (keys.length === 0) {
|
|
13891
|
+
return string2();
|
|
13892
|
+
}
|
|
13893
|
+
if (keys.length === 1) {
|
|
13894
|
+
return literal2(keys[0]);
|
|
13895
|
+
}
|
|
13896
|
+
return _enum2(keys);
|
|
13897
|
+
}
|
|
13898
|
+
case "propsOf": {
|
|
13899
|
+
const path = schemaType.inner;
|
|
13900
|
+
const propsSchemas = getPropsFromPath(path, catalogData);
|
|
13901
|
+
if (propsSchemas.length === 0) {
|
|
13902
|
+
return record2(string2(), unknown());
|
|
13903
|
+
}
|
|
13904
|
+
if (propsSchemas.length === 1) {
|
|
13905
|
+
return propsSchemas[0];
|
|
13906
|
+
}
|
|
13907
|
+
return record2(string2(), unknown());
|
|
13908
|
+
}
|
|
13909
|
+
default:
|
|
13910
|
+
return unknown();
|
|
13911
|
+
}
|
|
13912
|
+
}
|
|
13913
|
+
function getKeysFromPath(path, catalogData) {
|
|
13914
|
+
const parts = path.split(".");
|
|
13915
|
+
let current = { catalog: catalogData };
|
|
13916
|
+
for (const part of parts) {
|
|
13917
|
+
if (current && typeof current === "object") {
|
|
13918
|
+
current = current[part];
|
|
13919
|
+
} else {
|
|
13920
|
+
return [];
|
|
13921
|
+
}
|
|
13922
|
+
}
|
|
13923
|
+
if (current && typeof current === "object") {
|
|
13924
|
+
return Object.keys(current);
|
|
13925
|
+
}
|
|
13926
|
+
return [];
|
|
13927
|
+
}
|
|
13928
|
+
function getPropsFromPath(path, catalogData) {
|
|
13929
|
+
const parts = path.split(".");
|
|
13930
|
+
let current = { catalog: catalogData };
|
|
13931
|
+
for (const part of parts) {
|
|
13932
|
+
if (current && typeof current === "object") {
|
|
13933
|
+
current = current[part];
|
|
13934
|
+
} else {
|
|
13935
|
+
return [];
|
|
13936
|
+
}
|
|
13937
|
+
}
|
|
13938
|
+
if (current && typeof current === "object") {
|
|
13939
|
+
return Object.values(current).map((entry) => entry.props).filter((props) => props !== undefined);
|
|
13940
|
+
}
|
|
13941
|
+
return [];
|
|
13942
|
+
}
|
|
13943
|
+
function generatePrompt(catalog, options) {
|
|
13944
|
+
if (catalog.schema.promptTemplate) {
|
|
13945
|
+
const context = {
|
|
13946
|
+
catalog: catalog.data,
|
|
13947
|
+
componentNames: catalog.componentNames,
|
|
13948
|
+
actionNames: catalog.actionNames,
|
|
13949
|
+
options,
|
|
13950
|
+
formatZodType
|
|
13951
|
+
};
|
|
13952
|
+
return catalog.schema.promptTemplate(context);
|
|
13953
|
+
}
|
|
13954
|
+
const {
|
|
13955
|
+
system = "You are a UI generator that outputs JSON.",
|
|
13956
|
+
customRules = [],
|
|
13957
|
+
mode: rawMode = "standalone"
|
|
13958
|
+
} = options;
|
|
13959
|
+
const mode = rawMode === "chat" ? (console.warn('[json-render] mode "chat" is deprecated, use "inline" instead'), "inline") : rawMode === "generate" ? (console.warn('[json-render] mode "generate" is deprecated, use "standalone" instead'), "standalone") : rawMode;
|
|
13960
|
+
const lines = [];
|
|
13961
|
+
lines.push(system);
|
|
13962
|
+
lines.push("");
|
|
13963
|
+
if (mode === "inline") {
|
|
13964
|
+
lines.push("OUTPUT FORMAT (text + JSONL, RFC 6902 JSON Patch):");
|
|
13965
|
+
lines.push("You respond conversationally. When generating UI, first write a brief explanation (1-3 sentences), then output JSONL patch lines wrapped in a ```spec code fence.");
|
|
13966
|
+
lines.push("The JSONL lines use RFC 6902 JSON Patch operations to build a UI tree. Always wrap them in a ```spec fence block:");
|
|
13967
|
+
lines.push(" ```spec");
|
|
13968
|
+
lines.push(' {"op":"add","path":"/root","value":"main"}');
|
|
13969
|
+
lines.push(' {"op":"add","path":"/elements/main","value":{"type":"Card","props":{"title":"Hello"},"children":[]}}');
|
|
13970
|
+
lines.push(" ```");
|
|
13971
|
+
lines.push("If the user's message does not require a UI (e.g. a greeting or clarifying question), respond with text only — no JSONL.");
|
|
13972
|
+
} else {
|
|
13973
|
+
lines.push("OUTPUT FORMAT (JSONL, RFC 6902 JSON Patch):");
|
|
13974
|
+
lines.push("Output JSONL (one JSON object per line) using RFC 6902 JSON Patch operations to build a UI tree.");
|
|
13975
|
+
}
|
|
13976
|
+
lines.push("Each line is a JSON patch operation (add, remove, replace). Start with /root, then stream /elements and /state patches interleaved so the UI fills in progressively as it streams.");
|
|
13977
|
+
lines.push("");
|
|
13978
|
+
lines.push("Example output (each line is a separate JSON object):");
|
|
13979
|
+
lines.push("");
|
|
13980
|
+
const allComponents = catalog.data.components;
|
|
13981
|
+
const specDefinition = catalog.schema.definition.spec;
|
|
13982
|
+
const specShape = specDefinition.kind === "object" ? specDefinition.inner : undefined;
|
|
13983
|
+
const elementsDefinition = specShape?.elements;
|
|
13984
|
+
const elementDefinition = elementsDefinition?.kind === "record" ? elementsDefinition.inner : undefined;
|
|
13985
|
+
const elementShape = elementDefinition?.kind === "object" ? elementDefinition.inner : undefined;
|
|
13986
|
+
const supportsNamedSlots = elementShape?.slots !== undefined;
|
|
13987
|
+
const cn = catalog.componentNames;
|
|
13988
|
+
const comp1 = cn[0] || "Component";
|
|
13989
|
+
const comp2 = cn.length > 1 ? cn[1] : comp1;
|
|
13990
|
+
const comp1Def = allComponents?.[comp1];
|
|
13991
|
+
const comp2Def = allComponents?.[comp2];
|
|
13992
|
+
const comp1Props = comp1Def ? getExampleProps(comp1Def) : {};
|
|
13993
|
+
const comp2Props = comp2Def ? getExampleProps(comp2Def) : {};
|
|
13994
|
+
const dynamicPropName = comp2Def?.props ? findFirstStringProp(comp2Def.props) : null;
|
|
13995
|
+
const dynamicProps = dynamicPropName ? { ...comp2Props, [dynamicPropName]: { $item: "title" } } : comp2Props;
|
|
13996
|
+
const exampleOutput = [
|
|
13997
|
+
JSON.stringify({ op: "add", path: "/root", value: "main" }),
|
|
13998
|
+
JSON.stringify({
|
|
13999
|
+
op: "add",
|
|
14000
|
+
path: "/elements/main",
|
|
14001
|
+
value: {
|
|
14002
|
+
type: comp1,
|
|
14003
|
+
props: comp1Props,
|
|
14004
|
+
children: ["child-1", "list"]
|
|
14005
|
+
}
|
|
14006
|
+
}),
|
|
14007
|
+
JSON.stringify({
|
|
14008
|
+
op: "add",
|
|
14009
|
+
path: "/elements/child-1",
|
|
14010
|
+
value: { type: comp2, props: comp2Props, children: [] }
|
|
14011
|
+
}),
|
|
14012
|
+
JSON.stringify({
|
|
14013
|
+
op: "add",
|
|
14014
|
+
path: "/elements/list",
|
|
14015
|
+
value: {
|
|
14016
|
+
type: comp1,
|
|
14017
|
+
props: comp1Props,
|
|
14018
|
+
repeat: { statePath: "/items", key: "id" },
|
|
14019
|
+
children: ["item"]
|
|
14020
|
+
}
|
|
14021
|
+
}),
|
|
14022
|
+
JSON.stringify({
|
|
14023
|
+
op: "add",
|
|
14024
|
+
path: "/elements/item",
|
|
14025
|
+
value: { type: comp2, props: dynamicProps, children: [] }
|
|
14026
|
+
}),
|
|
14027
|
+
JSON.stringify({ op: "add", path: "/state/items", value: [] }),
|
|
14028
|
+
JSON.stringify({
|
|
14029
|
+
op: "add",
|
|
14030
|
+
path: "/state/items/0",
|
|
14031
|
+
value: { id: "1", title: "First Item" }
|
|
14032
|
+
}),
|
|
14033
|
+
JSON.stringify({
|
|
14034
|
+
op: "add",
|
|
14035
|
+
path: "/state/items/1",
|
|
14036
|
+
value: { id: "2", title: "Second Item" }
|
|
14037
|
+
})
|
|
14038
|
+
].join(`
|
|
14039
|
+
`);
|
|
14040
|
+
lines.push(`${exampleOutput}
|
|
14041
|
+
|
|
14042
|
+
Note: state patches appear right after the elements that use them, so the UI fills in as it streams. ONLY use component types from the AVAILABLE COMPONENTS list below.`);
|
|
14043
|
+
lines.push("");
|
|
14044
|
+
lines.push("INITIAL STATE:");
|
|
14045
|
+
lines.push("Specs include a /state field to seed the state model. Components with { $bindState } or { $bindItem } read from and write to this state, and $state expressions read from it.");
|
|
14046
|
+
lines.push("CRITICAL: You MUST include state patches whenever your UI displays data via $state, $bindState, $bindItem, $item, or $index expressions, or uses repeat to iterate over arrays. Without state, these references resolve to nothing and repeat lists render zero items.");
|
|
14047
|
+
lines.push("Output state patches right after the elements that reference them, so the UI fills in progressively as it streams.");
|
|
14048
|
+
lines.push("Stream state progressively - output one patch per array item instead of one giant blob:");
|
|
14049
|
+
lines.push(' For arrays: {"op":"add","path":"/state/posts/0","value":{"id":"1","title":"First Post",...}} then /state/posts/1, /state/posts/2, etc.');
|
|
14050
|
+
lines.push(' For scalars: {"op":"add","path":"/state/newTodoText","value":""}');
|
|
14051
|
+
lines.push(' Initialize the array first if needed: {"op":"add","path":"/state/posts","value":[]}');
|
|
14052
|
+
lines.push('When content comes from the state model, use { "$state": "/some/path" } dynamic props to display it instead of hardcoding the same value in both state and props. The state model is the single source of truth.');
|
|
14053
|
+
lines.push("Include realistic sample data in state. For blogs: 3-4 posts with titles, excerpts, authors, dates. For product lists: 3-5 items with names, prices, descriptions. Never leave arrays empty.");
|
|
14054
|
+
lines.push("");
|
|
14055
|
+
lines.push("DYNAMIC LISTS (repeat field):");
|
|
14056
|
+
lines.push('Any element can have a top-level "repeat" field to render its children once per item in a state array: { "repeat": { "statePath": "/arrayPath", "key": "id" } }.');
|
|
14057
|
+
lines.push('The element itself renders once (as the container), and its children are expanded once per array item. "statePath" is the state array path. "key" is an optional field name on each item for stable React keys.');
|
|
14058
|
+
lines.push('For nested lists, an inner repeat can read an array from the enclosing item with { "statePath": { "$item": "field" } }. This form is valid only inside another repeat. Use an empty field to repeat over the enclosing item itself.');
|
|
14059
|
+
lines.push(`Example: ${JSON.stringify({ type: comp1, props: comp1Props, repeat: { statePath: "/todos", key: "id" }, children: ["todo-item"] })}`);
|
|
14060
|
+
lines.push('Inside children of a repeated element, use { "$item": "field" } to read a field from the current item, and { "$index": true } to get the current array index. For two-way binding to an item field use { "$bindItem": "completed" } on the appropriate prop.');
|
|
14061
|
+
lines.push("ALWAYS use the repeat field for lists backed by state arrays. NEVER hardcode individual elements for each array item.");
|
|
14062
|
+
lines.push('IMPORTANT: "repeat" is a top-level field on the element (sibling of type/props/children), NOT inside props.');
|
|
14063
|
+
lines.push("");
|
|
14064
|
+
lines.push("ARRAY STATE ACTIONS:");
|
|
14065
|
+
lines.push('Use action "pushState" to append items to arrays. Params: { statePath: "/arrayPath", value: { ...item }, clearStatePath: "/inputPath" }.');
|
|
14066
|
+
lines.push('Values inside pushState can contain { "$state": "/statePath" } references to read current state (e.g. the text from an input field).');
|
|
14067
|
+
lines.push('Use "$id" inside a pushState value to auto-generate a unique ID.');
|
|
14068
|
+
lines.push('Example: on: { "press": { "action": "pushState", "params": { "statePath": "/todos", "value": { "id": "$id", "title": { "$state": "/newTodoText" }, "completed": false }, "clearStatePath": "/newTodoText" } } }');
|
|
14069
|
+
lines.push(`Use action "removeState" to remove items from arrays by index. Params: { statePath: "/arrayPath", index: N }. Inside a repeated element's children, use { "$index": true } for the current item index. Action params support the same expressions as props: { "$item": "field" } resolves to the absolute state path, { "$index": true } resolves to the index number, and { "$state": "/path" } reads a value from state.`);
|
|
14070
|
+
lines.push("For lists where users can add/remove items (todos, carts, etc.), use pushState and removeState instead of hardcoding with setState.");
|
|
14071
|
+
lines.push("");
|
|
14072
|
+
lines.push('IMPORTANT: State paths use RFC 6901 JSON Pointer syntax (e.g. "/todos/0/title"). Do NOT use JavaScript-style dot notation (e.g. "/todos.length" is WRONG). To generate unique IDs for new items, use "$id" instead of trying to read array length.');
|
|
14073
|
+
lines.push("");
|
|
14074
|
+
const components = allComponents;
|
|
14075
|
+
if (components) {
|
|
14076
|
+
lines.push(`AVAILABLE COMPONENTS (${catalog.componentNames.length}):`);
|
|
14077
|
+
lines.push("");
|
|
14078
|
+
for (const [name, def] of Object.entries(components)) {
|
|
14079
|
+
const propsStr = def.props ? formatZodType(def.props) : "{}";
|
|
14080
|
+
const slotNames = def.slots ?? [];
|
|
14081
|
+
const namedSlotNames = slotNames.filter((slot) => slot !== "default");
|
|
14082
|
+
const acceptsChildren = slotNames.includes("default");
|
|
14083
|
+
const slotsStr = supportsNamedSlots ? [
|
|
14084
|
+
acceptsChildren ? "accepts children" : "",
|
|
14085
|
+
namedSlotNames.length > 0 ? `slots: ${namedSlotNames.join(", ")}` : ""
|
|
14086
|
+
].filter(Boolean).join("; ") : slotNames.length > 0 ? "accepts children" : "";
|
|
14087
|
+
const slotsSuffix = slotsStr ? ` [${slotsStr}]` : "";
|
|
14088
|
+
const eventsStr = def.events && def.events.length > 0 ? ` [events: ${def.events.join(", ")}]` : "";
|
|
14089
|
+
const descStr = def.description ? ` - ${def.description}` : "";
|
|
14090
|
+
lines.push(`- ${name}: ${propsStr}${descStr}${slotsSuffix}${eventsStr}`);
|
|
14091
|
+
}
|
|
14092
|
+
lines.push("");
|
|
14093
|
+
}
|
|
14094
|
+
const actions = catalog.data.actions;
|
|
14095
|
+
const builtInActions = catalog.schema.builtInActions ?? [];
|
|
14096
|
+
const hasCustomActions = actions && catalog.actionNames.length > 0;
|
|
14097
|
+
const hasBuiltInActions = builtInActions.length > 0;
|
|
14098
|
+
if (hasCustomActions || hasBuiltInActions) {
|
|
14099
|
+
lines.push("AVAILABLE ACTIONS:");
|
|
14100
|
+
lines.push("");
|
|
14101
|
+
for (const action2 of builtInActions) {
|
|
14102
|
+
lines.push(`- ${action2.name}: ${action2.description} [built-in]`);
|
|
14103
|
+
}
|
|
14104
|
+
if (hasCustomActions) {
|
|
14105
|
+
for (const [name, def] of Object.entries(actions)) {
|
|
14106
|
+
lines.push(`- ${name}${def.description ? `: ${def.description}` : ""}`);
|
|
14107
|
+
}
|
|
14108
|
+
}
|
|
14109
|
+
lines.push("");
|
|
14110
|
+
}
|
|
14111
|
+
lines.push("EVENTS (the `on` field):");
|
|
14112
|
+
lines.push("Elements can have an optional `on` field to bind events to actions. The `on` field is a top-level field on the element (sibling of type/props/children), NOT inside props.");
|
|
14113
|
+
lines.push('Each key in `on` is an event name (from the component\'s supported events), and the value is an action binding: `{ "action": "<actionName>", "params": { ... } }`.');
|
|
14114
|
+
lines.push("");
|
|
14115
|
+
lines.push("Example:");
|
|
14116
|
+
lines.push(` ${JSON.stringify({ type: comp1, props: comp1Props, on: { press: { action: "setState", params: { statePath: "/saved", value: true } } }, children: [] })}`);
|
|
14117
|
+
lines.push("");
|
|
14118
|
+
lines.push('Action params can use dynamic references to read from state: { "$state": "/statePath" }.');
|
|
14119
|
+
lines.push("IMPORTANT: Do NOT put action/actionParams inside props. Always use the `on` field for event bindings.");
|
|
14120
|
+
lines.push("");
|
|
14121
|
+
lines.push("VISIBILITY CONDITIONS:");
|
|
14122
|
+
lines.push("Elements can have an optional `visible` field to conditionally show/hide based on state. IMPORTANT: `visible` is a top-level field on the element object (sibling of type/props/children), NOT inside props.");
|
|
14123
|
+
lines.push(`Correct: ${JSON.stringify({ type: comp1, props: comp1Props, visible: { $state: "/activeTab", eq: "home" }, children: ["..."] })}`);
|
|
14124
|
+
lines.push('- `{ "$state": "/path" }` - visible when state at path is truthy');
|
|
14125
|
+
lines.push('- `{ "$state": "/path", "not": true }` - visible when state at path is falsy');
|
|
14126
|
+
lines.push('- `{ "$state": "/path", "eq": "value" }` - visible when state equals value');
|
|
14127
|
+
lines.push('- `{ "$state": "/path", "neq": "value" }` - visible when state does not equal value');
|
|
14128
|
+
lines.push('- `{ "$state": "/path", "gt": N }` / `gte` / `lt` / `lte` - numeric comparisons');
|
|
14129
|
+
lines.push("- Use ONE operator per condition (eq, neq, gt, gte, lt, lte). Do not combine multiple operators.");
|
|
14130
|
+
lines.push('- Any condition can add `"not": true` to invert its result');
|
|
14131
|
+
lines.push("- `[condition, condition]` - all conditions must be true (implicit AND)");
|
|
14132
|
+
lines.push('- `{ "$and": [condition, condition] }` - explicit AND (use when nesting inside $or)');
|
|
14133
|
+
lines.push('- `{ "$or": [condition, condition] }` - at least one must be true (OR)');
|
|
14134
|
+
lines.push("- `true` / `false` - always visible/hidden");
|
|
14135
|
+
lines.push("");
|
|
14136
|
+
lines.push("Use a component with on.press bound to setState to update state and drive visibility.");
|
|
14137
|
+
lines.push(`Example: A ${comp1} with on: { "press": { "action": "setState", "params": { "statePath": "/activeTab", "value": "home" } } } sets state, then a container with visible: { "$state": "/activeTab", "eq": "home" } shows only when that tab is active.`);
|
|
14138
|
+
lines.push("");
|
|
14139
|
+
lines.push('For tab patterns where the first/default tab should be visible when no tab is selected yet, use $or to handle both cases: visible: { "$or": [{ "$state": "/activeTab", "eq": "home" }, { "$state": "/activeTab", "not": true }] }. This ensures the first tab is visible both when explicitly selected AND when /activeTab is not yet set.');
|
|
14140
|
+
lines.push("");
|
|
14141
|
+
lines.push("DYNAMIC PROPS:");
|
|
14142
|
+
lines.push("Any prop value can be a dynamic expression that resolves based on state. Three forms are supported:");
|
|
14143
|
+
lines.push("");
|
|
14144
|
+
lines.push('1. Read-only state: `{ "$state": "/statePath" }` - resolves to the value at that state path (one-way read).');
|
|
14145
|
+
lines.push(' Example: `"color": { "$state": "/theme/primary" }` reads the color from state.');
|
|
14146
|
+
lines.push("");
|
|
14147
|
+
lines.push('2. Two-way binding: `{ "$bindState": "/statePath" }` - resolves to the value at the state path AND enables write-back. Use on form input props (value, checked, pressed, etc.).');
|
|
14148
|
+
lines.push(' Example: `"value": { "$bindState": "/form/email" }` binds the input value to /form/email.');
|
|
14149
|
+
lines.push(' Inside repeat scopes: `"checked": { "$bindItem": "completed" }` binds to the current item\'s completed field.');
|
|
14150
|
+
lines.push("");
|
|
14151
|
+
lines.push('3. Conditional: `{ "$cond": <condition>, "$then": <value>, "$else": <value> }` - evaluates the condition (same syntax as visibility conditions) and picks the matching value.');
|
|
14152
|
+
lines.push(' Example: `"color": { "$cond": { "$state": "/activeTab", "eq": "home" }, "$then": "#007AFF", "$else": "#8E8E93" }`');
|
|
14153
|
+
lines.push("");
|
|
14154
|
+
lines.push("Use $bindState for form inputs (text fields, checkboxes, selects, sliders, etc.) and $state for read-only data display. Inside repeat scopes, use $bindItem for form inputs bound to the current item. Use dynamic props instead of duplicating elements with opposing visible conditions when only prop values differ.");
|
|
14155
|
+
lines.push("");
|
|
14156
|
+
lines.push('4. Template: `{ "$template": "Hello, ${/name}!" }` - interpolates references in the string. Absolute paths like `${/path}` resolve against the state model. Bare names like `${field}` resolve against the current repeat item first, then fall back to the state model at `/<field>`.');
|
|
14157
|
+
lines.push(' Example: `"label": { "$template": "Items: ${/cart/count} | Total: ${/cart/total}" }` renders "Items: 3 | Total: 42.00" when /cart/count is 3 and /cart/total is 42.00. Inside a repeat, `{ "$template": "${name} - ${email}" }` reads name and email from each item.');
|
|
14158
|
+
lines.push("");
|
|
14159
|
+
const catalogFunctions = catalog.data.functions;
|
|
14160
|
+
if (catalogFunctions && Object.keys(catalogFunctions).length > 0) {
|
|
14161
|
+
lines.push('5. Computed: `{ "$computed": "<functionName>", "args": { "key": <expression> } }` - calls a registered function with resolved args and returns the result.');
|
|
14162
|
+
lines.push(' Example: `"value": { "$computed": "fullName", "args": { "first": { "$state": "/form/firstName" }, "last": { "$state": "/form/lastName" } } }`');
|
|
14163
|
+
lines.push(" Available functions:");
|
|
14164
|
+
for (const name of Object.keys(catalogFunctions)) {
|
|
14165
|
+
lines.push(` - ${name}`);
|
|
14166
|
+
}
|
|
14167
|
+
lines.push("");
|
|
14168
|
+
}
|
|
14169
|
+
const directives = options.directives;
|
|
14170
|
+
if (directives && directives.length > 0) {
|
|
14171
|
+
lines.push("CUSTOM DYNAMIC VALUES:");
|
|
14172
|
+
lines.push("");
|
|
14173
|
+
for (const d of directives) {
|
|
14174
|
+
const desc = d.description ? ` (${d.description})` : "";
|
|
14175
|
+
lines.push(`- ${d.name}${desc}: ${formatZodType(d.schema)}`);
|
|
14176
|
+
}
|
|
14177
|
+
lines.push("");
|
|
14178
|
+
lines.push("Directives compose: any value field can contain another directive or a $state expression, resolved inside-out.");
|
|
14179
|
+
lines.push("");
|
|
14180
|
+
}
|
|
14181
|
+
const hasChecksComponents = allComponents ? Object.entries(allComponents).some(([, def]) => {
|
|
14182
|
+
if (!def.props)
|
|
14183
|
+
return false;
|
|
14184
|
+
const formatted = formatZodType(def.props);
|
|
14185
|
+
return formatted.includes("checks");
|
|
14186
|
+
}) : false;
|
|
14187
|
+
if (hasChecksComponents) {
|
|
14188
|
+
lines.push("VALIDATION:");
|
|
14189
|
+
lines.push("Form components that accept a `checks` prop support client-side validation.");
|
|
14190
|
+
lines.push('Each check is an object: { "type": "<name>", "message": "...", "args": { ... } }');
|
|
14191
|
+
lines.push("");
|
|
14192
|
+
lines.push("Built-in validation types:");
|
|
14193
|
+
lines.push(" - required — value must be non-empty");
|
|
14194
|
+
lines.push(" - email — valid email format");
|
|
14195
|
+
lines.push(' - minLength — minimum string length (args: { "min": N })');
|
|
14196
|
+
lines.push(' - maxLength — maximum string length (args: { "max": N })');
|
|
14197
|
+
lines.push(' - pattern — match a regex (args: { "pattern": "regex" })');
|
|
14198
|
+
lines.push(' - min — minimum numeric value (args: { "min": N })');
|
|
14199
|
+
lines.push(' - max — maximum numeric value (args: { "max": N })');
|
|
14200
|
+
lines.push(" - numeric — value must be a number");
|
|
14201
|
+
lines.push(" - url — valid URL format");
|
|
14202
|
+
lines.push(' - matches — must equal another field (args: { "other": { "$state": "/path" } })');
|
|
14203
|
+
lines.push(' - equalTo — alias for matches (args: { "other": { "$state": "/path" } })');
|
|
14204
|
+
lines.push(' - lessThan — value must be less than another field (args: { "other": { "$state": "/path" } })');
|
|
14205
|
+
lines.push(' - greaterThan — value must be greater than another field (args: { "other": { "$state": "/path" } })');
|
|
14206
|
+
lines.push(' - requiredIf — required only when another field is truthy (args: { "field": { "$state": "/path" } })');
|
|
14207
|
+
lines.push("");
|
|
14208
|
+
lines.push("Example:");
|
|
14209
|
+
lines.push(' "checks": [{ "type": "required", "message": "Email is required" }, { "type": "email", "message": "Invalid email" }]');
|
|
14210
|
+
lines.push("");
|
|
14211
|
+
lines.push("IMPORTANT: When using checks, the component must also have a { $bindState } or { $bindItem } on its value/checked prop for two-way binding.");
|
|
14212
|
+
lines.push("Always include validation checks on form inputs for a good user experience (e.g. required, email, minLength).");
|
|
14213
|
+
lines.push("");
|
|
14214
|
+
}
|
|
14215
|
+
if (hasCustomActions || hasBuiltInActions) {
|
|
14216
|
+
lines.push("STATE WATCHERS:");
|
|
14217
|
+
lines.push("Elements can have an optional `watch` field to react to state changes and trigger actions. The `watch` field is a top-level field on the element (sibling of type/props/children), NOT inside props.");
|
|
14218
|
+
lines.push("Maps state paths (JSON Pointers) to action bindings. When the value at a watched path changes, the bound actions fire automatically.");
|
|
14219
|
+
lines.push("");
|
|
14220
|
+
lines.push("Example (cascading select — country changes trigger city loading):");
|
|
14221
|
+
lines.push(` ${JSON.stringify({ type: "Select", props: { value: { $bindState: "/form/country" }, options: ["US", "Canada", "UK"] }, watch: { "/form/country": { action: "loadCities", params: { country: { $state: "/form/country" } } } }, children: [] })}`);
|
|
14222
|
+
lines.push("");
|
|
14223
|
+
lines.push("Use `watch` for cascading dependencies where changing one field should trigger side effects (loading data, resetting dependent fields, computing derived values).");
|
|
14224
|
+
lines.push("IMPORTANT: `watch` is a top-level field on the element (sibling of type/props/children), NOT inside props. Watchers only fire when the value changes, not on initial render.");
|
|
14225
|
+
lines.push("");
|
|
14226
|
+
}
|
|
14227
|
+
const editModes = options.editModes;
|
|
14228
|
+
if (editModes && editModes.length > 0) {
|
|
14229
|
+
lines.push(buildEditInstructions({ modes: editModes }, "json"));
|
|
14230
|
+
}
|
|
14231
|
+
lines.push("RULES:");
|
|
14232
|
+
const baseRules = mode === "inline" ? [
|
|
14233
|
+
"When generating UI, wrap all JSONL patches in a ```spec code fence - one JSON object per line inside the fence",
|
|
14234
|
+
"Write a brief conversational response before any JSONL output",
|
|
14235
|
+
'First set root: {"op":"add","path":"/root","value":"<root-key>"}',
|
|
14236
|
+
'Then add each element: {"op":"add","path":"/elements/<key>","value":{...}}',
|
|
14237
|
+
"Output /state patches right after the elements that use them, one per array item for progressive loading. REQUIRED whenever using $state, $bindState, $bindItem, $item, $index, or repeat.",
|
|
14238
|
+
"ONLY use components listed above",
|
|
14239
|
+
"Each element value needs: type, props, children (array of child keys)",
|
|
14240
|
+
"Use unique keys for the element map entries (e.g., 'header', 'metric-1', 'chart-revenue')"
|
|
14241
|
+
] : [
|
|
14242
|
+
"Output ONLY JSONL patches - one JSON object per line, no markdown, no code fences",
|
|
14243
|
+
'First set root: {"op":"add","path":"/root","value":"<root-key>"}',
|
|
14244
|
+
'Then add each element: {"op":"add","path":"/elements/<key>","value":{...}}',
|
|
14245
|
+
"Output /state patches right after the elements that use them, one per array item for progressive loading. REQUIRED whenever using $state, $bindState, $bindItem, $item, $index, or repeat.",
|
|
14246
|
+
"ONLY use components listed above",
|
|
14247
|
+
"Each element value needs: type, props, children (array of child keys)",
|
|
14248
|
+
"Use unique keys for the element map entries (e.g., 'header', 'metric-1', 'chart-revenue')"
|
|
14249
|
+
];
|
|
14250
|
+
const schemaRules = catalog.schema.defaultRules ?? [];
|
|
14251
|
+
const allRules = [...baseRules, ...schemaRules, ...customRules];
|
|
14252
|
+
allRules.forEach((rule, i) => {
|
|
14253
|
+
lines.push(`${i + 1}. ${rule}`);
|
|
14254
|
+
});
|
|
14255
|
+
return lines.join(`
|
|
14256
|
+
`);
|
|
14257
|
+
}
|
|
14258
|
+
function getExampleProps(def) {
|
|
14259
|
+
if (def.example && Object.keys(def.example).length > 0) {
|
|
14260
|
+
return def.example;
|
|
14261
|
+
}
|
|
14262
|
+
if (def.props) {
|
|
14263
|
+
return generateExamplePropsFromZod(def.props);
|
|
14264
|
+
}
|
|
14265
|
+
return {};
|
|
14266
|
+
}
|
|
14267
|
+
function generateExamplePropsFromZod(schema) {
|
|
14268
|
+
if (!schema || !schema._def)
|
|
14269
|
+
return {};
|
|
14270
|
+
const def = schema._def;
|
|
14271
|
+
const typeName = getZodTypeName(schema);
|
|
14272
|
+
if (typeName !== "ZodObject" && typeName !== "object")
|
|
14273
|
+
return {};
|
|
14274
|
+
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
14275
|
+
if (!shape)
|
|
14276
|
+
return {};
|
|
14277
|
+
const result = {};
|
|
14278
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
14279
|
+
const innerTypeName = getZodTypeName(value);
|
|
14280
|
+
if (innerTypeName === "ZodOptional" || innerTypeName === "optional" || innerTypeName === "ZodNullable" || innerTypeName === "nullable") {
|
|
14281
|
+
continue;
|
|
14282
|
+
}
|
|
14283
|
+
result[key] = generateExampleValue(value);
|
|
14284
|
+
}
|
|
14285
|
+
return result;
|
|
14286
|
+
}
|
|
14287
|
+
function generateExampleValue(schema) {
|
|
14288
|
+
if (!schema || !schema._def)
|
|
14289
|
+
return "...";
|
|
14290
|
+
const def = schema._def;
|
|
14291
|
+
const typeName = getZodTypeName(schema);
|
|
14292
|
+
switch (typeName) {
|
|
14293
|
+
case "ZodString":
|
|
14294
|
+
case "string":
|
|
14295
|
+
return "example";
|
|
14296
|
+
case "ZodNumber":
|
|
14297
|
+
case "number":
|
|
14298
|
+
return 0;
|
|
14299
|
+
case "ZodBoolean":
|
|
14300
|
+
case "boolean":
|
|
14301
|
+
return true;
|
|
14302
|
+
case "ZodLiteral":
|
|
14303
|
+
case "literal":
|
|
14304
|
+
return def.value;
|
|
14305
|
+
case "ZodEnum":
|
|
14306
|
+
case "enum": {
|
|
14307
|
+
if (Array.isArray(def.values) && def.values.length > 0)
|
|
14308
|
+
return def.values[0];
|
|
14309
|
+
if (def.entries && typeof def.entries === "object") {
|
|
14310
|
+
const values = Object.values(def.entries);
|
|
14311
|
+
return values.length > 0 ? values[0] : "example";
|
|
14312
|
+
}
|
|
14313
|
+
return "example";
|
|
14314
|
+
}
|
|
14315
|
+
case "ZodOptional":
|
|
14316
|
+
case "optional":
|
|
14317
|
+
case "ZodNullable":
|
|
14318
|
+
case "nullable":
|
|
14319
|
+
case "ZodDefault":
|
|
14320
|
+
case "default": {
|
|
14321
|
+
const inner = def.innerType ?? def.wrapped;
|
|
14322
|
+
return inner ? generateExampleValue(inner) : null;
|
|
14323
|
+
}
|
|
14324
|
+
case "ZodArray":
|
|
14325
|
+
case "array":
|
|
14326
|
+
return [];
|
|
14327
|
+
case "ZodObject":
|
|
14328
|
+
case "object":
|
|
14329
|
+
return generateExamplePropsFromZod(schema);
|
|
14330
|
+
case "ZodUnion":
|
|
14331
|
+
case "union": {
|
|
14332
|
+
const options = def.options;
|
|
14333
|
+
return options && options.length > 0 ? generateExampleValue(options[0]) : "...";
|
|
14334
|
+
}
|
|
14335
|
+
default:
|
|
14336
|
+
return "...";
|
|
14337
|
+
}
|
|
14338
|
+
}
|
|
14339
|
+
function findFirstStringProp(schema) {
|
|
14340
|
+
if (!schema || !schema._def)
|
|
14341
|
+
return null;
|
|
14342
|
+
const def = schema._def;
|
|
14343
|
+
const typeName = getZodTypeName(schema);
|
|
14344
|
+
if (typeName !== "ZodObject" && typeName !== "object")
|
|
14345
|
+
return null;
|
|
14346
|
+
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
14347
|
+
if (!shape)
|
|
14348
|
+
return null;
|
|
14349
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
14350
|
+
const innerTypeName = getZodTypeName(value);
|
|
14351
|
+
if (innerTypeName === "ZodOptional" || innerTypeName === "optional" || innerTypeName === "ZodNullable" || innerTypeName === "nullable") {
|
|
14352
|
+
continue;
|
|
14353
|
+
}
|
|
14354
|
+
if (innerTypeName === "ZodString" || innerTypeName === "string") {
|
|
14355
|
+
return key;
|
|
14356
|
+
}
|
|
14357
|
+
}
|
|
14358
|
+
return null;
|
|
14359
|
+
}
|
|
14360
|
+
function getZodTypeName(schema) {
|
|
14361
|
+
if (!schema || !schema._def)
|
|
14362
|
+
return "";
|
|
14363
|
+
const def = schema._def;
|
|
14364
|
+
return def.typeName ?? def.type ?? "";
|
|
14365
|
+
}
|
|
14366
|
+
function formatZodType(schema) {
|
|
14367
|
+
if (!schema || !schema._def)
|
|
14368
|
+
return "unknown";
|
|
14369
|
+
const def = schema._def;
|
|
14370
|
+
const typeName = getZodTypeName(schema);
|
|
14371
|
+
switch (typeName) {
|
|
14372
|
+
case "ZodString":
|
|
14373
|
+
case "string":
|
|
14374
|
+
return "string";
|
|
14375
|
+
case "ZodNumber":
|
|
14376
|
+
case "number":
|
|
14377
|
+
return "number";
|
|
14378
|
+
case "ZodBoolean":
|
|
14379
|
+
case "boolean":
|
|
14380
|
+
return "boolean";
|
|
14381
|
+
case "ZodLiteral":
|
|
14382
|
+
case "literal": {
|
|
14383
|
+
const litValues = def.values;
|
|
14384
|
+
const litValue = litValues?.[0] ?? def.value;
|
|
14385
|
+
return JSON.stringify(litValue);
|
|
14386
|
+
}
|
|
14387
|
+
case "ZodEnum":
|
|
14388
|
+
case "enum": {
|
|
14389
|
+
let values;
|
|
14390
|
+
if (Array.isArray(def.values)) {
|
|
14391
|
+
values = def.values;
|
|
14392
|
+
} else if (def.entries && typeof def.entries === "object") {
|
|
14393
|
+
values = Object.values(def.entries);
|
|
14394
|
+
} else {
|
|
14395
|
+
return "enum";
|
|
14396
|
+
}
|
|
14397
|
+
return values.map((v) => `"${v}"`).join(" | ");
|
|
14398
|
+
}
|
|
14399
|
+
case "ZodArray":
|
|
14400
|
+
case "array": {
|
|
14401
|
+
const inner = typeof def.element === "object" ? def.element : typeof def.type === "object" ? def.type : undefined;
|
|
14402
|
+
return inner ? `Array<${formatZodType(inner)}>` : "Array<unknown>";
|
|
14403
|
+
}
|
|
14404
|
+
case "ZodObject":
|
|
14405
|
+
case "object": {
|
|
14406
|
+
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
14407
|
+
if (!shape)
|
|
14408
|
+
return "object";
|
|
14409
|
+
const props = Object.entries(shape).map(([key, value]) => {
|
|
14410
|
+
const innerTypeName = getZodTypeName(value);
|
|
14411
|
+
const isOptional = innerTypeName === "ZodOptional" || innerTypeName === "ZodNullable" || innerTypeName === "optional" || innerTypeName === "nullable";
|
|
14412
|
+
return `${key}${isOptional ? "?" : ""}: ${formatZodType(value)}`;
|
|
14413
|
+
}).join(", ");
|
|
14414
|
+
return `{ ${props} }`;
|
|
14415
|
+
}
|
|
14416
|
+
case "ZodOptional":
|
|
14417
|
+
case "optional":
|
|
14418
|
+
case "ZodNullable":
|
|
14419
|
+
case "nullable": {
|
|
14420
|
+
const inner = def.innerType ?? def.wrapped;
|
|
14421
|
+
return inner ? formatZodType(inner) : "unknown";
|
|
14422
|
+
}
|
|
14423
|
+
case "ZodUnion":
|
|
14424
|
+
case "union": {
|
|
14425
|
+
const options = def.options;
|
|
14426
|
+
return options ? options.map((opt) => formatZodType(opt)).join(" | ") : "unknown";
|
|
14427
|
+
}
|
|
14428
|
+
case "ZodRecord":
|
|
14429
|
+
case "record": {
|
|
14430
|
+
const keyType = def.keyType ?? undefined;
|
|
14431
|
+
const valueType = def.valueType ?? def.element ?? undefined;
|
|
14432
|
+
const keyStr = keyType ? formatZodType(keyType) : "string";
|
|
14433
|
+
const valueStr = valueType ? formatZodType(valueType) : "unknown";
|
|
14434
|
+
return `Record<${keyStr}, ${valueStr}>`;
|
|
14435
|
+
}
|
|
14436
|
+
case "ZodDefault":
|
|
14437
|
+
case "default": {
|
|
14438
|
+
const inner = def.innerType ?? def.wrapped;
|
|
14439
|
+
return inner ? formatZodType(inner) : "unknown";
|
|
14440
|
+
}
|
|
14441
|
+
default:
|
|
14442
|
+
return "unknown";
|
|
14443
|
+
}
|
|
14444
|
+
}
|
|
14445
|
+
function zodTypeName(def) {
|
|
14446
|
+
if (typeof def.type === "string")
|
|
14447
|
+
return def.type;
|
|
14448
|
+
if (typeof def.typeName === "string")
|
|
14449
|
+
return def.typeName;
|
|
14450
|
+
return "";
|
|
14451
|
+
}
|
|
14452
|
+
function normalizeTypeName(raw) {
|
|
14453
|
+
if (raw.startsWith("Zod")) {
|
|
14454
|
+
return raw.slice(3).toLowerCase();
|
|
14455
|
+
}
|
|
14456
|
+
return raw.toLowerCase();
|
|
14457
|
+
}
|
|
14458
|
+
function zodToJsonSchema(schema, strict = false) {
|
|
14459
|
+
const def = schema._def;
|
|
14460
|
+
const kind = normalizeTypeName(zodTypeName(def));
|
|
14461
|
+
switch (kind) {
|
|
14462
|
+
case "string":
|
|
14463
|
+
return { type: "string" };
|
|
14464
|
+
case "number":
|
|
14465
|
+
return { type: "number" };
|
|
14466
|
+
case "boolean":
|
|
14467
|
+
return { type: "boolean" };
|
|
14468
|
+
case "literal": {
|
|
14469
|
+
const values = def.values;
|
|
14470
|
+
const value = values ? values[0] : def.value;
|
|
14471
|
+
return { const: value };
|
|
14472
|
+
}
|
|
14473
|
+
case "enum": {
|
|
14474
|
+
const entries = def.entries;
|
|
14475
|
+
const values = entries ? Object.values(entries) : def.values;
|
|
14476
|
+
return { enum: values ?? [] };
|
|
14477
|
+
}
|
|
14478
|
+
case "array": {
|
|
14479
|
+
const inner = def.element ?? def.type;
|
|
14480
|
+
return {
|
|
14481
|
+
type: "array",
|
|
14482
|
+
items: inner ? zodToJsonSchema(inner, strict) : {}
|
|
14483
|
+
};
|
|
14484
|
+
}
|
|
14485
|
+
case "object": {
|
|
14486
|
+
const rawShape = def.shape;
|
|
14487
|
+
const shape = typeof rawShape === "function" ? rawShape() : rawShape;
|
|
14488
|
+
if (!shape) {
|
|
14489
|
+
if (strict) {
|
|
14490
|
+
return {
|
|
14491
|
+
type: "object",
|
|
14492
|
+
properties: {},
|
|
14493
|
+
required: [],
|
|
14494
|
+
additionalProperties: false
|
|
14495
|
+
};
|
|
14496
|
+
}
|
|
14497
|
+
return { type: "object" };
|
|
14498
|
+
}
|
|
14499
|
+
const properties = {};
|
|
14500
|
+
const required = [];
|
|
14501
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
14502
|
+
const innerDef = value._def;
|
|
14503
|
+
const innerKind = normalizeTypeName(zodTypeName(innerDef));
|
|
14504
|
+
const isOptional = innerKind === "optional" || innerKind === "nullable";
|
|
14505
|
+
if (strict) {
|
|
14506
|
+
required.push(key);
|
|
14507
|
+
if (isOptional) {
|
|
14508
|
+
const unwrapped = zodToJsonSchema(value, strict);
|
|
14509
|
+
properties[key] = { anyOf: [unwrapped, { type: "null" }] };
|
|
14510
|
+
} else {
|
|
14511
|
+
properties[key] = zodToJsonSchema(value, strict);
|
|
14512
|
+
}
|
|
14513
|
+
} else {
|
|
14514
|
+
properties[key] = zodToJsonSchema(value);
|
|
14515
|
+
if (!isOptional) {
|
|
14516
|
+
required.push(key);
|
|
14517
|
+
}
|
|
14518
|
+
}
|
|
14519
|
+
}
|
|
14520
|
+
return {
|
|
14521
|
+
type: "object",
|
|
14522
|
+
properties,
|
|
14523
|
+
required: required.length > 0 ? required : undefined,
|
|
14524
|
+
additionalProperties: false
|
|
14525
|
+
};
|
|
14526
|
+
}
|
|
14527
|
+
case "record": {
|
|
14528
|
+
const valueType = def.valueType;
|
|
14529
|
+
if (strict) {
|
|
14530
|
+
return {
|
|
14531
|
+
type: "object",
|
|
14532
|
+
properties: {},
|
|
14533
|
+
required: [],
|
|
14534
|
+
additionalProperties: false
|
|
14535
|
+
};
|
|
14536
|
+
}
|
|
14537
|
+
return {
|
|
14538
|
+
type: "object",
|
|
14539
|
+
additionalProperties: valueType ? zodToJsonSchema(valueType) : true
|
|
14540
|
+
};
|
|
14541
|
+
}
|
|
14542
|
+
case "optional":
|
|
14543
|
+
case "nullable": {
|
|
14544
|
+
const inner = def.innerType;
|
|
14545
|
+
return inner ? zodToJsonSchema(inner, strict) : {};
|
|
14546
|
+
}
|
|
14547
|
+
case "union": {
|
|
14548
|
+
const options = def.options;
|
|
14549
|
+
return options ? { anyOf: options.map((o) => zodToJsonSchema(o, strict)) } : {};
|
|
14550
|
+
}
|
|
14551
|
+
case "any":
|
|
14552
|
+
case "unknown":
|
|
14553
|
+
if (strict) {
|
|
14554
|
+
return {
|
|
14555
|
+
type: "object",
|
|
14556
|
+
properties: {},
|
|
14557
|
+
required: [],
|
|
14558
|
+
additionalProperties: false
|
|
14559
|
+
};
|
|
14560
|
+
}
|
|
14561
|
+
return {};
|
|
14562
|
+
default:
|
|
14563
|
+
return {};
|
|
14564
|
+
}
|
|
14565
|
+
}
|
|
14566
|
+
var numericOrStateRef, comparisonOps, StateConditionSchema, ItemConditionSchema, IndexConditionSchema, SingleConditionSchema, VisibilityConditionSchema, StrictSingleConditionSchema, VisibilityConditionStrictSchema, WARNED_COMPUTED_MAX = 100, warnedComputedFns, ActionConfirmSchema, ActionOnSuccessSchema, ActionOnErrorSchema, ActionBindingSchema, ValidationCheckSchema, ValidationConfigSchema, DEFAULT_MODES, seedSchema, compositionActionSchema, probability, responseSchema;
|
|
14567
|
+
var init_dist = __esm(() => {
|
|
14568
|
+
init_chunk_FVP4K5MD();
|
|
14569
|
+
init_zod();
|
|
14570
|
+
init_zod();
|
|
14571
|
+
init_zod();
|
|
14572
|
+
init_zod();
|
|
14573
|
+
init_zod();
|
|
14574
|
+
init_zod();
|
|
14575
|
+
init_zod();
|
|
14576
|
+
numericOrStateRef = union3([
|
|
14577
|
+
number2(),
|
|
14578
|
+
object2({ $state: string2() })
|
|
14579
|
+
]);
|
|
14580
|
+
comparisonOps = {
|
|
14581
|
+
eq: unknown().optional(),
|
|
14582
|
+
neq: unknown().optional(),
|
|
14583
|
+
gt: numericOrStateRef.optional(),
|
|
14584
|
+
gte: numericOrStateRef.optional(),
|
|
14585
|
+
lt: numericOrStateRef.optional(),
|
|
14586
|
+
lte: numericOrStateRef.optional(),
|
|
14587
|
+
not: literal2(true).optional()
|
|
14588
|
+
};
|
|
14589
|
+
StateConditionSchema = object2({
|
|
14590
|
+
$state: string2(),
|
|
14591
|
+
...comparisonOps
|
|
14592
|
+
});
|
|
14593
|
+
ItemConditionSchema = object2({
|
|
14594
|
+
$item: string2(),
|
|
14595
|
+
...comparisonOps
|
|
14596
|
+
});
|
|
14597
|
+
IndexConditionSchema = object2({
|
|
14598
|
+
$index: literal2(true),
|
|
14599
|
+
...comparisonOps
|
|
14600
|
+
});
|
|
14601
|
+
SingleConditionSchema = union3([
|
|
14602
|
+
StateConditionSchema,
|
|
14603
|
+
ItemConditionSchema,
|
|
14604
|
+
IndexConditionSchema
|
|
14605
|
+
]);
|
|
14606
|
+
VisibilityConditionSchema = lazy(() => union3([
|
|
14607
|
+
boolean(),
|
|
14608
|
+
SingleConditionSchema,
|
|
14609
|
+
array2(SingleConditionSchema),
|
|
14610
|
+
object2({ $and: array2(VisibilityConditionSchema) }),
|
|
14611
|
+
object2({ $or: array2(VisibilityConditionSchema) })
|
|
14612
|
+
]));
|
|
14613
|
+
StrictSingleConditionSchema = union3([
|
|
14614
|
+
strictObject2({ $state: string2(), ...comparisonOps }),
|
|
14615
|
+
strictObject2({ $item: string2(), ...comparisonOps }),
|
|
14616
|
+
strictObject2({ $index: literal2(true), ...comparisonOps })
|
|
14617
|
+
]);
|
|
14618
|
+
VisibilityConditionStrictSchema = lazy(() => union3([
|
|
14619
|
+
boolean(),
|
|
14620
|
+
StrictSingleConditionSchema,
|
|
14621
|
+
array2(StrictSingleConditionSchema),
|
|
14622
|
+
strictObject2({ $and: array2(VisibilityConditionStrictSchema) }),
|
|
14623
|
+
strictObject2({ $or: array2(VisibilityConditionStrictSchema) })
|
|
14624
|
+
]));
|
|
14625
|
+
warnedComputedFns = /* @__PURE__ */ new Set;
|
|
14626
|
+
ActionConfirmSchema = object2({
|
|
14627
|
+
title: string2(),
|
|
14628
|
+
message: string2(),
|
|
14629
|
+
confirmLabel: string2().optional(),
|
|
14630
|
+
cancelLabel: string2().optional(),
|
|
14631
|
+
variant: _enum2(["default", "danger"]).optional()
|
|
14632
|
+
});
|
|
14633
|
+
ActionOnSuccessSchema = union3([
|
|
14634
|
+
object2({ navigate: string2() }),
|
|
14635
|
+
object2({ set: record2(string2(), unknown()) }),
|
|
14636
|
+
object2({
|
|
14637
|
+
action: string2(),
|
|
14638
|
+
params: record2(string2(), DynamicValueSchema).optional()
|
|
14639
|
+
})
|
|
14640
|
+
]);
|
|
14641
|
+
ActionOnErrorSchema = union3([
|
|
14642
|
+
object2({ set: record2(string2(), unknown()) }),
|
|
14643
|
+
object2({
|
|
14644
|
+
action: string2(),
|
|
14645
|
+
params: record2(string2(), DynamicValueSchema).optional()
|
|
14646
|
+
})
|
|
14647
|
+
]);
|
|
14648
|
+
ActionBindingSchema = object2({
|
|
14649
|
+
action: string2(),
|
|
14650
|
+
params: record2(string2(), DynamicValueSchema).optional(),
|
|
14651
|
+
confirm: ActionConfirmSchema.optional(),
|
|
14652
|
+
onSuccess: ActionOnSuccessSchema.optional(),
|
|
14653
|
+
onError: ActionOnErrorSchema.optional(),
|
|
14654
|
+
preventDefault: boolean().optional()
|
|
14655
|
+
});
|
|
14656
|
+
ValidationCheckSchema = object2({
|
|
14657
|
+
type: string2(),
|
|
14658
|
+
args: record2(string2(), DynamicValueSchema).optional(),
|
|
14659
|
+
message: string2()
|
|
14660
|
+
});
|
|
14661
|
+
ValidationConfigSchema = object2({
|
|
14662
|
+
checks: array2(ValidationCheckSchema).optional(),
|
|
14663
|
+
validateOn: _enum2(["change", "blur", "submit"]).optional(),
|
|
14664
|
+
enabled: VisibilityConditionSchema.optional()
|
|
14665
|
+
});
|
|
14666
|
+
DEFAULT_MODES = ["patch"];
|
|
14667
|
+
seedSchema = object2({
|
|
14668
|
+
root: string2().min(1),
|
|
14669
|
+
elements: record2(string2(), object2({
|
|
14670
|
+
type: string2(),
|
|
14671
|
+
props: record2(string2(), unknown()),
|
|
14672
|
+
children: array2(string2()).optional(),
|
|
14673
|
+
slots: record2(string2(), array2(string2())).optional(),
|
|
14674
|
+
on: record2(string2(), unknown()).optional(),
|
|
14675
|
+
visible: unknown().optional()
|
|
14676
|
+
}).strict()),
|
|
14677
|
+
state: record2(string2(), unknown()).optional()
|
|
14678
|
+
}).strict();
|
|
14679
|
+
compositionActionSchema = ActionBindingSchema.extend({
|
|
14680
|
+
params: record2(string2(), unknown()).optional(),
|
|
14681
|
+
onSuccess: unknown().optional(),
|
|
14682
|
+
onError: unknown().optional()
|
|
14683
|
+
}).strict();
|
|
14684
|
+
probability = number2().min(0).max(1);
|
|
14685
|
+
responseSchema = object2({
|
|
14686
|
+
answers: record2(string2(), object2({ type: literal2("choice"), choice: string2() })),
|
|
14687
|
+
providerMetadata: object2({
|
|
14688
|
+
typesafe: object2({ confidence: record2(string2(), probability) }).optional()
|
|
14689
|
+
}).optional(),
|
|
14690
|
+
usage: object2({ inputTokens: number2().int().nonnegative().optional() }).optional()
|
|
14691
|
+
});
|
|
14692
|
+
});
|
|
14693
|
+
|
|
14694
|
+
// node_modules/@json-render/chat/dist/index.mjs
|
|
14695
|
+
function normalizeTableRows(props) {
|
|
14696
|
+
if (!Array.isArray(props.rows) || !Array.isArray(props.headers))
|
|
14697
|
+
return props;
|
|
14698
|
+
const headers = props.headers.map((h) => normalizeKey(String(h)));
|
|
14699
|
+
const rows = props.rows.map((row) => {
|
|
14700
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
14701
|
+
return row;
|
|
14702
|
+
const entries = Object.entries(row).map(([k, v]) => [normalizeKey(k), v]);
|
|
14703
|
+
const byKey = new Map(entries);
|
|
14704
|
+
const unmatched = entries.filter(([k]) => !headers.includes(k));
|
|
14705
|
+
const rest = [
|
|
14706
|
+
...unmatched.filter(([k]) => !ID_KEYS.has(k)),
|
|
14707
|
+
...unmatched.filter(([k]) => ID_KEYS.has(k))
|
|
14708
|
+
];
|
|
14709
|
+
return headers.map((h) => byKey.has(h) ? byKey.get(h) : rest.shift()?.[1]);
|
|
14710
|
+
});
|
|
14711
|
+
return { ...props, rows };
|
|
14712
|
+
}
|
|
14713
|
+
function validateProps(elements, defs) {
|
|
14714
|
+
const issues = [];
|
|
14715
|
+
for (const [key, el] of Object.entries(elements)) {
|
|
14716
|
+
const def = defs[el.type];
|
|
14717
|
+
if (!def) {
|
|
14718
|
+
issues.push(`${key}: unknown component "${el.type}"`);
|
|
14719
|
+
continue;
|
|
14720
|
+
}
|
|
14721
|
+
const props = el.type === "Table" ? normalizeTableRows(el.props ?? {}) : el.props ?? {};
|
|
14722
|
+
const parsed = def.props.safeParse(props);
|
|
14723
|
+
if (!parsed.success) {
|
|
14724
|
+
for (const issue of parsed.error.issues)
|
|
14725
|
+
issues.push(`${key}.props.${issue.path.join(".")}: ${issue.message}`);
|
|
14726
|
+
} else {
|
|
14727
|
+
el.props = parsed.data;
|
|
14728
|
+
}
|
|
14729
|
+
}
|
|
14730
|
+
return issues;
|
|
14731
|
+
}
|
|
14732
|
+
function validateStructure(spec, elements, defs) {
|
|
14733
|
+
const issues = [];
|
|
14734
|
+
const root = elements[spec.root];
|
|
14735
|
+
if (!root)
|
|
14736
|
+
issues.push(`root "${spec.root}" is not an element`);
|
|
14737
|
+
else if (root.type !== "Card")
|
|
14738
|
+
issues.push("root must be a Card");
|
|
14739
|
+
for (const [key, el] of Object.entries(elements)) {
|
|
14740
|
+
if (el.children.length && !defs[el.type]?.slots?.length)
|
|
14741
|
+
issues.push(`${key}: ${el.type} cannot have children`);
|
|
14742
|
+
for (const childKey of el.children) {
|
|
14743
|
+
const child = elements[childKey];
|
|
14744
|
+
if (!child) {
|
|
14745
|
+
issues.push(`${key}: missing child "${childKey}"`);
|
|
14746
|
+
continue;
|
|
14747
|
+
}
|
|
14748
|
+
if (el.type === "Fields" && child.type !== "Field")
|
|
14749
|
+
issues.push(`${key}: Fields only holds Field elements`);
|
|
14750
|
+
if (el.type === "Actions" && !["Button", "LinkButton"].includes(child.type))
|
|
14751
|
+
issues.push(`${key}: Actions only holds Button and LinkButton elements`);
|
|
14752
|
+
}
|
|
14753
|
+
if (el.type === "Table") {
|
|
14754
|
+
const width = el.props.headers.length;
|
|
14755
|
+
el.props.rows.forEach((row, i) => {
|
|
14756
|
+
if (row.length !== width)
|
|
14757
|
+
issues.push(`${key}: row ${i} has ${row.length} cells, expected ${width}`);
|
|
14758
|
+
});
|
|
14759
|
+
}
|
|
14760
|
+
if (el.type === "Chart" && el.props.chart.type !== "pie") {
|
|
14761
|
+
const count = el.props.chart.categories.length;
|
|
14762
|
+
for (const series of el.props.chart.series)
|
|
14763
|
+
if (series.values.length !== count)
|
|
14764
|
+
issues.push(`${key}: series "${series.name}" has ${series.values.length} values, expected ${count}`);
|
|
14765
|
+
}
|
|
14766
|
+
}
|
|
14767
|
+
return issues;
|
|
14768
|
+
}
|
|
14769
|
+
function validateLimits(elements, limits) {
|
|
14770
|
+
const issues = [];
|
|
14771
|
+
const all = Object.entries(elements);
|
|
14772
|
+
const count = (type) => all.filter(([, el]) => el.type === type).length;
|
|
14773
|
+
const over = (value, max) => max !== undefined && value > max;
|
|
14774
|
+
if (over(count("Table"), limits.tables))
|
|
14775
|
+
issues.push(`at most ${limits.tables} Table per message`);
|
|
14776
|
+
if (over(count("Chart"), limits.charts))
|
|
14777
|
+
issues.push(`at most ${limits.charts} Chart per message`);
|
|
14778
|
+
for (const [key, el] of all) {
|
|
14779
|
+
const p = el.props;
|
|
14780
|
+
if (el.type === "Fields" && over(el.children.length, limits.fields))
|
|
14781
|
+
issues.push(`${key}: at most ${limits.fields} fields`);
|
|
14782
|
+
if (el.type === "Table") {
|
|
14783
|
+
if (over(p.rows.length + 1, limits.tableRows))
|
|
14784
|
+
issues.push(`${key}: at most ${limits.tableRows} rows including the header`);
|
|
14785
|
+
if (over(p.headers.length, limits.tableColumns))
|
|
14786
|
+
issues.push(`${key}: at most ${limits.tableColumns} columns`);
|
|
14787
|
+
}
|
|
14788
|
+
if (el.type === "Chart") {
|
|
14789
|
+
const c = p.chart;
|
|
14790
|
+
if (over(p.title.length, limits.chartTitle))
|
|
14791
|
+
issues.push(`${key}: title longer than ${limits.chartTitle} characters`);
|
|
14792
|
+
const labels = c.type === "pie" ? c.segments.map((s) => s.label) : [...c.categories, ...c.series.map((s) => s.name)];
|
|
14793
|
+
for (const label of labels)
|
|
14794
|
+
if (over(label.length, limits.chartLabel))
|
|
14795
|
+
issues.push(`${key}: label "${label}" longer than ${limits.chartLabel} characters`);
|
|
14796
|
+
const groups = c.type === "pie" ? c.segments.length : c.series.length;
|
|
14797
|
+
if (over(groups, limits.chartSeries))
|
|
14798
|
+
issues.push(`${key}: at most ${limits.chartSeries} series or segments`);
|
|
14799
|
+
if (c.type !== "pie" && over(c.categories.length, limits.chartPoints))
|
|
14800
|
+
issues.push(`${key}: at most ${limits.chartPoints} categories`);
|
|
14801
|
+
}
|
|
14802
|
+
}
|
|
14803
|
+
return issues;
|
|
14804
|
+
}
|
|
14805
|
+
function toChild(key, elements) {
|
|
14806
|
+
const el = elements[key];
|
|
14807
|
+
const p = el.props;
|
|
14808
|
+
const children = () => el.children.map((k) => elements[k]);
|
|
14809
|
+
switch (el.type) {
|
|
14810
|
+
case "Section":
|
|
14811
|
+
return section(el.children.map((k) => toChild(k, elements)));
|
|
14812
|
+
case "Card":
|
|
14813
|
+
return section([
|
|
14814
|
+
...p.title ? [text(p.title, "bold")] : [],
|
|
14815
|
+
...p.subtitle ? [text(p.subtitle, "muted")] : [],
|
|
14816
|
+
...el.children.map((k) => toChild(k, elements))
|
|
14817
|
+
]);
|
|
14818
|
+
case "Text":
|
|
14819
|
+
return text(p.content, p.style ?? undefined);
|
|
14820
|
+
case "Divider":
|
|
14821
|
+
return divider();
|
|
14822
|
+
case "Image":
|
|
14823
|
+
return image(p.url, p.alt);
|
|
14824
|
+
case "Fields":
|
|
14825
|
+
return fields(children().map((f) => field(f.props.label, f.props.value)));
|
|
14826
|
+
case "Table":
|
|
14827
|
+
return table({
|
|
14828
|
+
headers: p.headers,
|
|
14829
|
+
rows: p.rows,
|
|
14830
|
+
align: p.align ?? undefined,
|
|
14831
|
+
caption: p.caption ?? undefined
|
|
14832
|
+
});
|
|
14833
|
+
case "Chart": {
|
|
14834
|
+
const c = p.chart;
|
|
14835
|
+
return chart({
|
|
14836
|
+
title: p.title,
|
|
14837
|
+
chart: c.type === "pie" ? { type: "pie", segments: c.segments } : {
|
|
14838
|
+
type: c.type,
|
|
14839
|
+
categories: c.categories,
|
|
14840
|
+
xLabel: c.xLabel ?? undefined,
|
|
14841
|
+
yLabel: c.yLabel ?? undefined,
|
|
14842
|
+
series: c.series.map((s) => ({
|
|
14843
|
+
name: s.name,
|
|
14844
|
+
data: s.values.map((value, i) => ({
|
|
14845
|
+
label: c.categories[i],
|
|
14846
|
+
value
|
|
14847
|
+
}))
|
|
14848
|
+
}))
|
|
14849
|
+
}
|
|
14850
|
+
});
|
|
14851
|
+
}
|
|
14852
|
+
case "Actions":
|
|
14853
|
+
return actions(children().map((b) => b.type === "LinkButton" ? linkButton({ label: b.props.label, url: b.props.url }) : button({
|
|
14854
|
+
id: b.props.id,
|
|
14855
|
+
label: b.props.label,
|
|
14856
|
+
style: b.props.style ?? undefined,
|
|
14857
|
+
value: b.props.value ?? undefined
|
|
14858
|
+
})));
|
|
14859
|
+
default:
|
|
14860
|
+
throw new CardSpecError([`${key}: ${el.type} cannot be nested here`]);
|
|
14861
|
+
}
|
|
14862
|
+
}
|
|
14863
|
+
function materialize(spec, maxElements) {
|
|
14864
|
+
const source = spec.elements ?? {};
|
|
14865
|
+
const stateModel = spec.state ?? {};
|
|
14866
|
+
const out = {};
|
|
14867
|
+
const missing = [];
|
|
14868
|
+
const seen = /* @__PURE__ */ new Set;
|
|
14869
|
+
let budget = maxElements;
|
|
14870
|
+
let overflow = false;
|
|
14871
|
+
const spend = () => {
|
|
14872
|
+
if (budget <= 0) {
|
|
14873
|
+
overflow = true;
|
|
14874
|
+
return false;
|
|
14875
|
+
}
|
|
14876
|
+
budget -= 1;
|
|
14877
|
+
return true;
|
|
14878
|
+
};
|
|
14879
|
+
const itemsAt = (repeat, ctx) => {
|
|
14880
|
+
const path = resolveRepeatStatePath(repeat.statePath, ctx.repeatBasePath);
|
|
14881
|
+
const items = path ? getByPath(stateModel, path) : undefined;
|
|
14882
|
+
return { path: path ?? "", items: Array.isArray(items) ? items : [] };
|
|
14883
|
+
};
|
|
14884
|
+
const itemContext = (path, item, index) => ({
|
|
14885
|
+
stateModel,
|
|
14886
|
+
repeatItem: item,
|
|
14887
|
+
repeatIndex: index,
|
|
14888
|
+
repeatBasePath: resolveRepeatItemStatePath(path, index)
|
|
14889
|
+
});
|
|
14890
|
+
const visit = (key, outKey, ctx) => {
|
|
14891
|
+
const el = source[key];
|
|
14892
|
+
if (!el?.type) {
|
|
14893
|
+
missing.push(key);
|
|
14894
|
+
return false;
|
|
14895
|
+
}
|
|
14896
|
+
if (seen.has(outKey))
|
|
14897
|
+
return false;
|
|
14898
|
+
const { container, itemFilter } = el.repeat && ctx.repeatIndex === undefined ? splitRepeatVisibility(el.visible) : { container: el.visible, itemFilter: undefined };
|
|
14899
|
+
if (container !== undefined && !evaluateVisibility(container, ctx))
|
|
14900
|
+
return false;
|
|
14901
|
+
if (!spend())
|
|
14902
|
+
return false;
|
|
14903
|
+
seen.add(outKey);
|
|
14904
|
+
const props = el.props ?? {};
|
|
14905
|
+
const childKeys = el.children ?? [];
|
|
14906
|
+
const children = [];
|
|
14907
|
+
const repeat = el.repeat;
|
|
14908
|
+
const keep = (path, item, index) => itemFilter === undefined || evaluateVisibility(itemFilter, itemContext(path, item, index));
|
|
14909
|
+
if (repeat && el.type === "Table" && Array.isArray(props.rows)) {
|
|
14910
|
+
const { path, items } = itemsAt(repeat, ctx);
|
|
14911
|
+
const rows = [];
|
|
14912
|
+
for (let index = 0;index < items.length && !overflow; index++) {
|
|
14913
|
+
if (!keep(path, items[index], index))
|
|
14914
|
+
continue;
|
|
14915
|
+
const itemCtx = itemContext(path, items[index], index);
|
|
14916
|
+
for (const row of props.rows) {
|
|
14917
|
+
if (!spend())
|
|
14918
|
+
break;
|
|
14919
|
+
rows.push(resolveElementProps({ row }, itemCtx).row);
|
|
14920
|
+
}
|
|
14921
|
+
}
|
|
14922
|
+
out[outKey] = {
|
|
14923
|
+
type: el.type,
|
|
14924
|
+
props: { ...resolveElementProps(props, ctx), rows },
|
|
14925
|
+
children: []
|
|
14926
|
+
};
|
|
14927
|
+
return true;
|
|
14928
|
+
}
|
|
14929
|
+
if (repeat) {
|
|
14930
|
+
const { path, items } = itemsAt(repeat, ctx);
|
|
14931
|
+
const scope = outKey === key ? "" : `${outKey}.`;
|
|
14932
|
+
for (let index = 0;index < items.length && !overflow; index++) {
|
|
14933
|
+
if (!keep(path, items[index], index))
|
|
14934
|
+
continue;
|
|
14935
|
+
const itemCtx = itemContext(path, items[index], index);
|
|
14936
|
+
for (const child of childKeys) {
|
|
14937
|
+
const childOut = `${child}#${scope}${index}`;
|
|
14938
|
+
if (visit(child, childOut, itemCtx))
|
|
14939
|
+
children.push(childOut);
|
|
14940
|
+
}
|
|
14941
|
+
}
|
|
14942
|
+
} else {
|
|
14943
|
+
const suffix = outKey.slice(key.length);
|
|
14944
|
+
for (const child of childKeys)
|
|
14945
|
+
if (visit(child, child + suffix, ctx))
|
|
14946
|
+
children.push(child + suffix);
|
|
14947
|
+
}
|
|
14948
|
+
out[outKey] = {
|
|
14949
|
+
type: el.type,
|
|
14950
|
+
props: resolveElementProps(props, ctx),
|
|
14951
|
+
children
|
|
14952
|
+
};
|
|
14953
|
+
return true;
|
|
14954
|
+
};
|
|
14955
|
+
if (spec.root)
|
|
14956
|
+
visit(spec.root, spec.root, { stateModel });
|
|
14957
|
+
return { elements: out, missing, overflow };
|
|
14958
|
+
}
|
|
14959
|
+
function prune(elements, rootKey) {
|
|
14960
|
+
const kept = /* @__PURE__ */ new Map;
|
|
14961
|
+
const visit = (key) => {
|
|
14962
|
+
const cached = kept.get(key);
|
|
14963
|
+
if (cached !== undefined)
|
|
14964
|
+
return cached;
|
|
14965
|
+
kept.set(key, false);
|
|
14966
|
+
const el = elements[key];
|
|
14967
|
+
if (!el)
|
|
14968
|
+
return false;
|
|
14969
|
+
const accepts = ACCEPTS[el.type];
|
|
14970
|
+
el.children = el.children.filter((child) => elements[child] !== undefined && (!accepts || accepts.includes(elements[child].type)) && visit(child));
|
|
14971
|
+
const keep = key === rootKey || (GROUPS.has(el.type) ? el.children.length > 0 : el.type !== "Card" || hasContent(el));
|
|
14972
|
+
kept.set(key, keep);
|
|
14973
|
+
return keep;
|
|
14974
|
+
};
|
|
14975
|
+
visit(rootKey);
|
|
14976
|
+
}
|
|
14977
|
+
function buildCard(root, elements, keys) {
|
|
14978
|
+
return card({
|
|
14979
|
+
title: root.props.title ?? undefined,
|
|
14980
|
+
subtitle: root.props.subtitle ?? undefined,
|
|
14981
|
+
imageUrl: root.props.imageUrl ?? undefined,
|
|
14982
|
+
children: keys.map((k) => toChild(k, elements))
|
|
14983
|
+
});
|
|
14984
|
+
}
|
|
14985
|
+
function toCard(spec, options = {}) {
|
|
14986
|
+
const defs = options.components ?? standardComponentDefinitions;
|
|
14987
|
+
if (!spec || typeof spec.root !== "string" || !spec.elements)
|
|
14988
|
+
throw new CardSpecError(["spec needs a root and elements"]);
|
|
14989
|
+
const maxElements = options.maxElements ?? DEFAULT_MAX_ELEMENTS;
|
|
14990
|
+
const { elements, missing, overflow } = materialize(spec, maxElements);
|
|
14991
|
+
if (overflow)
|
|
14992
|
+
throw new CardSpecError([
|
|
14993
|
+
`the spec expands to more than ${maxElements} elements and table rows`
|
|
14994
|
+
]);
|
|
14995
|
+
let issues = validateProps(elements, defs);
|
|
14996
|
+
if (!issues.length)
|
|
14997
|
+
issues = [
|
|
14998
|
+
...missing.map((key) => `missing element "${key}"`),
|
|
14999
|
+
...validateStructure(spec, elements, defs)
|
|
15000
|
+
];
|
|
15001
|
+
if (!issues.length) {
|
|
15002
|
+
prune(elements, spec.root);
|
|
15003
|
+
if (!hasContent(elements[spec.root]))
|
|
15004
|
+
issues.push("the Card needs a title, an image or at least one child");
|
|
15005
|
+
}
|
|
15006
|
+
if (!issues.length && options.limits)
|
|
15007
|
+
issues = validateLimits(elements, options.limits);
|
|
15008
|
+
if (issues.length)
|
|
15009
|
+
throw new CardSpecError(issues);
|
|
15010
|
+
const root = elements[spec.root];
|
|
15011
|
+
return buildCard(root, elements, root.children);
|
|
15012
|
+
}
|
|
15013
|
+
var schema, displayText, pieChart, seriesChart, standardComponentDefinitions, card = (options) => ({ type: "card", ...options }), text = (content, style) => ({ type: "text", content, style }), image = (url, alt) => ({
|
|
15014
|
+
type: "image",
|
|
15015
|
+
url,
|
|
15016
|
+
alt
|
|
15017
|
+
}), divider = () => ({ type: "divider" }), section = (children) => ({
|
|
15018
|
+
type: "section",
|
|
15019
|
+
children
|
|
15020
|
+
}), field = (label, value) => ({
|
|
15021
|
+
type: "field",
|
|
15022
|
+
label,
|
|
15023
|
+
value
|
|
15024
|
+
}), fields = (children) => ({
|
|
15025
|
+
type: "fields",
|
|
15026
|
+
children
|
|
15027
|
+
}), table = (options) => ({
|
|
15028
|
+
type: "table",
|
|
15029
|
+
...options
|
|
15030
|
+
}), chart = (options) => ({
|
|
15031
|
+
type: "chart",
|
|
15032
|
+
...options
|
|
15033
|
+
}), button = (options) => ({ type: "button", ...options }), linkButton = (options) => ({ type: "link-button", ...options }), actions = (children) => ({ type: "actions", children }), DEFAULT_MAX_ELEMENTS = 1000, CardSpecError, normalizeKey = (value) => value.toLowerCase().replace(/[^a-z0-9]/g, ""), ID_KEYS, ACCEPTS, GROUPS, hasContent = (el) => Boolean(el.props.title || el.props.subtitle || el.props.imageUrl || el.children.length);
|
|
15034
|
+
var init_dist5 = __esm(() => {
|
|
15035
|
+
init_dist();
|
|
15036
|
+
init_zod();
|
|
15037
|
+
init_dist();
|
|
15038
|
+
init_dist();
|
|
15039
|
+
schema = defineSchema((s) => ({
|
|
15040
|
+
spec: s.object({
|
|
15041
|
+
root: s.string(),
|
|
15042
|
+
elements: s.record(s.object({
|
|
15043
|
+
type: s.ref("catalog.components"),
|
|
15044
|
+
props: s.propsOf("catalog.components"),
|
|
15045
|
+
children: s.array(s.string()),
|
|
15046
|
+
visible: { ...s.any(), ...s.optional() },
|
|
15047
|
+
repeat: { ...s.any(), ...s.optional() }
|
|
15048
|
+
}))
|
|
15049
|
+
}),
|
|
15050
|
+
catalog: s.object({
|
|
15051
|
+
components: s.map({
|
|
15052
|
+
props: s.zod(),
|
|
15053
|
+
slots: s.array(s.string()),
|
|
15054
|
+
description: s.string(),
|
|
15055
|
+
example: s.any()
|
|
15056
|
+
})
|
|
15057
|
+
})
|
|
15058
|
+
}), {
|
|
15059
|
+
defaultRules: [
|
|
15060
|
+
"The root element MUST be a Card. Every other element is a descendant of it. To group items inside the message, use Section, not another Card.",
|
|
15061
|
+
"Messages are static once posted. $state, $item, $index, $template, repeat and visible are resolved when the card is built, but there are no inputs, so do not use $bindState or $bindItem.",
|
|
15062
|
+
"Pick components by the shape of the data: Fields for a few key numbers, Table for row data, Chart for a trend or a share of a whole, Actions for next steps.",
|
|
15063
|
+
'For a Table backed by state, set rows to { "$state": "/path" } where the path holds an array of rows (arrays or objects with one value per header).',
|
|
15064
|
+
"Text content uses markdown: **bold**, _italic_, `code` and [label](https://url). Do not use headings inside Text.",
|
|
15065
|
+
"Field elements MUST be children of a Fields element. Button and LinkButton elements MUST be children of an Actions element.",
|
|
15066
|
+
"Every series in a bar, line or area Chart has exactly one value per category, in category order.",
|
|
15067
|
+
'Every element MUST include a "children" array. Leaf elements use "children": [].'
|
|
15068
|
+
]
|
|
15069
|
+
});
|
|
15070
|
+
displayText = union3([string2(), number2()]).transform(String);
|
|
15071
|
+
pieChart = object2({
|
|
15072
|
+
type: literal2("pie"),
|
|
15073
|
+
segments: array2(object2({ label: string2().min(1), value: number2().positive() })).min(1)
|
|
15074
|
+
});
|
|
15075
|
+
seriesChart = object2({
|
|
15076
|
+
type: _enum2(["bar", "line", "area"]),
|
|
15077
|
+
categories: array2(string2().min(1)).min(1),
|
|
15078
|
+
series: array2(object2({ name: string2().min(1), values: array2(number2()) })).min(1),
|
|
15079
|
+
xLabel: string2().nullish(),
|
|
15080
|
+
yLabel: string2().nullish()
|
|
15081
|
+
});
|
|
15082
|
+
standardComponentDefinitions = {
|
|
15083
|
+
Card: {
|
|
15084
|
+
props: object2({
|
|
15085
|
+
title: string2().nullish(),
|
|
15086
|
+
subtitle: string2().nullish(),
|
|
15087
|
+
imageUrl: string2().url().nullish()
|
|
15088
|
+
}),
|
|
15089
|
+
slots: ["default"],
|
|
15090
|
+
description: "Root of a message. Title renders as the card header, subtitle as secondary text.",
|
|
15091
|
+
example: { title: "Weekly deploys", subtitle: "Oct 27 to Nov 2" }
|
|
15092
|
+
},
|
|
15093
|
+
Section: {
|
|
15094
|
+
props: object2({}),
|
|
15095
|
+
slots: ["default"],
|
|
15096
|
+
description: "Groups related elements.",
|
|
15097
|
+
example: {}
|
|
15098
|
+
},
|
|
15099
|
+
Text: {
|
|
15100
|
+
props: object2({
|
|
15101
|
+
content: string2().min(1),
|
|
15102
|
+
style: _enum2(["plain", "bold", "muted"]).nullish()
|
|
15103
|
+
}),
|
|
15104
|
+
slots: [],
|
|
15105
|
+
description: "A paragraph of markdown text. Use muted for footnotes.",
|
|
15106
|
+
example: { content: "Deploys are **up 12%** week over week." }
|
|
15107
|
+
},
|
|
15108
|
+
Fields: {
|
|
15109
|
+
props: object2({}),
|
|
15110
|
+
slots: ["default"],
|
|
15111
|
+
description: "Grid of label and value pairs. Children are Field elements.",
|
|
15112
|
+
example: {}
|
|
15113
|
+
},
|
|
15114
|
+
Field: {
|
|
15115
|
+
props: object2({ label: string2().min(1), value: displayText }),
|
|
15116
|
+
slots: [],
|
|
15117
|
+
description: "One label and value pair inside Fields. Good for KPIs.",
|
|
15118
|
+
example: { label: "Deploys", value: "1,284" }
|
|
15119
|
+
},
|
|
15120
|
+
Table: {
|
|
15121
|
+
props: object2({
|
|
15122
|
+
headers: array2(string2()).min(1),
|
|
15123
|
+
rows: array2(array2(displayText)),
|
|
15124
|
+
align: array2(_enum2(["left", "center", "right"])).nullish(),
|
|
15125
|
+
caption: string2().nullish()
|
|
15126
|
+
}),
|
|
15127
|
+
slots: [],
|
|
15128
|
+
description: "Table for row data. Every row has one cell per header. Right-align numeric columns.",
|
|
15129
|
+
example: {
|
|
15130
|
+
headers: ["Project", "Deploys"],
|
|
15131
|
+
rows: [
|
|
15132
|
+
["web", "412"],
|
|
15133
|
+
["api", "203"]
|
|
15134
|
+
],
|
|
15135
|
+
align: ["left", "right"]
|
|
15136
|
+
}
|
|
15137
|
+
},
|
|
15138
|
+
Chart: {
|
|
15139
|
+
props: object2({
|
|
15140
|
+
title: string2().min(1),
|
|
15141
|
+
chart: union3([pieChart, seriesChart])
|
|
15142
|
+
}),
|
|
15143
|
+
slots: [],
|
|
15144
|
+
description: "Chart. pie for shares of a whole, bar, line or area for series over categories.",
|
|
15145
|
+
example: {
|
|
15146
|
+
title: "Deploys per day",
|
|
15147
|
+
chart: {
|
|
15148
|
+
type: "bar",
|
|
15149
|
+
categories: ["Mon", "Tue", "Wed"],
|
|
15150
|
+
series: [{ name: "Deploys", values: [180, 210, 195] }]
|
|
15151
|
+
}
|
|
15152
|
+
}
|
|
15153
|
+
},
|
|
15154
|
+
Divider: {
|
|
15155
|
+
props: object2({}),
|
|
15156
|
+
slots: [],
|
|
15157
|
+
description: "Separator between groups.",
|
|
15158
|
+
example: {}
|
|
15159
|
+
},
|
|
15160
|
+
Image: {
|
|
15161
|
+
props: object2({ url: string2().url(), alt: string2().min(1) }),
|
|
15162
|
+
slots: [],
|
|
15163
|
+
description: "Image from a public https URL.",
|
|
15164
|
+
example: { url: "https://picsum.photos/600/300", alt: "Preview" }
|
|
15165
|
+
},
|
|
15166
|
+
Actions: {
|
|
15167
|
+
props: object2({}),
|
|
15168
|
+
slots: ["default"],
|
|
15169
|
+
description: "Row of Button and LinkButton elements.",
|
|
15170
|
+
example: {}
|
|
15171
|
+
},
|
|
15172
|
+
Button: {
|
|
15173
|
+
props: object2({
|
|
15174
|
+
id: string2().min(1),
|
|
15175
|
+
label: string2().min(1),
|
|
15176
|
+
style: _enum2(["primary", "danger", "default"]).nullish(),
|
|
15177
|
+
value: string2().nullish()
|
|
15178
|
+
}),
|
|
15179
|
+
slots: [],
|
|
15180
|
+
description: "Interactive button. id is the action id the bot handles with onAction.",
|
|
15181
|
+
example: { id: "approve", label: "Approve", style: "primary" }
|
|
15182
|
+
},
|
|
15183
|
+
LinkButton: {
|
|
15184
|
+
props: object2({ label: string2().min(1), url: string2().url() }),
|
|
15185
|
+
slots: [],
|
|
15186
|
+
description: "Button that opens a URL.",
|
|
15187
|
+
example: { label: "Open dashboard", url: "https://vercel.com" }
|
|
15188
|
+
}
|
|
15189
|
+
};
|
|
15190
|
+
CardSpecError = class extends Error {
|
|
15191
|
+
constructor(issues) {
|
|
15192
|
+
super(issues.join(`
|
|
15193
|
+
`));
|
|
15194
|
+
this.issues = issues;
|
|
15195
|
+
this.name = "CardSpecError";
|
|
15196
|
+
}
|
|
15197
|
+
};
|
|
15198
|
+
ID_KEYS = /* @__PURE__ */ new Set(["id", "key", "uuid"]);
|
|
15199
|
+
ACCEPTS = {
|
|
15200
|
+
Fields: ["Field"],
|
|
15201
|
+
Actions: ["Button", "LinkButton"]
|
|
15202
|
+
};
|
|
15203
|
+
GROUPS = /* @__PURE__ */ new Set(["Fields", "Actions", "Section"]);
|
|
15204
|
+
});
|
|
15205
|
+
|
|
15206
|
+
// src/utils/task-ui-spec.ts
|
|
15207
|
+
var UI_SPEC_MAX_BYTES = 32768, UI_SPEC_MAX_BLOCKS = 45, UI_SPEC_MAX_ACTIONS_ROW_ELEMENTS = 25, UI_SPEC_ACTION_PREFIX = "swarm_ui:", UI_SPEC_ACTION_ID, UI_SPEC_CARD_LIMITS;
|
|
15208
|
+
var init_task_ui_spec2 = __esm(() => {
|
|
15209
|
+
UI_SPEC_ACTION_ID = /^[a-z][a-z0-9_]{0,39}$/;
|
|
15210
|
+
UI_SPEC_CARD_LIMITS = {
|
|
15211
|
+
tables: 1,
|
|
15212
|
+
charts: 2,
|
|
15213
|
+
chartLabel: 20,
|
|
15214
|
+
chartTitle: 50,
|
|
15215
|
+
tableRows: 100,
|
|
15216
|
+
tableColumns: 20
|
|
15217
|
+
};
|
|
15218
|
+
});
|
|
15219
|
+
|
|
15220
|
+
// src/ui-spec/validate.ts
|
|
15221
|
+
function asElement(value) {
|
|
15222
|
+
return value !== null && typeof value === "object" ? value : null;
|
|
15223
|
+
}
|
|
15224
|
+
function elementProps(element) {
|
|
15225
|
+
const props = element.props;
|
|
15226
|
+
return props !== null && typeof props === "object" ? props : {};
|
|
15227
|
+
}
|
|
15228
|
+
function isHttpsUrl(value) {
|
|
15229
|
+
if (typeof value !== "string")
|
|
15230
|
+
return false;
|
|
15231
|
+
try {
|
|
15232
|
+
return new URL(value).protocol === "https:";
|
|
15233
|
+
} catch {
|
|
15234
|
+
return false;
|
|
15235
|
+
}
|
|
15236
|
+
}
|
|
15237
|
+
function renderTaskUiSpec(spec, taskId) {
|
|
15238
|
+
const renderCopy = structuredClone(spec);
|
|
15239
|
+
for (const value of Object.values(renderCopy.elements)) {
|
|
15240
|
+
const element = asElement(value);
|
|
15241
|
+
if (!element || element.type !== "Button")
|
|
15242
|
+
continue;
|
|
15243
|
+
const props = elementProps(element);
|
|
15244
|
+
element.props = { ...props, id: `${UI_SPEC_ACTION_PREFIX}${String(props.id)}`, value: taskId };
|
|
15245
|
+
}
|
|
15246
|
+
let card;
|
|
15247
|
+
try {
|
|
15248
|
+
card = toCard(renderCopy, { limits: UI_SPEC_CARD_LIMITS });
|
|
15249
|
+
} catch (error) {
|
|
15250
|
+
if (error instanceof CardSpecError)
|
|
15251
|
+
return { ok: false, issues: [...error.issues] };
|
|
15252
|
+
throw error;
|
|
15253
|
+
}
|
|
15254
|
+
const blocks = cardToBlockKit2(card);
|
|
15255
|
+
const issues = [];
|
|
15256
|
+
if (blocks.length > UI_SPEC_MAX_BLOCKS) {
|
|
15257
|
+
issues.push(`uiSpec renders as ${blocks.length} Slack blocks; the limit is ${UI_SPEC_MAX_BLOCKS}.`);
|
|
15258
|
+
}
|
|
15259
|
+
for (const block of blocks) {
|
|
15260
|
+
const count = block.elements?.length ?? 0;
|
|
15261
|
+
if (block.type === "actions" && count > UI_SPEC_MAX_ACTIONS_ROW_ELEMENTS) {
|
|
15262
|
+
issues.push(`An Actions row renders ${count} Slack elements; the limit is ${UI_SPEC_MAX_ACTIONS_ROW_ELEMENTS}.`);
|
|
15263
|
+
}
|
|
15264
|
+
}
|
|
15265
|
+
if (issues.length > 0)
|
|
15266
|
+
return { ok: false, issues };
|
|
15267
|
+
return { ok: true, blocks, fallbackText: cardToFallbackText2(card) };
|
|
15268
|
+
}
|
|
15269
|
+
function validateTaskUiSpec(input, { taskId, actionsEnabled }) {
|
|
15270
|
+
const issues = [];
|
|
15271
|
+
const bytes = new TextEncoder().encode(JSON.stringify(input.spec)).length;
|
|
15272
|
+
if (bytes > UI_SPEC_MAX_BYTES) {
|
|
15273
|
+
issues.push(`uiSpec is ${bytes} bytes; the limit is ${UI_SPEC_MAX_BYTES}.`);
|
|
15274
|
+
}
|
|
15275
|
+
for (const [elementId, value] of Object.entries(input.spec.elements)) {
|
|
15276
|
+
const element = asElement(value);
|
|
15277
|
+
if (!element)
|
|
15278
|
+
continue;
|
|
15279
|
+
const props = elementProps(element);
|
|
15280
|
+
const type = typeof element.type === "string" ? element.type : "";
|
|
15281
|
+
const urlProp = Object.hasOwn(URL_PROPS, type) ? URL_PROPS[type] : undefined;
|
|
15282
|
+
if (urlProp) {
|
|
15283
|
+
const url = props[urlProp];
|
|
15284
|
+
if (url !== undefined && url !== null && !isHttpsUrl(url)) {
|
|
15285
|
+
issues.push(`${elementId}.${urlProp} must be an https: URL.`);
|
|
15286
|
+
}
|
|
15287
|
+
}
|
|
15288
|
+
if (type === "Button") {
|
|
15289
|
+
if (!actionsEnabled) {
|
|
15290
|
+
issues.push(`Button ${elementId} needs UI_SPEC_ACTIONS_ENABLED=true; use LinkButton.`);
|
|
15291
|
+
continue;
|
|
15292
|
+
}
|
|
15293
|
+
const id = props.id;
|
|
15294
|
+
const declared = typeof id === "string" && UI_SPEC_ACTION_ID.test(id) && input.actions !== undefined && Object.hasOwn(input.actions, id);
|
|
15295
|
+
if (!declared) {
|
|
15296
|
+
issues.push(`Button ${elementId} names action "${String(id)}", which uiSpec.actions does not declare.`);
|
|
15297
|
+
}
|
|
15298
|
+
}
|
|
15299
|
+
}
|
|
15300
|
+
if (issues.length > 0)
|
|
15301
|
+
return { ok: false, issues };
|
|
15302
|
+
const rendered = renderTaskUiSpec(input.spec, taskId);
|
|
15303
|
+
if (!rendered.ok)
|
|
15304
|
+
return rendered;
|
|
15305
|
+
return {
|
|
15306
|
+
ok: true,
|
|
15307
|
+
spec: input.spec,
|
|
15308
|
+
actions: input.actions,
|
|
15309
|
+
blocks: rendered.blocks,
|
|
15310
|
+
fallbackText: rendered.fallbackText
|
|
15311
|
+
};
|
|
15312
|
+
}
|
|
15313
|
+
var URL_PROPS;
|
|
15314
|
+
var init_validate2 = __esm(() => {
|
|
15315
|
+
init_dist6();
|
|
15316
|
+
init_dist5();
|
|
15317
|
+
init_task_ui_spec2();
|
|
15318
|
+
URL_PROPS = {
|
|
15319
|
+
LinkButton: "url",
|
|
15320
|
+
Image: "url",
|
|
15321
|
+
Card: "imageUrl"
|
|
15322
|
+
};
|
|
15323
|
+
});
|
|
15324
|
+
|
|
15325
|
+
// src/ui-spec/slack.ts
|
|
15326
|
+
function taskUiSpecSlackBlocks(stored, taskId) {
|
|
15327
|
+
const rendered = renderTaskUiSpec(stored.spec, taskId);
|
|
15328
|
+
if (rendered.ok)
|
|
15329
|
+
return rendered.blocks;
|
|
15330
|
+
console.warn(`[ui-spec] stored spec for task ${taskId} no longer renders: ${rendered.issues.join(" | ")}`);
|
|
15331
|
+
return [];
|
|
15332
|
+
}
|
|
15333
|
+
var init_slack = __esm(() => {
|
|
15334
|
+
init_validate2();
|
|
15335
|
+
});
|
|
15336
|
+
|
|
13215
15337
|
// node_modules/@desplega.ai/business-use/dist/index.js
|
|
13216
15338
|
function initialize(options) {
|
|
13217
15339
|
if (_state.initialized) {
|
|
@@ -13566,7 +15688,7 @@ var log, BatchProcessor = class {
|
|
|
13566
15688
|
initialized = false;
|
|
13567
15689
|
batchProcessor = null;
|
|
13568
15690
|
}, _state, package_default, version;
|
|
13569
|
-
var
|
|
15691
|
+
var init_dist2 = __esm(() => {
|
|
13570
15692
|
log = {
|
|
13571
15693
|
debug: (msg) => console.log(`[business-use] [${(/* @__PURE__ */ new Date()).toISOString()}] [DEBUG] ${msg}`),
|
|
13572
15694
|
info: (msg) => console.log(`[business-use] [${(/* @__PURE__ */ new Date()).toISOString()}] [INFO] ${msg}`),
|
|
@@ -13659,9 +15781,9 @@ var ensure = (options) => {
|
|
|
13659
15781
|
ensure2({ ...options, data: scrubObject(options.data) });
|
|
13660
15782
|
};
|
|
13661
15783
|
var init_business_use = __esm(() => {
|
|
13662
|
-
|
|
15784
|
+
init_dist2();
|
|
13663
15785
|
init_secret_scrubber();
|
|
13664
|
-
|
|
15786
|
+
init_dist2();
|
|
13665
15787
|
});
|
|
13666
15788
|
|
|
13667
15789
|
// src/slack/closure.ts
|
|
@@ -13703,6 +15825,24 @@ var init_closure = __esm(() => {
|
|
|
13703
15825
|
init_types5();
|
|
13704
15826
|
});
|
|
13705
15827
|
|
|
15828
|
+
// src/ui-spec/fallback.ts
|
|
15829
|
+
async function withUiSpecFallback(taskId, body) {
|
|
15830
|
+
if (!isEnvFlagEnabled("UI_SPEC_ENABLED", false))
|
|
15831
|
+
return body;
|
|
15832
|
+
const stored = await getTaskUiSpec(taskId);
|
|
15833
|
+
if (!stored?.fallbackText)
|
|
15834
|
+
return body;
|
|
15835
|
+
const fallbackText = scrubSecrets(stored.fallbackText);
|
|
15836
|
+
return body ? `${body}
|
|
15837
|
+
|
|
15838
|
+
${fallbackText}` : fallbackText;
|
|
15839
|
+
}
|
|
15840
|
+
var init_fallback = __esm(() => {
|
|
15841
|
+
init_task_ui_spec();
|
|
15842
|
+
init_env_flag();
|
|
15843
|
+
init_secret_scrubber();
|
|
15844
|
+
});
|
|
15845
|
+
|
|
13706
15846
|
// src/slack/task-attachments.ts
|
|
13707
15847
|
async function getSlackOutputAttachments(taskId) {
|
|
13708
15848
|
return (await getTaskAttachments2(taskId)).filter((attachment) => attachment.intent !== "user-upload" && attachment.intent !== "slack-file");
|
|
@@ -13752,7 +15892,7 @@ async function sendInlineTaskOutput(task) {
|
|
|
13752
15892
|
const chunks = formatInlineCompletionOutputChunks({
|
|
13753
15893
|
agentName: agent.name,
|
|
13754
15894
|
taskId: task.id,
|
|
13755
|
-
output: slackTaskOutput(task) ?? ""
|
|
15895
|
+
output: await withUiSpecFallback(task.id, slackTaskOutput(task) ?? "")
|
|
13756
15896
|
});
|
|
13757
15897
|
try {
|
|
13758
15898
|
for (let i = 0;i < chunks.length; i += MAX_INLINE_OUTPUT_BLOCKS_PER_MESSAGE) {
|
|
@@ -13796,7 +15936,7 @@ async function sendTaskResponse(task) {
|
|
|
13796
15936
|
const agentName = agent.name;
|
|
13797
15937
|
try {
|
|
13798
15938
|
if (task.status === "completed") {
|
|
13799
|
-
const output = slackTaskOutput(task) || "Task completed.";
|
|
15939
|
+
const output = await withUiSpecFallback(task.id, slackTaskOutput(task) || "Task completed.");
|
|
13800
15940
|
const slackOutput = markdownToSlack(output);
|
|
13801
15941
|
const attachmentsBlock = formatAttachmentsBlockForSlack(await getSlackOutputAttachments(task.id));
|
|
13802
15942
|
const body = slackOutput + attachmentsBlock;
|
|
@@ -14042,6 +16182,7 @@ function getAgentEmoji(agent) {
|
|
|
14042
16182
|
var isDev, MAX_INLINE_OUTPUT_BLOCKS_PER_MESSAGE = 10;
|
|
14043
16183
|
var init_responses = __esm(() => {
|
|
14044
16184
|
init_db4();
|
|
16185
|
+
init_fallback();
|
|
14045
16186
|
init_app3();
|
|
14046
16187
|
init_blocks();
|
|
14047
16188
|
init_reaction_shortcode();
|
|
@@ -15081,6 +17222,34 @@ function attachmentCaption(attachments) {
|
|
|
15081
17222
|
const destination = url.replace(/[\s\\<>|]/g, encodeURIComponent);
|
|
15082
17223
|
return `\uD83D\uDCCE <${destination}|${label}>`;
|
|
15083
17224
|
}
|
|
17225
|
+
async function outcomeUiSpec(task) {
|
|
17226
|
+
if (!isEnvFlagEnabled("UI_SPEC_ENABLED", false))
|
|
17227
|
+
return null;
|
|
17228
|
+
const stored = await getTaskUiSpec(task.id);
|
|
17229
|
+
if (!stored)
|
|
17230
|
+
return null;
|
|
17231
|
+
return { blocks: taskUiSpecSlackBlocks(stored, task.id), fallbackText: stored.fallbackText };
|
|
17232
|
+
}
|
|
17233
|
+
async function withUiSpecBlockFallback(uiSpec, taskId, send) {
|
|
17234
|
+
if (!uiSpec?.blocks.length)
|
|
17235
|
+
return await send(false);
|
|
17236
|
+
try {
|
|
17237
|
+
return await send(true);
|
|
17238
|
+
} catch (error) {
|
|
17239
|
+
const code = slackErrorCode2(error);
|
|
17240
|
+
if (!code || !UI_SPEC_BLOCK_REJECTION_CODES.has(code))
|
|
17241
|
+
throw error;
|
|
17242
|
+
console.warn(`[Slack] ${code} for the card of task ${taskId}; retrying with its fallback text`);
|
|
17243
|
+
return await send(false);
|
|
17244
|
+
}
|
|
17245
|
+
}
|
|
17246
|
+
function withUiSpecFallbackText(presentation, uiSpec, withCard) {
|
|
17247
|
+
if (!uiSpec || withCard || !uiSpec.fallbackText)
|
|
17248
|
+
return presentation;
|
|
17249
|
+
return `${presentation}
|
|
17250
|
+
|
|
17251
|
+
${uiSpec.fallbackText}`;
|
|
17252
|
+
}
|
|
15084
17253
|
async function outcomeCaptionBlocks(task, content) {
|
|
15085
17254
|
const moreUrl = getTaskUrl(task.id);
|
|
15086
17255
|
const sources = taskCitationSourceGroups(content, await getTaskCitations(task.id)).map((group) => buildCaptionBlock(group.items, { heading: group.heading, moreUrl }));
|
|
@@ -15190,6 +17359,8 @@ async function streamOutcomeCard(task, tree, options) {
|
|
|
15190
17359
|
...await outcomeCaptionBlocks(task, content),
|
|
15191
17360
|
...await outcomeFooter(task, tasks, duration)
|
|
15192
17361
|
];
|
|
17362
|
+
const uiSpec = await outcomeUiSpec(task);
|
|
17363
|
+
const blocksFor = (withCard) => withCard && uiSpec ? [...uiSpec.blocks, ...captions] : captions;
|
|
15193
17364
|
const startPayload = {
|
|
15194
17365
|
channel: task.slackChannelId,
|
|
15195
17366
|
thread_ts: task.slackThreadTs,
|
|
@@ -15235,12 +17406,15 @@ async function streamOutcomeCard(task, tree, options) {
|
|
|
15235
17406
|
started = await callSlackWithRetry2(app.client, "chat.startStream", startPayload);
|
|
15236
17407
|
} catch (error) {
|
|
15237
17408
|
console.error(`[Slack] chat.startStream failed for task ${task.id}; falling back to chat.postMessage:`, error);
|
|
15238
|
-
started = await
|
|
15239
|
-
|
|
15240
|
-
|
|
15241
|
-
|
|
15242
|
-
|
|
15243
|
-
|
|
17409
|
+
started = await withUiSpecBlockFallback(uiSpec, task.id, (withCard) => {
|
|
17410
|
+
const text = withUiSpecFallbackText(presentation, uiSpec, withCard);
|
|
17411
|
+
return callSlackWithRetry2(app.client, "chat.postMessage", {
|
|
17412
|
+
channel: task.slackChannelId,
|
|
17413
|
+
thread_ts: task.slackThreadTs,
|
|
17414
|
+
text,
|
|
17415
|
+
blocks: [{ type: "markdown", text }, ...blocksFor(withCard)],
|
|
17416
|
+
...persona
|
|
17417
|
+
});
|
|
15244
17418
|
});
|
|
15245
17419
|
deliveredViaFallback = true;
|
|
15246
17420
|
}
|
|
@@ -15257,21 +17431,27 @@ async function streamOutcomeCard(task, tree, options) {
|
|
|
15257
17431
|
}
|
|
15258
17432
|
if (!deliveredViaFallback) {
|
|
15259
17433
|
try {
|
|
15260
|
-
await callSlackWithRetry2(app.client, "chat.stopStream", {
|
|
17434
|
+
await withUiSpecBlockFallback(uiSpec, task.id, (withCard) => callSlackWithRetry2(app.client, "chat.stopStream", {
|
|
15261
17435
|
channel: task.slackChannelId,
|
|
15262
17436
|
ts: outcome.ts,
|
|
15263
|
-
|
|
15264
|
-
|
|
17437
|
+
...uiSpec?.fallbackText && !withCard ? { markdown_text: `
|
|
17438
|
+
|
|
17439
|
+
${uiSpec.fallbackText}` } : {},
|
|
17440
|
+
blocks: blocksFor(withCard)
|
|
17441
|
+
}));
|
|
15265
17442
|
} catch (error) {
|
|
15266
17443
|
if (!isStreamAlreadyStopped(error))
|
|
15267
17444
|
throw error;
|
|
15268
17445
|
}
|
|
15269
17446
|
if (!streamedFreshContent) {
|
|
15270
|
-
await
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15274
|
-
|
|
17447
|
+
await withUiSpecBlockFallback(uiSpec, task.id, (withCard) => {
|
|
17448
|
+
const text = withUiSpecFallbackText(presentation, uiSpec, withCard);
|
|
17449
|
+
return callSlackWithRetry2(app.client, "chat.update", {
|
|
17450
|
+
channel: task.slackChannelId,
|
|
17451
|
+
ts: outcome.ts,
|
|
17452
|
+
text,
|
|
17453
|
+
blocks: [{ type: "markdown", text }, ...blocksFor(withCard)]
|
|
17454
|
+
});
|
|
15275
17455
|
});
|
|
15276
17456
|
}
|
|
15277
17457
|
}
|
|
@@ -15292,7 +17472,15 @@ async function resolvedDeferralContent(wake) {
|
|
|
15292
17472
|
const content = await outcomeContent(wake, wake.slackReplySent);
|
|
15293
17473
|
const presentation = await outcomePresentation(wake, content);
|
|
15294
17474
|
const captions = await outcomeCaptionBlocks(wake, content);
|
|
15295
|
-
|
|
17475
|
+
const uiSpec = await outcomeUiSpec(wake);
|
|
17476
|
+
return {
|
|
17477
|
+
uiSpec,
|
|
17478
|
+
build: (withCard) => {
|
|
17479
|
+
const text = withUiSpecFallbackText(presentation, uiSpec, withCard);
|
|
17480
|
+
const card = withCard && uiSpec ? uiSpec.blocks : [];
|
|
17481
|
+
return { text, blocks: [{ type: "markdown", text }, ...card, ...captions] };
|
|
17482
|
+
}
|
|
17483
|
+
};
|
|
15296
17484
|
}
|
|
15297
17485
|
async function isAnsweredByDeferralCard(task, threadTasks) {
|
|
15298
17486
|
const seen = new Set;
|
|
@@ -15343,11 +17531,11 @@ async function refreshResolvedDeferralCards() {
|
|
|
15343
17531
|
if (!wake)
|
|
15344
17532
|
continue;
|
|
15345
17533
|
const content = await resolvedDeferralContent(wake);
|
|
15346
|
-
await callSlackWithRetry2(app.client, "chat.update", {
|
|
17534
|
+
await withUiSpecBlockFallback(content.uiSpec, wake.id, (withCard) => callSlackWithRetry2(app.client, "chat.update", {
|
|
15347
17535
|
channel: card.channelId,
|
|
15348
17536
|
ts: card.ts,
|
|
15349
|
-
...content
|
|
15350
|
-
});
|
|
17537
|
+
...content.build(withCard)
|
|
17538
|
+
}));
|
|
15351
17539
|
if (isDeferredTask(wake)) {
|
|
15352
17540
|
await updateSlackMessageRecord2(card.id, {});
|
|
15353
17541
|
} else {
|
|
@@ -15734,12 +17922,14 @@ async function renderDirtyThreads() {
|
|
|
15734
17922
|
if (touched.wakeTouched)
|
|
15735
17923
|
await refreshResolvedDeferralCards();
|
|
15736
17924
|
}
|
|
15737
|
-
var TREE_UPDATE_DEBOUNCE_MS = 500, TREE_UPDATE_MIN_INTERVAL_MS = 3000, MAX_SLACK_RETRIES = 3, MAX_RETRY_DELAY_MS = 30000, MAX_TITLE_LENGTH = 72, MAX_OUTCOME_MARKDOWN_LENGTH = 12000, MAX_TREE_NODE_LINE_LENGTH = 1000, MAX_TREE_PREFIX_LENGTH = 120, MAX_TREE_PROGRESS_LENGTH = 60, CHILD_CARDS_PER_TICK = 3, CHILD_CARDS_PER_ASK = 10, CONCLUSION_DIGEST_LENGTH = 300, TREE_INDENT, FIGURE_SPACE = " ", SLACK_RENDER_METADATA_EVENT = "agent_swarm_render_v2", treeCreationPromises, pendingTreeUpdates, treeUpdateTails, lastTreeText, lastTreeUpdateAt, cachedTeamId, OUTCOME_DELIVERY_MAX_ATTEMPTS = 5, OUTCOME_DELIVERY_BASE_DELAY_MS = 30000, OUTCOME_DELIVERY_MAX_DELAY_MS, outcomeDeliveryNextAttemptAt, outcomeReservedWithoutAttempt, LINE_START_BLOCK, TRANSIENT_SLACK_ERROR_CODES, DEFERRAL_REFRESH_MAX_ATTEMPTS = 5, deferralRefreshAttempts, SLACK_RENDER_TASK_EVENTS, DIRTY_FLUSH_DEBOUNCE_MS = 500, DIRTY_REVISIT_MS = 3000, dirtyTaskIds, dirtyThreads, renderInFlight = null, renderEventsSubscribed = false, dirtyFlushTimer = null, dirtyFlushAt = 0;
|
|
17925
|
+
var TREE_UPDATE_DEBOUNCE_MS = 500, TREE_UPDATE_MIN_INTERVAL_MS = 3000, MAX_SLACK_RETRIES = 3, MAX_RETRY_DELAY_MS = 30000, MAX_TITLE_LENGTH = 72, MAX_OUTCOME_MARKDOWN_LENGTH = 12000, MAX_TREE_NODE_LINE_LENGTH = 1000, MAX_TREE_PREFIX_LENGTH = 120, MAX_TREE_PROGRESS_LENGTH = 60, CHILD_CARDS_PER_TICK = 3, CHILD_CARDS_PER_ASK = 10, CONCLUSION_DIGEST_LENGTH = 300, TREE_INDENT, FIGURE_SPACE = " ", SLACK_RENDER_METADATA_EVENT = "agent_swarm_render_v2", treeCreationPromises, pendingTreeUpdates, treeUpdateTails, lastTreeText, lastTreeUpdateAt, cachedTeamId, OUTCOME_DELIVERY_MAX_ATTEMPTS = 5, OUTCOME_DELIVERY_BASE_DELAY_MS = 30000, OUTCOME_DELIVERY_MAX_DELAY_MS, outcomeDeliveryNextAttemptAt, outcomeReservedWithoutAttempt, LINE_START_BLOCK, UI_SPEC_BLOCK_REJECTION_CODES, TRANSIENT_SLACK_ERROR_CODES, DEFERRAL_REFRESH_MAX_ATTEMPTS = 5, deferralRefreshAttempts, SLACK_RENDER_TASK_EVENTS, DIRTY_FLUSH_DEBOUNCE_MS = 500, DIRTY_REVISIT_MS = 3000, dirtyTaskIds, dirtyThreads, renderInFlight = null, renderEventsSubscribed = false, dirtyFlushTimer = null, dirtyFlushAt = 0;
|
|
15738
17926
|
var init_render_v2 = __esm(() => {
|
|
15739
17927
|
init_db4();
|
|
15740
17928
|
init_slack_trees();
|
|
15741
17929
|
init_task_citations2();
|
|
17930
|
+
init_task_ui_spec();
|
|
15742
17931
|
init_context_key();
|
|
17932
|
+
init_slack();
|
|
15743
17933
|
init_business_use();
|
|
15744
17934
|
init_env_flag();
|
|
15745
17935
|
init_secret_scrubber();
|
|
@@ -15765,6 +17955,11 @@ var init_render_v2 = __esm(() => {
|
|
|
15765
17955
|
outcomeDeliveryNextAttemptAt = new Map;
|
|
15766
17956
|
outcomeReservedWithoutAttempt = new Set;
|
|
15767
17957
|
LINE_START_BLOCK = /^(?:`{3}|~{3}|[-*+]\s|\d+[.)]\s|>|#{1,6}\s|\||(?:-{3,}|\*{3,}|_{3,})[ \t]*(?:\r?\n|$)|(?: {4}|\t))/;
|
|
17958
|
+
UI_SPEC_BLOCK_REJECTION_CODES = new Set([
|
|
17959
|
+
"invalid_blocks",
|
|
17960
|
+
"invalid_blocks_format",
|
|
17961
|
+
"msg_blocks_too_long"
|
|
17962
|
+
]);
|
|
15768
17963
|
TRANSIENT_SLACK_ERROR_CODES = new Set([
|
|
15769
17964
|
"ratelimited",
|
|
15770
17965
|
"rate_limited",
|
|
@@ -16567,32 +18762,33 @@ async function initSlackApp2() {
|
|
|
16567
18762
|
});
|
|
16568
18763
|
inboundDrain = installSocketAckRecovery(receiver.client, app);
|
|
16569
18764
|
}
|
|
16570
|
-
const
|
|
18765
|
+
const created = app;
|
|
18766
|
+
const authClient = created.client;
|
|
16571
18767
|
const enterpriseInstall = isSlackEnterpriseInstall();
|
|
16572
18768
|
setSlackWorkspaceIdentitySource(() => resolveSlackIdentity(authClient, enterpriseInstall));
|
|
16573
18769
|
if (receiver)
|
|
16574
18770
|
installSocketWorkspaceGate(receiver.client);
|
|
16575
18771
|
initialized2 = true;
|
|
16576
|
-
|
|
18772
|
+
created.use(slackInboundOutcomeMiddleware(config.mode === "http" ? "http" : "socket"));
|
|
16577
18773
|
if (config.mode === "http")
|
|
16578
|
-
|
|
16579
|
-
const { registerMessageHandler } = await import("./handlers-
|
|
16580
|
-
const { registerCommandHandler } = await import("./commands-
|
|
16581
|
-
const { registerActionHandlers } = await import("./actions-
|
|
16582
|
-
const { registerWorkObjectHandlers } = await import("./work-objects-
|
|
16583
|
-
registerMessageHandler(
|
|
16584
|
-
registerCommandHandler(
|
|
16585
|
-
registerActionHandlers(
|
|
16586
|
-
registerWorkObjectHandlers(
|
|
16587
|
-
const { createAssistant } = await import("./assistant-
|
|
16588
|
-
|
|
16589
|
-
const { isBlockExternalEnabled, scanExternalChannelsOnBoot } = await import("./external-channel-
|
|
18774
|
+
created.use(ignoreSelfAsIgnored);
|
|
18775
|
+
const { registerMessageHandler } = await import("./handlers-yzy0c87x.js");
|
|
18776
|
+
const { registerCommandHandler } = await import("./commands-gwea8z5p.js");
|
|
18777
|
+
const { registerActionHandlers } = await import("./actions-b9qgrmeq.js");
|
|
18778
|
+
const { registerWorkObjectHandlers } = await import("./work-objects-4aghh73z.js");
|
|
18779
|
+
registerMessageHandler(created);
|
|
18780
|
+
registerCommandHandler(created);
|
|
18781
|
+
registerActionHandlers(created);
|
|
18782
|
+
registerWorkObjectHandlers(created);
|
|
18783
|
+
const { createAssistant } = await import("./assistant-2cgfxsgk.js");
|
|
18784
|
+
created.assistant(createAssistant());
|
|
18785
|
+
const { isBlockExternalEnabled, scanExternalChannelsOnBoot } = await import("./external-channel-1ac6t56s.js");
|
|
16590
18786
|
if (isBlockExternalEnabled()) {
|
|
16591
|
-
scanExternalChannelsOnBoot(
|
|
18787
|
+
scanExternalChannelsOnBoot(created.client).catch((error) => {
|
|
16592
18788
|
console.error("[Slack] External channel boot scan failed:", error);
|
|
16593
18789
|
});
|
|
16594
18790
|
}
|
|
16595
|
-
return
|
|
18791
|
+
return created;
|
|
16596
18792
|
}
|
|
16597
18793
|
async function startSlackApp2() {
|
|
16598
18794
|
const generation = lifecycleGeneration;
|
|
@@ -16614,7 +18810,7 @@ async function startSlackApp2() {
|
|
|
16614
18810
|
startRetryAttempt = 0;
|
|
16615
18811
|
if (!httpReceiver)
|
|
16616
18812
|
startSocketWatchdog();
|
|
16617
|
-
const { isSlackRenderV2Enabled } = await import("./render-v2-
|
|
18813
|
+
const { isSlackRenderV2Enabled } = await import("./render-v2-nx20t3rb.js");
|
|
16618
18814
|
if (isSlackRenderV2Enabled())
|
|
16619
18815
|
await ensureSlackRenderV2Activation2();
|
|
16620
18816
|
await recoverSlackInboundAfterRestart();
|
|
@@ -16630,7 +18826,7 @@ async function startSlackApp2() {
|
|
|
16630
18826
|
} else {
|
|
16631
18827
|
console.log("[Slack] Bot connected via Socket Mode");
|
|
16632
18828
|
}
|
|
16633
|
-
const { restoreBufferedSlackMessages } = await import("./thread-buffer-
|
|
18829
|
+
const { restoreBufferedSlackMessages } = await import("./thread-buffer-a1re2r9r.js");
|
|
16634
18830
|
await restoreBufferedSlackMessages().catch((error) => {
|
|
16635
18831
|
console.error("[Slack] Failed to restore buffered thread messages:", error);
|
|
16636
18832
|
});
|
|
@@ -16646,7 +18842,7 @@ async function startSlackApp2() {
|
|
|
16646
18842
|
async function verifySlackIdentity(current) {
|
|
16647
18843
|
if (!await getSlackWorkspaceIdentity())
|
|
16648
18844
|
return false;
|
|
16649
|
-
if (
|
|
18845
|
+
if (boltInitializedApp === current)
|
|
16650
18846
|
return true;
|
|
16651
18847
|
try {
|
|
16652
18848
|
await current.init();
|
|
@@ -16655,7 +18851,7 @@ async function verifySlackIdentity(current) {
|
|
|
16655
18851
|
console.error(`[Slack] Bolt initialization failed: ${message}`);
|
|
16656
18852
|
return false;
|
|
16657
18853
|
}
|
|
16658
|
-
|
|
18854
|
+
boltInitializedApp = current;
|
|
16659
18855
|
return true;
|
|
16660
18856
|
}
|
|
16661
18857
|
function clearStartRetry() {
|
|
@@ -16724,7 +18920,7 @@ function detachSlackApp() {
|
|
|
16724
18920
|
lifecycleGeneration += 1;
|
|
16725
18921
|
clearStartRetry();
|
|
16726
18922
|
startRetryAttempt = 0;
|
|
16727
|
-
|
|
18923
|
+
boltInitializedApp = null;
|
|
16728
18924
|
stopTaskWatcher();
|
|
16729
18925
|
inboundDrain?.stop();
|
|
16730
18926
|
inboundDrain = null;
|
|
@@ -16738,7 +18934,7 @@ function detachSlackApp() {
|
|
|
16738
18934
|
initialized2 = false;
|
|
16739
18935
|
return detached;
|
|
16740
18936
|
}
|
|
16741
|
-
var import_bolt6, app = null, receiver = null, httpReceiver = null, initialized2 = false, inboundDrain = null, socketFence = null, lifecycleGeneration = 0, lastSocketActivityAt = null, DEFAULT_START_RETRY_DELAYS_MS, startRetryDelaysMs, startRetryTimer = null, startRetryAttempt = 0,
|
|
18937
|
+
var import_bolt6, app = null, receiver = null, httpReceiver = null, initialized2 = false, inboundDrain = null, socketFence = null, lifecycleGeneration = 0, lastSocketActivityAt = null, DEFAULT_START_RETRY_DELAYS_MS, startRetryDelaysMs, startRetryTimer = null, startRetryAttempt = 0, boltInitializedApp = null, SOCKET_EVENT_STATES, SLACK_SOCKET_WATCHDOG_DEFAULTS, watchdogTimer = null, watchdogOptions;
|
|
16742
18938
|
var init_app3 = __esm(() => {
|
|
16743
18939
|
init_db4();
|
|
16744
18940
|
init_node_env();
|
|
@@ -16777,4 +18973,4 @@ var init_app3 = __esm(() => {
|
|
|
16777
18973
|
watchdogOptions = SLACK_SOCKET_WATCHDOG_DEFAULTS;
|
|
16778
18974
|
});
|
|
16779
18975
|
|
|
16780
|
-
export { require_dist4, require_dist5, getSlackConnectionState, init_connection_state, noteSlackInboundSideEffect, ignoreSlackInbound, reportSlackInboundFailure, isAdmittedSlackDelivery, getSlackInboundDiagnostics, init_inbound_dispatch, runSlackLifecycleExclusive, init_lifecycle_lock, terminalReactionEvent, init_reaction_events, isPollTracingEnabled, initOtel, withSpan2, startSpan2, withSpanContext2, withRemoteContext2, injectTraceContext2, recordSessionCost2, recordDbRetentionSweep2, recordDbRetentionStatement2, init_otel, slackTaskOutput, init_task_output, ackSlackMessage, skipSlackMessageReaction, finalizeTerminalSlackReactions, init_ack, getTaskLink, getTaskUrl, markdownToSlack, buildMrkdwnSectionBlocks, buildCaptionBlock, buildCancelledBlocks, buildBufferFlushBlocks, buildTreeBlocks, init_blocks, taskCitationIssues, stripInvalidTaskCitations, taskCitationSourceGroups, renderTaskCitations, taskCitationWarnings, init_task_citations, MAX_TASK_CITATIONS, CitationInputSchema, TaskCitationSchema, upsertTaskCitations, getTaskCitations, getTaskCitationsForTasks, hasTaskCitationCheckRefusal, init_task_citations2, initialize, ensure, init_business_use, getAgentDisplayName, getAgentSlackIcon, init_responses, markSlackSessionProcessing, init_session_status, isSlackRenderV2Enabled2, callSlackWithRetry2, ensureSlackThreadTree2, slackErrorCode2, startSlackRenderV2Events2, stopSlackRenderV2Events2, processSlackRenderV22, init_render_v2, registerTreeMessage, init_watcher, getSlackApp2, getSlackHttpReceiver2, initSlackApp2, startSlackApp2, stopSlackApp2, stopSlackAppUnderLifecycleLock2, init_app3 };
|
|
18976
|
+
export { require_dist4, require_dist5, getSlackConnectionState, init_connection_state, noteSlackInboundSideEffect, ignoreSlackInbound, reportSlackInboundFailure, isAdmittedSlackDelivery, getSlackInboundDiagnostics, init_inbound_dispatch, runSlackLifecycleExclusive, init_lifecycle_lock, terminalReactionEvent, init_reaction_events, isPollTracingEnabled, initOtel, withSpan2, startSpan2, withSpanContext2, withRemoteContext2, injectTraceContext2, recordSessionCost2, recordDbRetentionSweep2, recordDbRetentionStatement2, init_otel, slackTaskOutput, init_task_output, ackSlackMessage, skipSlackMessageReaction, finalizeTerminalSlackReactions, init_ack, getTaskLink, getTaskUrl, markdownToSlack, buildMrkdwnSectionBlocks, buildCaptionBlock, buildCancelledBlocks, buildBufferFlushBlocks, buildTreeBlocks, init_blocks, taskCitationIssues, stripInvalidTaskCitations, taskCitationSourceGroups, renderTaskCitations, taskCitationWarnings, init_task_citations, MAX_TASK_CITATIONS, CitationInputSchema, TaskCitationSchema, upsertTaskCitations, getTaskCitations, getTaskCitationsForTasks, hasTaskCitationCheckRefusal, init_task_citations2, TaskUiSpecSchema, getTaskUiSpec, getTaskUiSpecsForTasks, upsertTaskUiSpec, reserveTaskUiActionRun, releaseTaskUiActionRun, setTaskUiActionResult, hasTaskUiSpecCheckRefusal, init_task_ui_spec, standardComponentDefinitions, CardSpecError, toCard, init_dist5, UI_SPEC_ACTION_PREFIX, UI_SPEC_ACTION_ID, UI_SPEC_CARD_LIMITS, init_task_ui_spec2, validateTaskUiSpec, init_validate2, initialize, ensure, init_business_use, withUiSpecFallback, init_fallback, getAgentDisplayName, getAgentSlackIcon, init_responses, markSlackSessionProcessing, init_session_status, isSlackRenderV2Enabled2, callSlackWithRetry2, ensureSlackThreadTree2, slackErrorCode2, startSlackRenderV2Events2, stopSlackRenderV2Events2, processSlackRenderV22, init_render_v2, registerTreeMessage, init_watcher, getSlackApp2, getSlackHttpReceiver2, initSlackApp2, startSlackApp2, stopSlackApp2, stopSlackAppUnderLifecycleLock2, init_app3 };
|