{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stack-trace-vue",
  "title": "Stack Trace (Vue)",
  "description": "An error's name, message and frames, with library frames folded and each frame able to open its file.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/vue@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/vue/stack-trace.ts",
      "content": "import { type StackTraceRow, type StackTraceState, stackTracePrimitive } from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/vue/primitive\";\nimport { type Component, defineComponent, h, type Slot, type VNode } from \"vue\";\n\n// `@ui-sdk/vue`'s `createParts` hands the primitive an emitter for every callback, whether or not anything listens, so\n// `onOpenFrame`, whose presence makes each frame a button, is declared a function prop instead, which `@open-frame`\n// binds.\nconst primitive = Object.defineProperty(\n  Object.assign((options: never) => stackTracePrimitive(options), stackTracePrimitive, {\n    options: { ...stackTracePrimitive.options, onOpenFrame: \"action\" },\n  }),\n  \"name\",\n  { value: stackTracePrimitive.name },\n) as typeof stackTracePrimitive;\n\n// `$stable` tells Vue these slots never change, so a part that renders again doesn't render the parts inside it.\nconst stable = (slot: () => unknown) => ({ default: slot, $stable: true });\n\nconst parts = createParts(primitive, {\n  root: \"div\",\n  trigger: \"button\",\n  icon: \"span\",\n  title: \"span\",\n  content: \"div\",\n  message: \"div\",\n  copy: \"button\",\n  list: \"ol\",\n  frame: \"li\",\n  \"frame-open\": \"button\",\n  \"frame-function\": \"span\",\n  \"frame-location\": \"span\",\n  group: \"li\",\n  library: \"button\",\n  \"library-frames\": \"ol\",\n});\n\n// Slot state is a proxy that answers reads, so fallbacks read each key they need.\ntype PartState = StackTraceState & {\n  text: string;\n  fn: string;\n  location: string;\n  count: number;\n  indexes: number[];\n};\n\n// A part whose default slot falls back to content built from its state.\nfunction withDefault<C extends Component>(part: C, name: string, fallback: (state: PartState) => unknown) {\n  return defineComponent({\n    name,\n    inheritAttrs: false,\n    setup(_, { attrs, slots }) {\n      const fill: Slot = ({ state }) => fallback(state) as VNode[];\n      return () => h(part, attrs, { ...slots, default: slots.default ?? fill });\n    },\n  }) as unknown as C;\n}\n\nexport const StackTraceTrigger = parts.Trigger;\nexport const StackTraceIcon = parts.Icon;\nexport const StackTraceContent = parts.Content;\nexport const StackTraceCopy = parts.Copy;\n/** The frame's function and location as a button, rendered only while `onOpenFrame` is set. */\nexport const StackTraceFrameOpen = parts.FrameOpen;\n\n/** The `label`, else the message's first line with the error's name set apart, unless you fill the default slot. */\nexport const StackTraceTitle = withDefault(parts.Title, \"StackTraceTitle\", (state) => {\n  const { name, summary } = state;\n  return name ? [h(\"span\", { \"data-stack-trace-name\": \"\" }, name), \": \", summary] : summary;\n});\n\n/** The message's lines after its first, unless you fill the default slot. Rendered only while there are any. */\nexport const StackTraceMessage = withDefault(parts.Message, \"StackTraceMessage\", (state) => state.text);\n\n/** The frame's function, unless you fill the default slot. */\nexport const StackTraceFrameFunction = withDefault(\n  parts.FrameFunction,\n  \"StackTraceFrameFunction\",\n  (state) => state.fn,\n);\n\n/** The frame's file, shortened to its last two segments, with line and column, unless you fill the default slot. */\nexport const StackTraceFrameLocation = withDefault(\n  parts.FrameLocation,\n  \"StackTraceFrameLocation\",\n  (state) => state.location,\n);\n\nconst frameText = () => [h(StackTraceFrameFunction), h(StackTraceFrameLocation)];\n\n/**\n * The frame whose index is `value`. Without a default slot, it shows the frame's function and location, inside a\n * `StackTraceFrameOpen` while `on-open-frame` is set.\n */\nexport const StackTraceFrame = withDefault(parts.Frame, \"StackTraceFrame\", (state) =>\n  state.canOpen ? h(StackTraceFrameOpen, null, frameText) : frameText(),\n);\n\n/** Shows or folds library frames. \"N library frames\", unless you fill the default slot. */\nexport const StackTraceLibrary = withDefault(parts.Library, \"StackTraceLibrary\", (state) => {\n  const count = state.count;\n  return `${count} library ${count === 1 ? \"frame\" : \"frames\"}`;\n});\n\n/** A group's frames, which open in place, unless you fill the default slot. */\nexport const StackTraceLibraryFrames = withDefault(parts.LibraryFrames, \"StackTraceLibraryFrames\", (state) =>\n  state.indexes.map((index) => h(StackTraceFrame, { key: index, value: String(index) })),\n);\n\n/**\n * The library frames that start at the index `value`, folded into one row. Without a default slot, it shows a\n * `StackTraceLibrary` toggle and the frames.\n */\nexport const StackTraceGroup = withDefault(parts.Group, \"StackTraceGroup\", () => [\n  h(StackTraceLibrary),\n  h(StackTraceLibraryFrames),\n]);\n\n/** A frame for each app frame and a group for each run of library frames, unless you fill the default slot. */\nexport const StackTraceList = withDefault(parts.List, \"StackTraceList\", (state) =>\n  state.rows.map((row: StackTraceRow) =>\n    row.type === \"frame\"\n      ? h(StackTraceFrame, { key: row.index, value: String(row.index) })\n      : h(StackTraceGroup, { key: `library-${row.start}`, value: String(row.start) }),\n  ),\n);\n\n/**\n * An error as a step: its name and message, then its frames, with consecutive library frames folded into one row.\n * A default slot replaces the default parts.\n */\nexport const StackTrace = withDefault(parts.Root, \"StackTrace\", () => [\n  h(\n    StackTraceTrigger,\n    null,\n    stable(() => [h(StackTraceIcon), h(StackTraceTitle)]),\n  ),\n  h(\n    StackTraceContent,\n    null,\n    stable(() =>\n      h(\"div\", { \"data-stack-trace-panel\": \"\", \"data-kind-code\": \"\" }, [\n        h(StackTraceMessage),\n        h(StackTraceList),\n        h(StackTraceCopy),\n      ]),\n    ),\n  ),\n]);\n",
      "type": "registry:ui",
      "target": "@ui/vue/stack-trace.ts"
    }
  ],
  "meta": {
    "layer": "vue"
  },
  "type": "registry:ui"
}
