sygnal 6.2.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +3 -1
  3. package/dist/ai.cjs.js +36 -0
  4. package/dist/ai.cjs.js.map +1 -1
  5. package/dist/ai.esm.js +1 -1
  6. package/dist/astro/server.cjs.js +3 -3
  7. package/dist/astro/server.cjs.js.map +1 -1
  8. package/dist/astro/server.mjs +3 -3
  9. package/dist/astro/server.mjs.map +1 -1
  10. package/dist/diagnostics.cjs.js +164 -3
  11. package/dist/diagnostics.cjs.js.map +1 -1
  12. package/dist/diagnostics.esm.js +164 -3
  13. package/dist/diagnostics.esm.js.map +1 -1
  14. package/dist/guide/agent.md +7 -1
  15. package/dist/guide/ai-cards.md +319 -0
  16. package/dist/guide/ai-chat.md +4 -0
  17. package/dist/guide/ai-compose.md +881 -0
  18. package/dist/guide/ai-decisions.md +16 -0
  19. package/dist/guide/http.md +1 -0
  20. package/dist/index.cjs.js +5695 -347
  21. package/dist/index.cjs.js.map +1 -1
  22. package/dist/index.d.ts +638 -8
  23. package/dist/index.esm.js +5685 -347
  24. package/dist/index.esm.js.map +1 -1
  25. package/dist/sygnal.min.js +1 -1
  26. package/dist/sygnal.min.js.map +1 -1
  27. package/dist/vike/config/package.json +1 -1
  28. package/dist/vike/onRenderClient.cjs.js +3 -2
  29. package/dist/vike/onRenderClient.cjs.js.map +1 -1
  30. package/dist/vike/onRenderClient.mjs +3 -2
  31. package/dist/vike/onRenderClient.mjs.map +1 -1
  32. package/llms.txt +6 -4
  33. package/package.json +2 -1
  34. package/src/ai.d.ts +642 -7
  35. package/src/ai.ts +6 -0
  36. package/src/collection.ts +2 -1
  37. package/src/core/instance.ts +6 -3
  38. package/src/core/markers/lazy.ts +7 -3
  39. package/src/core/markers/portal.ts +5 -2
  40. package/src/core/markers/suspense.ts +3 -2
  41. package/src/core/markers/transition.ts +6 -3
  42. package/src/core/registry.ts +9 -5
  43. package/src/cycle/dom/IsolateModule.ts +25 -22
  44. package/src/extra/ai/chat/behavior.ts +354 -81
  45. package/src/extra/ai/chat/driver.ts +7 -4
  46. package/src/extra/ai/compose/agent.ts +55 -0
  47. package/src/extra/ai/compose/ask.ts +147 -0
  48. package/src/extra/ai/compose/behavior.ts +183 -0
  49. package/src/extra/ai/compose/catalog.ts +211 -0
  50. package/src/extra/ai/compose/composed.ts +61 -0
  51. package/src/extra/ai/compose/decisions.ts +1649 -0
  52. package/src/extra/ai/compose/diag.ts +33 -0
  53. package/src/extra/ai/compose/index.ts +23 -0
  54. package/src/extra/ai/compose/layout.ts +441 -0
  55. package/src/extra/ai/compose/llm.ts +1120 -0
  56. package/src/extra/ai/compose/render.ts +159 -0
  57. package/src/extra/ai/compose/testing.ts +71 -0
  58. package/src/extra/ai/compose/types.ts +159 -0
  59. package/src/extra/ai/decide.ts +97 -1
  60. package/src/extra/ai/index.ts +6 -1
  61. package/src/extra/diagnostics/checks/next.ts +86 -2
  62. package/src/extra/diagnostics/codes.ts +54 -0
  63. package/src/extra/fetchDriver.ts +58 -27
  64. package/src/extra/lens.ts +15 -0
  65. package/src/extra/ssr.ts +3 -3
  66. package/src/extra/testing.ts +2 -0
  67. package/src/extra/widget.ts +3 -3
  68. package/src/index.d.ts +41 -0
  69. package/src/index.ts +8 -0
  70. package/src/lazy.ts +3 -2
  71. package/src/portal.ts +5 -2
  72. package/src/pragma/index.ts +2 -1
  73. package/src/suspense.ts +5 -2
  74. package/src/switchable.ts +2 -1
  75. package/src/transition.ts +5 -2
  76. package/src/vike/onRenderClient.ts +3 -2
