paseo-dsh 0.2.15 → 0.2.16

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.
@@ -7,5 +7,4 @@ declare module "react-native" {
7
7
  export const View: any;
8
8
  export const Text: any;
9
9
  export const Pressable: any;
10
- export const Platform: { readonly OS: "ios" | "android" | "web" | "windows" | "macos" };
11
10
  }
@@ -1,10 +1,7 @@
1
1
  import type { PluginClientContext, PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
- import { useSettings } from "@getpaseo/plugin/client";
3
- import { Fragment, useLayoutEffect, useRef, useState } from "react";
2
+ import { Fragment, useState } from "react";
4
3
  import { Pressable, Text, View } from "react-native";
5
4
  import { z } from "zod";
6
- import { DEFAULT_STREAM_STATS, streamStatsSettings } from "../shared/settings";
7
- import { measureFooterLift, watchFooter } from "./web";
8
5
 
9
6
  export const streamStatsSchema = z.object({
10
7
  firstTokenMs: z.number().optional(),
@@ -23,38 +20,10 @@ export const streamStatsSchema = z.object({
23
20
  steps: z.number().optional(),
24
21
  sessionTokens: z.number().optional(),
25
22
  cacheHit: z.number().optional(),
26
- /** Last stats row of a turn: Paseo puts its completed-turn footer above it. */
27
- final: z.boolean().optional(),
28
23
  });
29
24
 
30
25
  type StreamStats = z.infer<typeof streamStatsSchema>;
31
26
 
32
- /**
33
- * Paseo draws the completed-turn footer — copy / model / time — directly under
34
- * the answer and keeps its own bottom padding free under it, while this row is
35
- * an ordinary timeline item spaced by the host's item gap. Neither number is
36
- * ours to rely on: a theme plugin restyles that footer, and the same footer is
37
- * also drawn under turns that are no longer the newest, where the host's
38
- * margins differ (the row sits 35px under the footer while its turn is latest,
39
- * 23px once a newer turn arrives).
40
- *
41
- * On web the row measures the footer actually painted above it (in `./web`,
42
- * the only client file allowed to touch the DOM) and lifts itself to the gap
43
- * the user chose in Settings → Plugins. Native has no DOM to measure; it keeps
44
- * the geometry the host's footer was tuned for.
45
- */
46
- /** Paseo's `SPACING[8]` (`TURN_FOOTER_BOTTOM_SPACING`): the footer's bottom padding. */
47
- const TURN_FOOTER_BOTTOM_PADDING = 32;
48
- /**
49
- * The furthest the row may pull up. Measured gaps can exceed Paseo's own 32px
50
- * footer padding once a theme restyles the footer, so the cap is twice that:
51
- * generous enough for themed footers, still bounded so a mis-measure cannot
52
- * drag the row across the answer.
53
- */
54
- const MAX_ROW_LIFT = -2 * TURN_FOOTER_BOTTOM_PADDING;
55
- /** Paseo's footer sets its text in a 18px line box at 13px. */
56
- const LINE_HEIGHT_RATIO = 18 / 13;
57
-
58
27
  function formatLatency(ms: number): string {
59
28
  return ms < 1000 ? `${Math.round(ms)}ms` : `${(ms / 1000).toFixed(1)}s`;
60
29
  }
@@ -101,60 +70,10 @@ function toolsLine(data: StreamStats): string | undefined {
101
70
  /** One compact line under an answer; tap to expand the full picture. */
102
71
  function StreamStatsRow({ item, theme, layout }: PluginTimelineItemProps<StreamStats>) {
103
72
  const [open, setOpen] = useState(false);
104
- const [lift, setLift] = useState(0);
105
- const rowRef = useRef<unknown>(null);
106
- /** The lift currently in the DOM, which the next measurement has to discount. */
107
- const appliedLift = useRef(0);
108
- const settings = useSettings(streamStatsSettings);
109
- const gap = settings.status === "ready" ? settings.values.gapPx : DEFAULT_STREAM_STATS.gapPx;
110
- const fontSize = settings.status === "ready" ? settings.values.fontSize : DEFAULT_STREAM_STATS.fontSize;
111
73
  const data = item.data;
112
-
113
- // The ref must describe the margin the DOM actually carries, not the one a
114
- // pending render is about to apply: a ResizeObserver callback between
115
- // `setLift` and its commit would otherwise discount a lift the frame has not
116
- // moved by yet and measure against the wrong origin.
117
- useLayoutEffect(() => {
118
- appliedLift.current = lift;
119
- }, [lift]);
120
-
121
- const applyLift = (next: number) => {
122
- if (appliedLift.current === next) return;
123
- setLift(next);
124
- };
125
-
126
- // The footer above this row is the host's markup and, with a theme plugin
127
- // installed, that plugin's restyling of it — so its height and padding are
128
- // measured instead of assumed. Everything DOM lives in `./web`; off web it
129
- // reports nothing, the row keeps the host's own gap, and native falls back to
130
- // the constant `nativeLift` below.
131
- useLayoutEffect(() => {
132
- if (data.final !== true) {
133
- applyLift(0);
134
- return;
135
- }
136
- const measure = () => {
137
- const next = measureFooterLift(rowRef.current, {
138
- appliedLift: appliedLift.current,
139
- gap,
140
- maxLift: MAX_ROW_LIFT,
141
- });
142
- applyLift(next ?? 0);
143
- };
144
- measure();
145
- const stop = watchFooter(rowRef.current, measure);
146
- return stop ?? undefined;
147
- // `applyLift` only reads refs and a state setter, so the values that can
148
- // change what is measured are the only dependencies.
149
- }, [data.final, gap]);
150
-
74
+ const fontSize = layout.compact ? 10 : 11;
151
75
  const muted = theme.colors.foregroundMuted;
152
- const base = {
153
- color: muted,
154
- fontSize,
155
- lineHeight: Math.round(fontSize * LINE_HEIGHT_RATIO),
156
- fontVariant: ["tabular-nums"] as const,
157
- };
76
+ const base = { color: muted, fontSize, fontVariant: ["tabular-nums"] as const };
158
77
 
159
78
  const ratio = contextRatio(data);
160
79
  const segments: Array<{ text: string; color: string }> = [];
@@ -178,20 +97,13 @@ function StreamStatsRow({ item, theme, layout }: PluginTimelineItemProps<StreamS
178
97
  const details = [contextLine(data), tokensLine(data), routeLine(data), toolsLine(data)].filter(
179
98
  (line): line is string => line !== undefined,
180
99
  );
181
- const nativeLift = gap - TURN_FOOTER_BOTTOM_PADDING;
182
100
 
183
101
  return (
184
102
  <Pressable
185
- ref={rowRef}
186
103
  accessibilityRole="button"
187
104
  accessibilityLabel={open ? "收起回答统计" : "展开回答统计"}
188
105
  onPress={() => setOpen((value) => !value)}
189
- style={{
190
- alignSelf: "flex-start",
191
- marginTop: data.final === true ? (layout.platform === "web" ? lift : nativeLift) : 0,
192
- marginBottom: 0,
193
- paddingLeft: 2,
194
- }}
106
+ style={{ alignSelf: "flex-start", marginTop: 0, marginBottom: 0, paddingLeft: 2 }}
195
107
  >
196
108
  <View style={{ flexDirection: "row", alignItems: "center", flexWrap: "wrap" }}>
197
109
  {segments.map((segment, index) => (
package/index.client.tsx CHANGED
@@ -1,17 +1,6 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
- import { StreamStatsSettingsScreen } from "./client/settings-screen";
3
2
  import { contributeStreamStats } from "./client/stream-stats";
4
3
 
5
4
  export default function contribute(client: PluginClientContext) {
6
- const removeStats = contributeStreamStats(client);
7
- const removeSettings = client.addSettingsScreen({
8
- id: "stream-stats",
9
- title: "回答统计行",
10
- icon: "SlidersHorizontal",
11
- Component: StreamStatsSettingsScreen,
12
- });
13
- return () => {
14
- removeStats();
15
- removeSettings();
16
- };
5
+ return contributeStreamStats(client);
17
6
  }
package/index.server.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { PluginServerContext } from "@getpaseo/plugin/server";
2
2
  import { ensurePaseoProfile } from "./server/bootstrap";
3
3
  import { createDshProvider } from "./server/provider";
4
- import { streamStatsSettings } from "./shared/settings";
5
4
 
6
5
  /**
7
6
  * Register the DeepSeek Harness provider, provisioning the DSH profile it needs.
@@ -25,7 +24,6 @@ export default function contribute(server: PluginServerContext) {
25
24
  );
26
25
  }
27
26
 
28
- server.registerSettings(streamStatsSettings);
29
27
  server.registerProvider(createDshProvider());
30
28
  return () => {};
31
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-dsh",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "DeepSeek Harness (dsh) as a native Paseo provider: question cards, plan mode, thinking levels, steering, images and a real slash menu. 把 DeepSeek Harness 接成 Paseo 原生 provider。",
5
5
  "keywords": [
6
6
  "paseo",
@@ -26,7 +26,6 @@
26
26
  "paseo-plugin.json",
27
27
  "index.server.ts",
28
28
  "server/",
29
- "shared/",
30
29
  "lib/",
31
30
  "bin/",
32
31
  "icon.svg",
@@ -1,148 +0,0 @@
1
- import type { PluginSurfaceProps } from "@getpaseo/plugin/client";
2
- import { useSettings } from "@getpaseo/plugin/client";
3
- import { Pressable, Text, View } from "react-native";
4
- import { DEFAULT_STREAM_STATS, streamStatsSettings, type StreamStatsSettings } from "../shared/settings";
5
-
6
- /**
7
- * Settings → Plugins → 回答统计行.
8
- *
9
- * The host renders plugin settings only as screens a plugin registers, so the
10
- * two numbers the stats row reads are edited here: how far the row sits under
11
- * the completed-turn footer, and how large its text is. Both default to the
12
- * geometry Paseo's own footer draws with, so leaving this page alone keeps the
13
- * row looking like part of that footer.
14
- */
15
- const FIELDS: Array<{
16
- key: keyof StreamStatsSettings;
17
- label: string;
18
- hint: string;
19
- min: number;
20
- max: number;
21
- step: number;
22
- unit: string;
23
- }> = [
24
- {
25
- key: "gapPx",
26
- label: "与页脚的间距",
27
- hint: "回合页脚最后一行文字到统计行的距离",
28
- min: 0,
29
- max: 24,
30
- step: 1,
31
- unit: "px",
32
- },
33
- {
34
- key: "fontSize",
35
- label: "字号",
36
- hint: "Paseo 自己的回合页脚用 13px",
37
- min: 10,
38
- max: 16,
39
- step: 1,
40
- unit: "px",
41
- },
42
- ];
43
-
44
- export function StreamStatsSettingsScreen({ theme }: PluginSurfaceProps) {
45
- const settings = useSettings(streamStatsSettings);
46
- const values = settings.status === "ready" ? settings.values : DEFAULT_STREAM_STATS;
47
- const editable = settings.status === "ready" && !settings.saving;
48
-
49
- const set = (key: keyof StreamStatsSettings, next: number) => {
50
- if (settings.status !== "ready" || settings.saving) return;
51
- if (settings.values[key] === next) return;
52
- void settings.save({ ...settings.values, [key]: next }, settings.revision);
53
- };
54
-
55
- const muted = theme.colors.foregroundMuted;
56
-
57
- return (
58
- <View style={{ padding: 20, gap: 18 }}>
59
- {FIELDS.map((field) => {
60
- const value = values[field.key];
61
- return (
62
- <View key={field.key} style={{ gap: 6 }}>
63
- <Text style={{ color: theme.colors.foreground, fontSize: 14 }}>{field.label}</Text>
64
- <Text style={{ color: muted, fontSize: 12 }}>{field.hint}</Text>
65
- <View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
66
- <StepButton
67
- label="−"
68
- disabled={!editable || value <= field.min}
69
- border={theme.colors.border}
70
- color={theme.colors.foreground}
71
- onPress={() => set(field.key, Math.max(field.min, value - field.step))}
72
- />
73
- <Text
74
- style={{
75
- color: theme.colors.foreground,
76
- fontSize: 14,
77
- minWidth: 64,
78
- textAlign: "center",
79
- fontVariant: ["tabular-nums"],
80
- }}
81
- >
82
- {`${value} ${field.unit}`}
83
- </Text>
84
- <StepButton
85
- label="+"
86
- disabled={!editable || value >= field.max}
87
- border={theme.colors.border}
88
- color={theme.colors.foreground}
89
- onPress={() => set(field.key, Math.min(field.max, value + field.step))}
90
- />
91
- </View>
92
- </View>
93
- );
94
- })}
95
- <Pressable
96
- accessibilityRole="button"
97
- accessibilityLabel="恢复默认"
98
- disabled={!editable}
99
- onPress={() => {
100
- if (settings.status !== "ready" || settings.saving) return;
101
- void settings.save({ ...DEFAULT_STREAM_STATS }, settings.revision);
102
- }}
103
- style={{ alignSelf: "flex-start", paddingVertical: 6 }}
104
- >
105
- <Text style={{ color: muted, fontSize: 12 }}>恢复默认(间距 6px,字号 13px)</Text>
106
- </Pressable>
107
- {settings.status === "ready" ? null : (
108
- <Text style={{ color: theme.colors.statusWarning, fontSize: 12 }}>
109
- {settings.status === "loading"
110
- ? "正在读取设置…"
111
- : `设置不可用:${settings.error}`}
112
- </Text>
113
- )}
114
- {settings.saveError === null ? null : (
115
- <Text style={{ color: theme.colors.statusDanger, fontSize: 12 }}>{settings.saveError}</Text>
116
- )}
117
- </View>
118
- );
119
- }
120
-
121
- function StepButton(props: {
122
- label: string;
123
- disabled: boolean;
124
- border: string;
125
- color: string;
126
- onPress: () => void;
127
- }) {
128
- return (
129
- <Pressable
130
- accessibilityRole="button"
131
- accessibilityLabel={props.label}
132
- disabled={props.disabled}
133
- onPress={props.onPress}
134
- style={{
135
- width: 30,
136
- height: 30,
137
- alignItems: "center",
138
- justifyContent: "center",
139
- borderWidth: 1,
140
- borderColor: props.border,
141
- borderRadius: 6,
142
- opacity: props.disabled ? 0.4 : 1,
143
- }}
144
- >
145
- <Text style={{ color: props.color, fontSize: 15 }}>{props.label}</Text>
146
- </Pressable>
147
- );
148
- }
package/client/web.ts DELETED
@@ -1,117 +0,0 @@
1
- import { Platform } from "react-native";
2
-
3
- /**
4
- * The one client file that reads the DOM.
5
- *
6
- * Paseo runs plugin client code on iOS and Android too, where none of these
7
- * globals exist, so every export here is a no-op off web and the shared
8
- * renderers only ever see numbers (or null). Keeping `getBoundingClientRect`,
9
- * `querySelectorAll` and `ResizeObserver` in this file means a host change to
10
- * its own layout costs one file to fix, and an SSR build has one place to
11
- * stub out.
12
- */
13
-
14
- /** The DOM shape read here; `tsconfig` ships no DOM typings. */
15
- interface MeasuredNode {
16
- parentElement: MeasuredNode | null;
17
- previousElementSibling: MeasuredNode | null;
18
- children: ArrayLike<MeasuredNode>;
19
- textContent: string | null;
20
- getBoundingClientRect(): { top: number; bottom: number; height: number };
21
- querySelectorAll(selector: string): ArrayLike<MeasuredNode>;
22
- }
23
-
24
- type ResizeObserverConstructor = new (callback: () => void) => {
25
- observe(target: unknown): void;
26
- disconnect(): void;
27
- };
28
-
29
- /** Where the footer above an item ends and where the item's own frame starts. */
30
- interface FooterAnchor {
31
- frame: MeasuredNode;
32
- above: MeasuredNode;
33
- }
34
-
35
- /**
36
- * The frame this item was laid out in, found from the row rendered inside it:
37
- * wrapper frames that hold nothing but this row are stepped over until a
38
- * sibling with height appears above.
39
- */
40
- function locate(row: MeasuredNode): FooterAnchor | null {
41
- let frame: MeasuredNode | null = row;
42
- for (let depth = 0; depth < 8 && frame !== null; depth += 1) {
43
- const above = frame.previousElementSibling;
44
- if (above !== null && above.getBoundingClientRect().height > 0) return { frame, above };
45
- frame = frame.parentElement;
46
- }
47
- return null;
48
- }
49
-
50
- /** Bottom edge of the last visible line of text inside `node`. */
51
- function lastTextBottom(node: MeasuredNode): number | null {
52
- let bottom: number | null = null;
53
- const lines = node.querySelectorAll("*");
54
- for (let index = 0; index < lines.length; index += 1) {
55
- const line = lines[index];
56
- if (line === undefined || line.children.length > 0) continue;
57
- if (line.textContent === null || line.textContent.trim() === "") continue;
58
- const rect = line.getBoundingClientRect();
59
- if (rect.height <= 0) continue;
60
- bottom = bottom === null ? rect.bottom : Math.max(bottom, rect.bottom);
61
- }
62
- return bottom;
63
- }
64
-
65
- function webRow(row: unknown): MeasuredNode | null {
66
- if (Platform.OS !== "web" || row === null || row === undefined) return null;
67
- return row as MeasuredNode;
68
- }
69
-
70
- /**
71
- * How far `row` has to pull itself up so its frame sits `gap` px under the last
72
- * line of text drawn above it — the completed-turn footer, or the answer's own
73
- * last line when a theme draws no footer.
74
- *
75
- * `appliedLift` is the margin the row is carrying right now: the frame has
76
- * already moved by it, so it is taken back out before measuring. Without that,
77
- * the row would measure the position it just moved itself to and bounce between
78
- * two places.
79
- *
80
- * Returns null when there is nothing to measure — native, a row that is not in
81
- * the DOM yet, no sibling above — and the caller falls back to its own layout.
82
- */
83
- export function measureFooterLift(
84
- row: unknown,
85
- options: { appliedLift: number; gap: number; maxLift: number },
86
- ): number | null {
87
- const node = webRow(row);
88
- if (node === null) return null;
89
- const anchor = locate(node);
90
- if (anchor === null) return null;
91
- const footerBottom = lastTextBottom(anchor.above);
92
- if (footerBottom === null) return null;
93
- const naturalTop = anchor.frame.getBoundingClientRect().top - options.appliedLift;
94
- const lift = options.gap - (naturalTop - footerBottom);
95
- return Math.max(options.maxLift, Math.min(0, Math.round(lift)));
96
- }
97
-
98
- /**
99
- * Calls `onResize` whenever the footer above `row` changes size — a theme
100
- * switching, a font loading, the turn being pushed down by a newer one.
101
- * Returns a cleanup, or null off web or when there is nothing to watch.
102
- */
103
- export function watchFooter(row: unknown, onResize: () => void): (() => void) | null {
104
- const node = webRow(row);
105
- if (node === null) return null;
106
- const anchor = locate(node);
107
- if (anchor === null) return null;
108
- const Observer = (globalThis as { ResizeObserver?: ResizeObserverConstructor }).ResizeObserver;
109
- if (Observer === undefined) return null;
110
- const observer = new Observer(onResize);
111
- observer.observe(anchor.above);
112
- // The 12px between "latest turn" and "pushed down by a newer turn" can come
113
- // from the container around this item rather than from the footer's own box.
114
- // Watching the parent catches both without polling.
115
- if (anchor.frame.parentElement !== null) observer.observe(anchor.frame.parentElement);
116
- return () => observer.disconnect();
117
- }
@@ -1,29 +0,0 @@
1
- import { defineSettings } from "@getpaseo/plugin";
2
- import { z } from "zod";
3
-
4
- /**
5
- * How the answer-stats row sits under a completed turn's footer.
6
- *
7
- * The defaults are what the row was drawn against: Paseo draws that footer at
8
- * `STREAM_METADATA_FONT_SIZE` (13px), and 6px above the row reads as one block
9
- * with it. A theme plugin redraws the footer, and a reader may want a
10
- * different rhythm or text size, so both numbers are host settings instead of
11
- * constants — registered by `index.server.ts`, read by the row and by the
12
- * settings screen.
13
- */
14
- export const streamStatsSettings = defineSettings({
15
- id: "stream-stats",
16
- scope: "host",
17
- version: 1,
18
- schema: z.object({
19
- /** Space between the footer's last line and the stats row, in px. */
20
- gapPx: z.number().min(0).max(24).default(6),
21
- /** The row's text size; Paseo's own footer draws at 13. */
22
- fontSize: z.number().min(10).max(16).default(13),
23
- }),
24
- });
25
-
26
- export type StreamStatsSettings = z.output<typeof streamStatsSettings.schema>;
27
-
28
- /** What the row falls back to while the settings are still loading. */
29
- export const DEFAULT_STREAM_STATS: StreamStatsSettings = { gapPx: 6, fontSize: 13 };