@@ -0,0 +1,61 @@
1
+ /*
2
+ * PLAN-9 M-1 (D466): `<Composed catalog={catalog} from="page" />`, catalog.render as a JSX tag.
3
+ * A template rewrite (registry `pres`, as Portal and Transition; no host): in the owner's
4
+ * reconcile walk the marker is replaced by `catalog.render(slice, state, opts)` on the owner's own
5
+ * state, so the parts are the owner's children with the same identity as `{catalog.render(...)}`
6
+ * in its view (CHILD.select, lenses, keys and container views behave the same).
7
+ * - `from`: a state key ('page', the default) or a path (['boards', 0, 'page']); it is `at`.
8
+ * - `card={part}`: an `ask_user` tool part's card, as askCard() renders it (`from` is then the
9
+ * chat's key, default 'assistant'); nothing while the card has no layout.
10
+ * - `scope`, `frozen`, `answer`: as catalog.render's options.
11
+ * - Error containment: a container view or part `props()` that throws replaces only the
12
+ * composition with the owner's `onError` (SYG408), where `{catalog.render(...)}` in a view shows a
13
+ * `.compose-error` element (SYG406).
14
+ * - Misuse (SYG451, dev): no catalog, or `from` not naming a composition slice: nothing rendered.
15
+ * - Registration (G-751): the pragma calls `Composed.$reg` when a tag uses it, so an app that never
16
+ * renders `<Composed>` ships none of this. The marker reads the owner's state cell: a composition
17
+ * computed in the view needs catalog.render().
18
+ */
19
+ import {pres} from '../../../core/registry'
20
+ import {renderLayout, cardArgs} from './render'
21
+ import {dev} from './diag'
22
+
23
+ const EMPTY = () => ({sel: undefined, data: {}, children: [], text: undefined, elm: undefined, key: undefined})
24
+ const misuse = (owner: any, msg: string) => (dev('SYG451', owner.def.name, '<Composed> ' + msg + ': nothing rendered', 'warn', owner, msg), EMPTY())
25
+
26
+ function rewrite(n: any, owner: any): any {
27
+ // a lowercase <composed> element (no marker function) is left as it is
28
+ if (!n.data?.m) return n
29
+ const {catalog, from, card, scope, frozen, answer} = n.data.props || {}
30
+ if (typeof catalog?.render != 'function') return misuse(owner, 'has no catalog')
31
+ const state = owner.cell.get()
32
+ let slice: any, opts: any
33
+ if (card !== undefined) {
34
+ if (!card || typeof card != 'object' || !card.toolCallId) return misuse(owner, 'card is not a tool part')
35
+ const c = cardArgs(state, card, from)
36
+ if (!c) return EMPTY()
37
+ ;[slice, opts] = c
38
+ } else {
39
+ const at = Array.isArray(from) ? from : [from ?? 'page']
40
+ slice = at.reduce((x: any, k: any) => x?.[k], state)
41
+ if (!slice || typeof slice != 'object' || !('layout' in slice || 'preview' in slice)) {
42
+ return misuse(owner, `from=${JSON.stringify(from ?? 'page')} is not a composition`)
43
+ }
44
+ opts = {at}
45
+ }
46
+ if (scope !== undefined) opts.scope = scope
47
+ if (frozen !== undefined) opts.frozen = frozen
48
+ if (answer !== undefined) opts.answer = answer
49
+ try { return renderLayout(catalog, slice, state, opts, false) || EMPTY() }
50
+ catch (e) { return owner.failed(e).outv }
51
+ }
52
+
53
+ const reg = () => { pres.composed = rewrite }
54
+
55
+ /** `<Composed catalog={catalog} from="page" />`: the composition's parts as the owner's children */
56
+ export function Composed(_props: any): any {
57
+ // never called: the pragma makes a `composed` marker vnode (preventInstantiation)
58
+ }
59
+ (Composed as any).componentName = 'composed';
60
+ (Composed as any).preventInstantiation = true;
61
+ (Composed as any).$reg = reg;