@tivility/dsh-session-share 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -36,12 +36,33 @@ Restricting what a visitor can reach is
36
36
  [`@tivility/dsh-readonly-auth`](../readonly-auth)'s job, and it does it at the
37
37
  API rather than in the DOM.
38
38
 
39
+ ## Getting a link
40
+
41
+ A **Copy link** control in the session header, beside the session log. Its
42
+ hover text is the URL itself — which is also how someone discovers the format
43
+ exists.
44
+
45
+ That control is the difference between a feature and a convention. Without it
46
+ the link format reaches only the *model*, through the system prompt, and a
47
+ person looking at the GUI is left to assemble a URL from a session id the
48
+ interface never shows them.
49
+
50
+ The origin comes from `window.location`, so the link is always the address this
51
+ browser reached the harness at — loopback when that is how you opened it, the
52
+ LAN address when it is not. Nothing to configure, and nothing that can drift
53
+ from where the server actually answers.
54
+
55
+ A refused clipboard write (denied permission, insecure context) leaves the
56
+ button idle rather than claiming a copy that did not happen. The URL is in the
57
+ hover text either way.
58
+
39
59
  ## How it works
40
60
 
41
61
  Two halves, which is what the harness's client-module system is for.
42
62
 
43
63
  **The browser half** reads `?session=`, waits for the session list, calls
44
- `sessions.open(id)`, then strips the parameter from the address bar.
64
+ `sessions.open(id)`, then strips the parameter from the address bar. It also
65
+ registers the header control into `conversation.session.header.utilities`.
45
66
 
46
67
  Two details carry their weight:
47
68
 
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * The session header's "copy link" control.
4
+ *
5
+ * Without it the feature is unreachable by a person: the link format lives in
6
+ * the system prompt, which teaches the *model* to hand out links, and leaves
7
+ * whoever is looking at the GUI to construct one from a session id they cannot
8
+ * see. This is the one affordance that makes it a feature rather than a
9
+ * convention.
10
+ *
11
+ * The origin comes from `window.location`, so the link is always the address
12
+ * this browser reached the harness at — the loopback URL when that is how you
13
+ * opened it, the LAN address when it is not. Nothing to configure, and nothing
14
+ * that can drift from where the server actually answers.
15
+ * @module @tivility/dsh-session-share/client/ShareLink
16
+ */
17
+ import { useCallback, useState } from 'react';
18
+ import { Button, IconCheckOutline16, IconLinkOutline16, writeClipboard, } from '@deepseek-ai/dsh-client-ui-primitives';
19
+ import { shareQuery } from '../param.js';
20
+ import { SHARE_NS } from './namespace.js';
21
+ /** How long the copied state shows, in ms — matched to the harness's own copy controls. */
22
+ const COPIED_MS = 1000;
23
+ /**
24
+ * Render the copy-link control for the current session.
25
+ * @param props - composed slot props.
26
+ * @returns the control.
27
+ */
28
+ export function ShareLink({ sessionId, t }) {
29
+ const [copied, setCopied] = useState(false);
30
+ const url = `${window.location.origin}/${shareQuery(String(sessionId))}`;
31
+ const onCopy = useCallback(() => {
32
+ if (copied)
33
+ return;
34
+ void writeClipboard(url).then((accepted) => {
35
+ // A refused write (denied permission, insecure context) leaves the flag
36
+ // alone: the control must never claim a copy the host declined.
37
+ if (!accepted)
38
+ return;
39
+ setCopied(true);
40
+ window.setTimeout(() => { setCopied(false); }, COPIED_MS);
41
+ });
42
+ }, [copied, url]);
43
+ return (_jsx(Button, { variant: "ghost", size: "sm", onClick: onCopy,
44
+ // The URL itself is the most useful hover text: it is what gets copied,
45
+ // and seeing it is how someone learns the format exists.
46
+ title: copied ? t('copied') : `${t('hint')}\n${url}`, icon: copied ? _jsx(IconCheckOutline16, { size: 14 }) : _jsx(IconLinkOutline16, { size: 14 }), children: copied ? t('copied') : t('copy') }));
47
+ }
48
+ //# sourceMappingURL=ShareLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShareLink.js","sourceRoot":"","sources":["../../src/client/ShareLink.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,GACf,MAAM,uCAAuC,CAAA;AAI9C,OAAO,EAAE,U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CAAC,KAAC,iBAAiB,IAAC,IAAI,EAAE,EAAE,GAAI,YAEhF,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAC1B,CACV,CAAA;AACH,CAAC"}
@@ -1,11 +1,11 @@
1
1
  /**
2
- * The browser half: open the session a link names.
2
+ * The browser half: open the session a link names, and offer a way to get one.
3
3
  *
4
4
  * The harness's GUI has no routing — the whole client is searched in vain for
5
5
  * `pushState`, `location.hash`, or `searchParams`. The selected session lives
6
6
  * in the sessions manager and is restored from persisted state on load, so a
7
- * URL naming one has nowhere to be read. This adds that one step and nothing
8
- * else: read the parameter, select the session, get out of the way.
7
+ * URL naming one has nowhere to be read. This adds that step, and the control
8
+ * that makes it reachable by a person rather than only by the model.
9
9
  *
10
10
  * It deliberately hides nothing. The sidebar, the other sessions, and the
11
11
  * composer are all exactly as they would be — the link decides where you land,
@@ -17,14 +17,18 @@
17
17
  * node half pulls in the harness's HOST augmentations of `Context` — where
18
18
  * `sessions` is a different service with the same name. Importing
19
19
  * `ClientContext` would therefore resolve `ctx.sessions` to the host's shape.
20
- * The harness avoids this with separate client and host programs; a two-file
21
- * package states the three members it uses instead, which also leaves this
22
- * half with no harness type dependency at all.
20
+ * The harness avoids this with separate client and host programs; this package
21
+ * states the members it uses instead.
23
22
  * @module @tivility/dsh-session-share/client
24
23
  */
25
24
  import { SESSION_PARAM } from '../param.js';
25
+ import { en, zh } from './locales.js';
26
+ import { SHARE_NS } from './namespace.js';
27
+ import { ShareLink } from './ShareLink.js';
28
+ export { ShareLink } from './ShareLink.js';
29
+ export { SHARE_NS } from './namespace.js';
26
30
  /** Client-side services this plugin drives. */
27
- export const inject = ['sessions'];
31
+ export const inject = ['sessions', 'slots', 'locale'];
28
32
  /**
29
33
  * Remove the parameter from the address bar once it has been acted on.
30
34
  *
@@ -41,13 +45,13 @@ function stripParam() {
41
45
  window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
42
46
  }
43
47
  /**
44
- * Watch the session list until the named session can be opened.
48
+ * Open the session a `?session=` parameter names, once the list can carry it.
45
49
  * @param ctx - the client root context.
46
50
  */
47
- export function apply(ctx) {
51
+ function openRequestedSession(ctx) {
48
52
  const requested = new URL(window.location.href).searchParams.get(SESSION_PARAM);
49
53
  // No parameter is the overwhelmingly common case — every ordinary visit — so
50
- // this plugin costs nothing at all when it has nothing to do.
54
+ // this costs nothing at all when it has nothing to do.
51
55
  if (requested === null || requested === '')
52
56
  return;
53
57
  ctx.effect(() => {
@@ -78,4 +82,19 @@ export function apply(ctx) {
78
82
  return unsubscribe;
79
83
  });
80
84
  }
85
+ /**
86
+ * Read the link, and offer one.
87
+ * @param ctx - the client root context.
88
+ */
89
+ export function apply(ctx) {
90
+ openRequestedSession(ctx);
91
+ ctx.effect(() => ctx.locale.register(SHARE_NS, { zh, en }));
92
+ ctx.effect(() => ctx.slots.register({
93
+ // The header's utility band, not the title row: this is a control, and the
94
+ // band beside the breadcrumb is where static session context belongs.
95
+ name: 'conversation.session.header.utilities',
96
+ id: 'session-share',
97
+ locale: SHARE_NS,
98
+ }, ShareLink));
99
+ }
81
100
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AA8B3C,+CAA+C;AAC/C,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,UAAU,CAAC,CAAA;AAElC;;;;;;;GAOG;AACH,SAAS,UAAU;IACjB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACzC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC;QAAE,OAAM;IAChD,GAAG,CAAC,YAAY,CAAC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,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IAC3D,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAClC,2EAA2E;QAC3E,sEAAsE;QACtE,IAAI,EAAE,uCAAuC;QAC7C,EAAE,EAAE,eAAe;QACnB,MAAM,EAAE,QAAQ;KACjB,EAAE,SAAS,CAAC,CAAC,CAAA;AAChB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /** Copy for the session-header share control. */
2
+ /** English copy. */
3
+ export const en = {
4
+ copy: 'Copy link',
5
+ copied: 'Copied',
6
+ hint: 'Copy a link that opens this session',
7
+ };
8
+ /** Chinese copy. */
9
+ export const zh = {
10
+ copy: '复制链接',
11
+ copied: '已复制',
12
+ hint: '复制一个直接打开这条会话的链接',
13
+ };
14
+ //# sourceMappingURL=locales.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.js","sourceRoot":"","sources":["../../src/client/locales.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAKjD,oBAAoB;AACpB,MAAM,CAAC,MAAM,EAAE,GAA6B;IAC1C,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,qCAAqC;CAC5C,CAAA;AAED,oBAAoB;AACpB,MAAM,CAAC,MAAM,EAAE,GAA6B;IAC1C,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,iBAAiB;CACxB,CAAA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The locale namespace this bundle registers, and the key union its copy
3
+ * satisfies.
4
+ *
5
+ * Kept in its own module because the declaration merge below has to be visible
6
+ * to both the registration site and the component, and importing the component
7
+ * from the registration site (or the reverse) would make that a cycle.
8
+ * @module @tivility/dsh-session-share/client/namespace
9
+ */
10
+ /** Locale namespace for the session-header share control. */
11
+ export const SHARE_NS = 'session.share';
12
+ //# sourceMappingURL=namespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/client/namespace.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,6DAA6D;AAC7D,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAA"}
package/lib/client.js CHANGED
@@ -1,6 +1,9 @@
1
1
  window.__ModuleLoader__.load({ id: "@tivility/dsh-session-share", factory: (require) => {
2
2
  var module = { exports: {} }; var exports = module.exports;
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ let react_jsx_runtime = require("react/jsx-runtime");
5
+ let react = require("react");
6
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
4
7
 
5
8
  //#region lib/param.js
6
9
  /**
@@ -16,17 +19,101 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
16
19
  */
17
20
  /** Query parameter naming the session to open on load. */
18
21
  const SESSION_PARAM = "session";
22
+ /**
23
+ * Build the query a share link carries.
24
+ * @param sessionId - the session to open.
25
+ * @returns the query string, question mark included.
26
+ */
27
+ function shareQuery(sessionId) {
28
+ return `?${SESSION_PARAM}=${encodeURIComponent(sessionId)}`;
29
+ }
30
+
31
+ //#endregion
32
+ //#region lib/client/locales.js
33
+ /** Copy for the session-header share control. */
34
+ /** English copy. */
35
+ const en = {
36
+ copy: "Copy link",
37
+ copied: "Copied",
38
+ hint: "Copy a link that opens this session"
39
+ };
40
+ /** Chinese copy. */
41
+ const zh = {
42
+ copy: "复制链接",
43
+ copied: "已复制",
44
+ hint: "复制一个直接打开这条会话的链接"
45
+ };
46
+
47
+ //#endregion
48
+ //#region lib/client/namespace.js
49
+ /**
50
+ * The locale namespace this bundle registers, and the key union its copy
51
+ * satisfies.
52
+ *
53
+ * Kept in its own module because the declaration merge below has to be visible
54
+ * to both the registration site and the component, and importing the component
55
+ * from the registration site (or the reverse) would make that a cycle.
56
+ * @module @tivility/dsh-session-share/client/namespace
57
+ */
58
+ /** Locale namespace for the session-header share control. */
59
+ const SHARE_NS = "session.share";
60
+
61
+ //#endregion
62
+ //#region lib/client/ShareLink.js
63
+ /**
64
+ * The session header's "copy link" control.
65
+ *
66
+ * Without it the feature is unreachable by a person: the link format lives in
67
+ * the system prompt, which teaches the *model* to hand out links, and leaves
68
+ * whoever is looking at the GUI to construct one from a session id they cannot
69
+ * see. This is the one affordance that makes it a feature rather than a
70
+ * convention.
71
+ *
72
+ * The origin comes from `window.location`, so the link is always the address
73
+ * this browser reached the harness at — the loopback URL when that is how you
74
+ * opened it, the LAN address when it is not. Nothing to configure, and nothing
75
+ * that can drift from where the server actually answers.
76
+ * @module @tivility/dsh-session-share/client/ShareLink
77
+ */
78
+ /** How long the copied state shows, in ms — matched to the harness's own copy controls. */
79
+ const COPIED_MS = 1e3;
80
+ /**
81
+ * Render the copy-link control for the current session.
82
+ * @param props - composed slot props.
83
+ * @returns the control.
84
+ */
85
+ function ShareLink({ sessionId, t }) {
86
+ const [copied, setCopied] = (0, react.useState)(false);
87
+ const url = `${window.location.origin}/${shareQuery(String(sessionId))}`;
88
+ return (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
89
+ variant: "ghost",
90
+ size: "sm",
91
+ onClick: (0, react.useCallback)(() => {
92
+ if (copied) return;
93
+ (0, _deepseek_ai_dsh_client_ui_primitives.writeClipboard)(url).then((accepted) => {
94
+ if (!accepted) return;
95
+ setCopied(true);
96
+ window.setTimeout(() => {
97
+ setCopied(false);
98
+ }, COPIED_MS);
99
+ });
100
+ }, [copied, url]),
101
+ title: copied ? t("copied") : `${t("hint")}\n${url}`,
102
+ icon: copied ? (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutline16, { size: 14 }) : (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconLinkOutline16, { size: 14 }),
103
+ children: copied ? t("copied") : t("copy")
104
+ });
105
+ }
19
106
 
20
107
  //#endregion
21
108
  //#region lib/client/index.js
22
109
  /**
23
- * The browser half: open the session a link names.
110
+ * The browser half: open the session a link names, and offer a way to get one.
24
111
  *
25
112
  * The harness's GUI has no routing — the whole client is searched in vain for
26
113
  * `pushState`, `location.hash`, or `searchParams`. The selected session lives
27
114
  * in the sessions manager and is restored from persisted state on load, so a
28
- * URL naming one has nowhere to be read. This adds that one step and nothing
29
- * else: read the parameter, select the session, get out of the way.
115
+ * URL naming one has nowhere to be read. This adds that step, and the control
116
+ * that makes it reachable by a person rather than only by the model.
30
117
  *
31
118
  * It deliberately hides nothing. The sidebar, the other sessions, and the
32
119
  * composer are all exactly as they would be — the link decides where you land,
@@ -38,13 +125,16 @@ const SESSION_PARAM = "session";
38
125
  * node half pulls in the harness's HOST augmentations of `Context` — where
39
126
  * `sessions` is a different service with the same name. Importing
40
127
  * `ClientContext` would therefore resolve `ctx.sessions` to the host's shape.
41
- * The harness avoids this with separate client and host programs; a two-file
42
- * package states the three members it uses instead, which also leaves this
43
- * half with no harness type dependency at all.
128
+ * The harness avoids this with separate client and host programs; this package
129
+ * states the members it uses instead.
44
130
  * @module @tivility/dsh-session-share/client
45
131
  */
46
132
  /** Client-side services this plugin drives. */
47
- const inject = ["sessions"];
133
+ const inject = [
134
+ "sessions",
135
+ "slots",
136
+ "locale"
137
+ ];
48
138
  /**
49
139
  * Remove the parameter from the address bar once it has been acted on.
50
140
  *
@@ -60,10 +150,10 @@ function stripParam() {
60
150
  window.history.replaceState(window.history.state, "", `${url.pathname}${url.search}${url.hash}`);
61
151
  }
62
152
  /**
63
- * Watch the session list until the named session can be opened.
153
+ * Open the session a `?session=` parameter names, once the list can carry it.
64
154
  * @param ctx - the client root context.
65
155
  */
66
- function apply(ctx) {
156
+ function openRequestedSession(ctx) {
67
157
  const requested = new URL(window.location.href).searchParams.get(SESSION_PARAM);
68
158
  if (requested === null || requested === "") return;
69
159
  ctx.effect(() => {
@@ -88,8 +178,26 @@ function apply(ctx) {
88
178
  return unsubscribe;
89
179
  });
90
180
  }
181
+ /**
182
+ * Read the link, and offer one.
183
+ * @param ctx - the client root context.
184
+ */
185
+ function apply(ctx) {
186
+ openRequestedSession(ctx);
187
+ ctx.effect(() => ctx.locale.register(SHARE_NS, {
188
+ zh,
189
+ en
190
+ }));
191
+ ctx.effect(() => ctx.slots.register({
192
+ name: "conversation.session.header.utilities",
193
+ id: "session-share",
194
+ locale: SHARE_NS
195
+ }, ShareLink));
196
+ }
91
197
 
92
198
  //#endregion
199
+ exports.SHARE_NS = SHARE_NS;
200
+ exports.ShareLink = ShareLink;
93
201
  exports.apply = apply;
94
202
  exports.inject = inject;
95
203
  return module.exports; } });
package/lib/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["param.js","client/index.js"],"sourcesContent":["/**\n * The one fact both halves of this plugin have to agree on.\n *\n * The query parameter is a constant rather than configuration because the two\n * halves cannot share a configuration value: the browser bundle is fetched\n * outside the loader's config tree and receives only what its own `apply`\n * is handed, while the link the host writes into the system prompt is built\n * on the other side of the wire. A constant is the honest form of a value\n * that must match in two places.\n * @module @tivility/dsh-session-share/param\n */\n/** Query parameter naming the session to open on load. */\nexport const SESSION_PARAM = 'session';\n/**\n * Build the query a share link carries.\n * @param sessionId - the session to open.\n * @returns the query string, question mark included.\n */\nexport function shareQuery(sessionId) {\n return `?${SESSION_PARAM}=${encodeURIComponent(sessionId)}`;\n}\n//# sourceMappingURL=param.js.map","/**\n * The browser half: open the session a link names.\n *\n * The harness's GUI has no routing — the whole client is searched in vain for\n * `pushState`, `location.hash`, or `searchParams`. The selected session lives\n * in the sessions manager and is restored from persisted state on load, so a\n * URL naming one has nowhere to be read. This adds that one step and nothing\n * else: read the parameter, select the session, get out of the way.\n *\n * It deliberately hides nothing. The sidebar, the other sessions, and the\n * composer are all exactly as they would be — the link decides where you land,\n * not what you can see.\n *\n * ## Why the context is typed here\n *\n * The two halves of this package compile in one TypeScript program, and the\n * node half pulls in the harness's HOST augmentations of `Context` — where\n * `sessions` is a different service with the same name. Importing\n * `ClientContext` would therefore resolve `ctx.sessions` to the host's shape.\n * The harness avoids this with separate client and host programs; a two-file\n * package states the three members it uses instead, which also leaves this\n * half with no harness type dependency at all.\n * @module @tivility/dsh-session-share/client\n */\nimport { SESSION_PARAM } from '../param.js';\n/** Client-side services this plugin drives. */\nexport const inject = ['sessions'];\n/**\n * Remove the parameter from the address bar once it has been acted on.\n *\n * The selection is persisted by the runtime, so leaving the parameter in place\n * would make every later reload jump back to the linked session — fighting the\n * user each time they navigate away and refresh. Consuming it once makes the\n * link mean \"start here\", which is what a link means.\n */\nfunction stripParam() {\n const url = new URL(window.location.href);\n if (!url.searchParams.has(SESSION_PARAM))\n return;\n url.searchParams.delete(SESSION_PARAM);\n window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);\n}\n/**\n * Watch the session list until the named session can be opened.\n * @param ctx - the client root context.\n */\nexport function apply(ctx) {\n const requested = new URL(window.location.href).searchParams.get(SESSION_PARAM);\n // No parameter is the overwhelmingly common case — every ordinary visit — so\n // this plugin costs nothing at all when it has nothing to do.\n if (requested === null || requested === '')\n return;\n ctx.effect(() => {\n let done = false;\n const attempt = () => {\n if (done)\n return;\n const state = ctx.sessions.list.getSnapshot();\n if (state.byId[requested] !== undefined) {\n done = true;\n ctx.sessions.open(requested);\n stripParam();\n return;\n }\n // The list arrives asynchronously, so an id that is absent right now may\n // simply not have loaded. The phase is what separates \"not yet\" from \"no\n // such session\" — a timeout would guess at it.\n if (state.phase === 'ready') {\n done = true;\n stripParam();\n ctx.logger?.warn?.(`session-share: no session ${requested} in this harness`);\n }\n };\n const unsubscribe = ctx.sessions.list.subscribe(attempt);\n // The list may already be ready before this plugin activates, in which case\n // no change is ever published and the subscription alone would wait forever.\n attempt();\n return unsubscribe;\n });\n}\n//# sourceMappingURL=index.js.map"],"mappings":";;;;;;;;;;;;;;;;;AAYA,MAAa,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACc7B,MAAa,SAAS,CAAC,WAAW;;;;;;;;;AASlC,SAAS,aAAa;CAClB,MAAM,MAAM,IAAI,IAAI,OAAO,SAAS,KAAK;AACzC,KAAI,CAAC,IAAI,aAAa,IAAI,cAAc,CACpC;AACJ,KAAI,aAAa,OAAO,cAAc;AACtC,QAAO,QAAQ,aAAa,OAAO,QAAQ,OAAO,IAAI,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI,OAAO;;;;;;AAMpG,SAAgB,MAAM,KAAK;CACvB,MAAM,YAAY,IAAI,IAAI,OAAO,SAAS,KAAK,CAAC,aAAa,IAAI,cAAc;AAG/E,KAAI,cAAc,QAAQ,cAAc,GACpC;AACJ,KAAI,aAAa;EACb,IAAI,OAAO;EACX,MAAM,gBAAgB;AAClB,OAAI,KACA;GACJ,MAAM,QAAQ,IAAI,SAAS,KAAK,aAAa;AAC7C,OAAI,MAAM,KAAK,eAAe,QAAW;AACrC,WAAO;AACP,QAAI,SAAS,KAAK,UAAU;AAC5B,gBAAY;AACZ;;AAKJ,OAAI,MAAM,UAAU,SAAS;AACzB,WAAO;AACP,gBAAY;AACZ,QAAI,QAAQ,OAAO,6BAA6B,UAAU,kBAAkB;;;EAGpF,MAAM,cAAc,IAAI,SAAS,KAAK,UAAU,QAAQ;AAGxD,WAAS;AACT,SAAO;GACT"}
1
+ {"version":3,"file":"client.js","names":["Button","IconCheckOutline16","IconLinkOutline16"],"sources":["param.js","client/locales.js","client/namespace.js","client/ShareLink.js","client/index.js"],"sourcesContent":["/**\n * The one fact both halves of this plugin have to agree on.\n *\n * The query parameter is a constant rather than configuration because the two\n * halves cannot share a configuration value: the browser bundle is fetched\n * outside the loader's config tree and receives only what its own `apply`\n * is handed, while the link the host writes into the system prompt is built\n * on the other side of the wire. A constant is the honest form of a value\n * that must match in two places.\n * @module @tivility/dsh-session-share/param\n */\n/** Query parameter naming the session to open on load. */\nexport const SESSION_PARAM = 'session';\n/**\n * Build the query a share link carries.\n * @param sessionId - the session to open.\n * @returns the query string, question mark included.\n */\nexport function shareQuery(sessionId) {\n return `?${SESSION_PARAM}=${encodeURIComponent(sessionId)}`;\n}\n//# sourceMappingURL=param.js.map","/** Copy for the session-header share control. */\n/** English copy. */\nexport const en = {\n copy: 'Copy link',\n copied: 'Copied',\n hint: 'Copy a link that opens this session',\n};\n/** Chinese copy. */\nexport const zh = {\n copy: '复制链接',\n copied: '已复制',\n hint: '复制一个直接打开这条会话的链接',\n};\n//# sourceMappingURL=locales.js.map","/**\n * The locale namespace this bundle registers, and the key union its copy\n * satisfies.\n *\n * Kept in its own module because the declaration merge below has to be visible\n * to both the registration site and the component, and importing the component\n * from the registration site (or the reverse) would make that a cycle.\n * @module @tivility/dsh-session-share/client/namespace\n */\n/** Locale namespace for the session-header share control. */\nexport const SHARE_NS = 'session.share';\n//# sourceMappingURL=namespace.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\n/**\n * The session header's \"copy link\" control.\n *\n * Without it the feature is unreachable by a person: the link format lives in\n * the system prompt, which teaches the *model* to hand out links, and leaves\n * whoever is looking at the GUI to construct one from a session id they cannot\n * see. This is the one affordance that makes it a feature rather than a\n * convention.\n *\n * The origin comes from `window.location`, so the link is always the address\n * this browser reached the harness at — the loopback URL when that is how you\n * opened it, the LAN address when it is not. Nothing to configure, and nothing\n * that can drift from where the server actually answers.\n * @module @tivility/dsh-session-share/client/ShareLink\n */\nimport { useCallback, useState } from 'react';\nimport { Button, IconCheckOutline16, IconLinkOutline16, writeClipboard, } from '@deepseek-ai/dsh-client-ui-primitives';\nimport { shareQuery } from '../param.js';\nimport { SHARE_NS } from './namespace.js';\n/** How long the copied state shows, in ms — matched to the harness's own copy controls. */\nconst COPIED_MS = 1000;\n/**\n * Render the copy-link control for the current session.\n * @param props - composed slot props.\n * @returns the control.\n */\nexport function ShareLink({ sessionId, t }) {\n const [copied, setCopied] = useState(false);\n const url = `${window.location.origin}/${shareQuery(String(sessionId))}`;\n const onCopy = useCallback(() => {\n if (copied)\n return;\n void writeClipboard(url).then((accepted) => {\n // A refused write (denied permission, insecure context) leaves the flag\n // alone: the control must never claim a copy the host declined.\n if (!accepted)\n return;\n setCopied(true);\n window.setTimeout(() => { setCopied(false); }, COPIED_MS);\n });\n }, [copied, url]);\n return (_jsx(Button, { variant: \"ghost\", size: \"sm\", onClick: onCopy, \n // The URL itself is the most useful hover text: it is what gets copied,\n // and seeing it is how someone learns the format exists.\n title: copied ? t('copied') : `${t('hint')}\\n${url}`, icon: copied ? _jsx(IconCheckOutline16, { size: 14 }) : _jsx(IconLinkOutline16, { size: 14 }), children: copied ? t('copied') : t('copy') }));\n}\n//# sourceMappingURL=ShareLink.js.map","/**\n * The browser half: open the session a link names, and offer a way to get one.\n *\n * The harness's GUI has no routing — the whole client is searched in vain for\n * `pushState`, `location.hash`, or `searchParams`. The selected session lives\n * in the sessions manager and is restored from persisted state on load, so a\n * URL naming one has nowhere to be read. This adds that step, and the control\n * that makes it reachable by a person rather than only by the model.\n *\n * It deliberately hides nothing. The sidebar, the other sessions, and the\n * composer are all exactly as they would be — the link decides where you land,\n * not what you can see.\n *\n * ## Why the context is typed here\n *\n * The two halves of this package compile in one TypeScript program, and the\n * node half pulls in the harness's HOST augmentations of `Context` — where\n * `sessions` is a different service with the same name. Importing\n * `ClientContext` would therefore resolve `ctx.sessions` to the host's shape.\n * The harness avoids this with separate client and host programs; this package\n * states the members it uses instead.\n * @module @tivility/dsh-session-share/client\n */\nimport { SESSION_PARAM } from '../param.js';\nimport { en, zh } from './locales.js';\nimport { SHARE_NS } from './namespace.js';\nimport { ShareLink } from './ShareLink.js';\nexport { ShareLink } from './ShareLink.js';\nexport { SHARE_NS } from './namespace.js';\n/** Client-side services this plugin drives. */\nexport const inject = ['sessions', 'slots', 'locale'];\n/**\n * Remove the parameter from the address bar once it has been acted on.\n *\n * The selection is persisted by the runtime, so leaving the parameter in place\n * would make every later reload jump back to the linked session — fighting the\n * user each time they navigate away and refresh. Consuming it once makes the\n * link mean \"start here\", which is what a link means.\n */\nfunction stripParam() {\n const url = new URL(window.location.href);\n if (!url.searchParams.has(SESSION_PARAM))\n return;\n url.searchParams.delete(SESSION_PARAM);\n window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);\n}\n/**\n * Open the session a `?session=` parameter names, once the list can carry it.\n * @param ctx - the client root context.\n */\nfunction openRequestedSession(ctx) {\n const requested = new URL(window.location.href).searchParams.get(SESSION_PARAM);\n // No parameter is the overwhelmingly common case — every ordinary visit — so\n // this costs nothing at all when it has nothing to do.\n if (requested === null || requested === '')\n return;\n ctx.effect(() => {\n let done = false;\n const attempt = () => {\n if (done)\n return;\n const state = ctx.sessions.list.getSnapshot();\n if (state.byId[requested] !== undefined) {\n done = true;\n ctx.sessions.open(requested);\n stripParam();\n return;\n }\n // The list arrives asynchronously, so an id that is absent right now may\n // simply not have loaded. The phase is what separates \"not yet\" from \"no\n // such session\" — a timeout would guess at it.\n if (state.phase === 'ready') {\n done = true;\n stripParam();\n ctx.logger?.warn?.(`session-share: no session ${requested} in this harness`);\n }\n };\n const unsubscribe = ctx.sessions.list.subscribe(attempt);\n // The list may already be ready before this plugin activates, in which case\n // no change is ever published and the subscription alone would wait forever.\n attempt();\n return unsubscribe;\n });\n}\n/**\n * Read the link, and offer one.\n * @param ctx - the client root context.\n */\nexport function apply(ctx) {\n openRequestedSession(ctx);\n ctx.effect(() => ctx.locale.register(SHARE_NS, { zh, en }));\n ctx.effect(() => ctx.slots.register({\n // The header's utility band, not the title row: this is a control, and the\n // band beside the breadcrumb is where static session context belongs.\n name: 'conversation.session.header.utilities',\n id: 'session-share',\n locale: SHARE_NS,\n }, ShareLink));\n}\n//# sourceMappingURL=index.js.map"],"mappings":";;;;;;;;;;;;;;;;;;;;AAYA,MAAa,gBAAgB;;;;;;AAM7B,SAAgB,WAAW,WAAW;AAClC,QAAO,IAAI,cAAc,GAAG,mBAAmB,UAAU;;;;;;;ACjB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AI,cAAc;AAG/E,KAAI,cAAc,QAAQ,cAAc,GACpC;AACJ,KAAI,aAAa;EACb,IAAI,OAAO;EACX,MAAM,gBAAgB;AAClB,OAAI,KACA;GACJ,MAAM,QAAQ,IAAI,SAAS,KAAK,aAAa;AAC7C,OAAI,MAAM,KAAK,eAAe,QAAW;AACrC,WAAO;AACP,QAAI,SAAS,KAAK,UAAU;AAC5B,gBAAY;AACZ;;AAKJ,OAAI,MAAM,UAAU,SAAS;AACzB,WAAO;AACP,gBAAY;AACZ,QAAI,QAAQ,OAAO,6BAA6B,UAAU,kBAAkB;;;EAGpF,MAAM,cAAc,IAAI,SAAS,KAAK,UAAU,QAAQ;AAGxD,WAAS;AACT,SAAO;GACT;;;;;;AAMN,SAAgB,MAAM,KAAK;AACvB,sBAAqB,IAAI;AACzB,KAAI,aAAa,IAAI,OAAO,SAAS,UAAU;EAAE;EAAI;EAAI,CAAC,CAAC;AAC3D,KAAI,aAAa,IAAI,MAAM,SAAS;EAGhC,MAAM;EACN,IAAI;EACJ,QAAQ;EACX,EAAE,UAAU,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The session header's "copy link" control.
3
+ *
4
+ * Without it the feature is unreachable by a person: the link format lives in
5
+ * the system prompt, which teaches the *model* to hand out links, and leaves
6
+ * whoever is looking at the GUI to construct one from a session id they cannot
7
+ * see. This is the one affordance that makes it a feature rather than a
8
+ * convention.
9
+ *
10
+ * The origin comes from `window.location`, so the link is always the address
11
+ * this browser reached the harness at — the loopback URL when that is how you
12
+ * opened it, the LAN address when it is not. Nothing to configure, and nothing
13
+ * that can drift from where the server actually answers.
14
+ * @module @tivility/dsh-session-share/client/ShareLink
15
+ */
16
+ import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
17
+ import { SHARE_NS } from './namespace.js';
18
+ /** Full component props: the framework's session context plus this bundle's copy. */
19
+ export type ShareLinkProps = PropsRuntime<'conversation.session.header.utilities'> & PropsLocale<typeof SHARE_NS>;
20
+ /**
21
+ * Render the copy-link control for the current session.
22
+ * @param props - composed slot props.
23
+ * @returns the control.
24
+ */
25
+ export declare function ShareLink({ sessionId, t }: ShareLinkProps): import("react").JSX.Element;
26
+ //# sourceMappingURL=ShareLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShareLink.d.ts","sourceRoot":"","sources":["../../../src/client/ShareLink.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAIjF,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAKzC,qFAAqF;AACrF,MAAM,MAAM,cAAc,GACxB,YAAY,CAAC,uCAAuC,CAAC,GACnD,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAA;AAEhC;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,cAAc,+BA4BzD"}
@@ -1,11 +1,11 @@
1
1
  /**
2
- * The browser half: open the session a link names.
2
+ * The browser half: open the session a link names, and offer a way to get one.
3
3
  *
4
4
  * The harness's GUI has no routing — the whole client is searched in vain for
5
5
  * `pushState`, `location.hash`, or `searchParams`. The selected session lives
6
6
  * in the sessions manager and is restored from persisted state on load, so a
7
- * URL naming one has nowhere to be read. This adds that one step and nothing
8
- * else: read the parameter, select the session, get out of the way.
7
+ * URL naming one has nowhere to be read. This adds that step, and the control
8
+ * that makes it reachable by a person rather than only by the model.
9
9
  *
10
10
  * It deliberately hides nothing. The sidebar, the other sessions, and the
11
11
  * composer are all exactly as they would be — the link decides where you land,
@@ -17,11 +17,12 @@
17
17
  * node half pulls in the harness's HOST augmentations of `Context` — where
18
18
  * `sessions` is a different service with the same name. Importing
19
19
  * `ClientContext` would therefore resolve `ctx.sessions` to the host's shape.
20
- * The harness avoids this with separate client and host programs; a two-file
21
- * package states the three members it uses instead, which also leaves this
22
- * half with no harness type dependency at all.
20
+ * The harness avoids this with separate client and host programs; this package
21
+ * states the members it uses instead.
23
22
  * @module @tivility/dsh-session-share/client
24
23
  */
24
+ export { ShareLink } from './ShareLink.js';
25
+ export { SHARE_NS } from './namespace.js';
25
26
  /** The session-list snapshot this plugin reads. */
26
27
  interface SessionListSnapshot {
27
28
  /** Every listed session, keyed by id. */
@@ -41,9 +42,24 @@ interface SessionsFace {
41
42
  */
42
43
  open(id: string): void;
43
44
  }
45
+ /** The slot registry, narrowed to the one registration this plugin makes. */
46
+ interface SlotsFace {
47
+ register(spec: {
48
+ name: string;
49
+ id?: string;
50
+ order?: number;
51
+ locale?: string;
52
+ }, component: unknown): () => void;
53
+ }
54
+ /** The locale registry, narrowed to the one bundle this plugin adds. */
55
+ interface LocaleFace {
56
+ register(namespace: string, dictionaries: Record<string, unknown>): () => void;
57
+ }
44
58
  /** The client context members this plugin uses. */
45
59
  interface ShareContext {
46
60
  readonly sessions: SessionsFace;
61
+ readonly slots: SlotsFace;
62
+ readonly locale: LocaleFace;
47
63
  effect(run: () => () => void): unknown;
48
64
  readonly logger?: {
49
65
  warn?(message: string): void;
@@ -52,9 +68,8 @@ interface ShareContext {
52
68
  /** Client-side services this plugin drives. */
53
69
  export declare const inject: string[];
54
70
  /**
55
- * Watch the session list until the named session can be opened.
71
+ * Read the link, and offer one.
56
72
  * @param ctx - the client root context.
57
73
  */
58
74
  export declare function apply(ctx: ShareContext): void;
59
- export {};
60
75
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,mDAAmD;AACnD,UAAU,mBAAmB;IAC3B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAChD,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,EAAE,SAA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AI,GAAG,MAAM,IAAI,CAAA;KAC5C,CAAA;IACD;;;OAGG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AAED,6EAA6E;AAC7E,UAAU,SAAS;IACjB,QAAQ,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,IAAI,CAAA;CAC/G;AAED,wEAAwE;AACxE,UAAU,UAAU;IAClB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI,CAAA;CAC/E;AAED,mDAAmD;AACnD,UAAU,YAAY;IACpB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,MAAM,CAAC,GAAG,EAAE,MAAM,MAAM,IAAI,GAAG,OAAO,CAAA;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CACnD;AAED,+CAA+C;AAC/C,eAAO,MAAM,MAAM,UAAkC,CAAA;AAuDrD;;;GAGG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAW7C"}
@@ -0,0 +1,8 @@
1
+ /** Copy for the session-header share control. */
2
+ /** Locale keys this surface renders. */
3
+ export type ShareKey = 'copy' | 'copied' | 'hint';
4
+ /** English copy. */
5
+ export declare const en: Record<ShareKey, string>;
6
+ /** Chinese copy. */
7
+ export declare const zh: Record<ShareKey, string>;
8
+ //# sourceMappingURL=locales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/client/locales.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,wCAAwC;AACxC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEjD,oBAAoB;AACpB,eAAO,MAAM,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAIvC,CAAA;AAED,oBAAoB;AACpB,eAAO,MAAM,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAIvC,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The locale namespace this bundle registers, and the key union its copy
3
+ * satisfies.
4
+ *
5
+ * Kept in its own module because the declaration merge below has to be visible
6
+ * to both the registration site and the component, and importing the component
7
+ * from the registration site (or the reverse) would make that a cycle.
8
+ * @module @tivility/dsh-session-share/client/namespace
9
+ */
10
+ import type { ShareKey } from './locales.js';
11
+ /** Locale namespace for the session-header share control. */
12
+ export declare const SHARE_NS = "session.share";
13
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
14
+ interface LocaleNamespaceMap {
15
+ /** The share control's copy. */
16
+ 'session.share': ShareKey;
17
+ }
18
+ }
19
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../src/client/namespace.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAE5C,6DAA6D;AAC7D,eAAO,MAAM,QAAQ,kBAAkB,CAAA;AAEvC,OAAO,QAAQ,kCAAkC,CAAC;IAChD,UAAU,kBAAkB;QAC1B,gCAAgC;QAChC,eAAe,EAAE,QAAQ,CAAA;KAC1B;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tivility/dsh-session-share",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Link straight to one DeepSeek Harness session: the GUI opens on it instead of wherever it was left.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -37,7 +37,9 @@
37
37
  "client": {
38
38
  "platform": "web",
39
39
  "inject": [
40
- "@deepseek-ai/dsh-client-runtime"
40
+ "@deepseek-ai/dsh-client-runtime",
41
+ "@deepseek-ai/dsh-client-ui-conversation",
42
+ "@deepseek-ai/dsh-client-locale"
41
43
  ]
42
44
  }
43
45
  },
@@ -61,10 +63,19 @@
61
63
  "devDependencies": {
62
64
  "@deepseek-ai/cordis": "*",
63
65
  "@deepseek-ai/dsh-agent": "0.1.1-rc.2",
66
+ "@deepseek-ai/dsh-client-locale": "0.1.1-rc.2",
64
67
  "@deepseek-ai/dsh-client-runtime": "0.1.1-rc.2",
68
+ "@deepseek-ai/dsh-client-ui-conversation": "0.1.1-rc.2",
69
+ "@deepseek-ai/dsh-client-ui-primitives": "0.1.1-rc.2",
70
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.1-rc.2",
65
71
  "@deepseek-ai/dsh-host-webserver": "0.1.1-rc.2",
66
72
  "@deepseek-ai/dsh-system-prompt": "0.1.1-rc.2",
67
73
  "@deepseek-ai/schemastery": "*",
74
+ "@testing-library/react": "^16.1.0",
75
+ "@types/react": "~18.3.1",
76
+ "jsdom": "^26.0.0",
77
+ "react": "^18.2.0",
78
+ "react-dom": "^18.2.0",
68
79
  "tsdown": "^0.20.0"
69
80
  },
70
81
  "publishConfig": {
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The session header's "copy link" control.
3
+ *
4
+ * Without it the feature is unreachable by a person: the link format lives in
5
+ * the system prompt, which teaches the *model* to hand out links, and leaves
6
+ * whoever is looking at the GUI to construct one from a session id they cannot
7
+ * see. This is the one affordance that makes it a feature rather than a
8
+ * convention.
9
+ *
10
+ * The origin comes from `window.location`, so the link is always the address
11
+ * this browser reached the harness at — the loopback URL when that is how you
12
+ * opened it, the LAN address when it is not. Nothing to configure, and nothing
13
+ * that can drift from where the server actually answers.
14
+ * @module @tivility/dsh-session-share/client/ShareLink
15
+ */
16
+
17
+ import { useCallback, useState } from 'react'
18
+ import {
19
+ Button,
20
+ IconCheckOutline16,
21
+ IconLinkOutline16,
22
+ writeClipboard,
23
+ } from '@deepseek-ai/dsh-client-ui-primitives'
24
+ import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
25
+ // Type-only: pulls the ui-conversation SlotMap merge that declares this seat.
26
+ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
27
+ import { shareQuery } from '../param.js'
28
+ import { SHARE_NS } from './namespace.js'
29
+
30
+ /** How long the copied state shows, in ms — matched to the harness's own copy controls. */
31
+ const COPIED_MS = 1000
32
+
33
+ /** Full component props: the framework's session context plus this bundle's copy. */
34
+ export type ShareLinkProps =
35
+ PropsRuntime<'conversation.session.header.utilities'>
36
+ & PropsLocale<typeof SHARE_NS>
37
+
38
+ /**
39
+ * Render the copy-link control for the current session.
40
+ * @param props - composed slot props.
41
+ * @returns the control.
42
+ */
43
+ export function ShareLink({ sessionId, t }: ShareLinkProps) {
44
+ const [copied, setCopied] = useState(false)
45
+ const url = `${window.location.origin}/${shareQuery(String(sessionId))}`
46
+
47
+ const onCopy = useCallback(() => {
48
+ if (copied) return
49
+ void writeClipboard(url).then((accepted) => {
50
+ // A refused write (denied permission, insecure context) leaves the flag
51
+ // alone: the control must never claim a copy the host declined.
52
+ if (!accepted) return
53
+ setCopied(true)
54
+ window.setTimeout(() => { setCopied(false) }, COPIED_MS)
55
+ })
56
+ }, [copied, url])
57
+
58
+ return (
59
+ <Button
60
+ variant="ghost"
61
+ size="sm"
62
+ onClick={onCopy}
63
+ // The URL itself is the most useful hover text: it is what gets copied,
64
+ // and seeing it is how someone learns the format exists.
65
+ title={copied ? t('copied') : `${t('hint')}\n${url}`}
66
+ icon={copied ? <IconCheckOutline16 size={14} /> : <IconLinkOutline16 size={14} />}
67
+ >
68
+ {copied ? t('copied') : t('copy')}
69
+ </Button>
70
+ )
71
+ }
@@ -1,11 +1,11 @@
1
1
  /**
2
- * The browser half: open the session a link names.
2
+ * The browser half: open the session a link names, and offer a way to get one.
3
3
  *
4
4
  * The harness's GUI has no routing — the whole client is searched in vain for
5
5
  * `pushState`, `location.hash`, or `searchParams`. The selected session lives
6
6
  * in the sessions manager and is restored from persisted state on load, so a
7
- * URL naming one has nowhere to be read. This adds that one step and nothing
8
- * else: read the parameter, select the session, get out of the way.
7
+ * URL naming one has nowhere to be read. This adds that step, and the control
8
+ * that makes it reachable by a person rather than only by the model.
9
9
  *
10
10
  * It deliberately hides nothing. The sidebar, the other sessions, and the
11
11
  * composer are all exactly as they would be — the link decides where you land,
@@ -17,13 +17,18 @@
17
17
  * node half pulls in the harness's HOST augmentations of `Context` — where
18
18
  * `sessions` is a different service with the same name. Importing
19
19
  * `ClientContext` would therefore resolve `ctx.sessions` to the host's shape.
20
- * The harness avoids this with separate client and host programs; a two-file
21
- * package states the three members it uses instead, which also leaves this
22
- * half with no harness type dependency at all.
20
+ * The harness avoids this with separate client and host programs; this package
21
+ * states the members it uses instead.
23
22
  * @module @tivility/dsh-session-share/client
24
23
  */
25
24
 
26
25
  import { SESSION_PARAM } from '../param.js'
26
+ import { en, zh } from './locales.js'
27
+ import { SHARE_NS } from './namespace.js'
28
+ import { ShareLink } from './ShareLink.js'
29
+
30
+ export { ShareLink } from './ShareLink.js'
31
+ export { SHARE_NS } from './namespace.js'
27
32
 
28
33
  /** The session-list snapshot this plugin reads. */
29
34
  interface SessionListSnapshot {
@@ -46,15 +51,27 @@ interface SessionsFace {
46
51
  open(id: string): void
47
52
  }
48
53
 
54
+ /** The slot registry, narrowed to the one registration this plugin makes. */
55
+ interface SlotsFace {
56
+ register(spec: { name: string, id?: string, order?: number, locale?: string }, component: unknown): () => void
57
+ }
58
+
59
+ /** The locale registry, narrowed to the one bundle this plugin adds. */
60
+ interface LocaleFace {
61
+ register(namespace: string, dictionaries: Record<string, unknown>): () => void
62
+ }
63
+
49
64
  /** The client context members this plugin uses. */
50
65
  interface ShareContext {
51
66
  readonly sessions: SessionsFace
67
+ readonly slots: SlotsFace
68
+ readonly locale: LocaleFace
52
69
  effect(run: () => () => void): unknown
53
70
  readonly logger?: { warn?(message: string): void }
54
71
  }
55
72
 
56
73
  /** Client-side services this plugin drives. */
57
- export const inject = ['sessions']
74
+ export const inject = ['sessions', 'slots', 'locale']
58
75
 
59
76
  /**
60
77
  * Remove the parameter from the address bar once it has been acted on.
@@ -72,13 +89,13 @@ function stripParam(): void {
72
89
  }
73
90
 
74
91
  /**
75
- * Watch the session list until the named session can be opened.
92
+ * Open the session a `?session=` parameter names, once the list can carry it.
76
93
  * @param ctx - the client root context.
77
94
  */
78
- export function apply(ctx: ShareContext): void {
95
+ function openRequestedSession(ctx: ShareContext): void {
79
96
  const requested = new URL(window.location.href).searchParams.get(SESSION_PARAM)
80
97
  // No parameter is the overwhelmingly common case — every ordinary visit — so
81
- // this plugin costs nothing at all when it has nothing to do.
98
+ // this costs nothing at all when it has nothing to do.
82
99
  if (requested === null || requested === '') return
83
100
 
84
101
  ctx.effect(() => {
@@ -108,3 +125,20 @@ export function apply(ctx: ShareContext): void {
108
125
  return unsubscribe
109
126
  })
110
127
  }
128
+
129
+ /**
130
+ * Read the link, and offer one.
131
+ * @param ctx - the client root context.
132
+ */
133
+ export function apply(ctx: ShareContext): void {
134
+ openRequestedSession(ctx)
135
+
136
+ ctx.effect(() => ctx.locale.register(SHARE_NS, { zh, en }))
137
+ ctx.effect(() => ctx.slots.register({
138
+ // The header's utility band, not the title row: this is a control, and the
139
+ // band beside the breadcrumb is where static session context belongs.
140
+ name: 'conversation.session.header.utilities',
141
+ id: 'session-share',
142
+ locale: SHARE_NS,
143
+ }, ShareLink))
144
+ }
@@ -0,0 +1,18 @@
1
+ /** Copy for the session-header share control. */
2
+
3
+ /** Locale keys this surface renders. */
4
+ export type ShareKey = 'copy' | 'copied' | 'hint'
5
+
6
+ /** English copy. */
7
+ export const en: Record<ShareKey, string> = {
8
+ copy: 'Copy link',
9
+ copied: 'Copied',
10
+ hint: 'Copy a link that opens this session',
11
+ }
12
+
13
+ /** Chinese copy. */
14
+ export const zh: Record<ShareKey, string> = {
15
+ copy: '复制链接',
16
+ copied: '已复制',
17
+ hint: '复制一个直接打开这条会话的链接',
18
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The locale namespace this bundle registers, and the key union its copy
3
+ * satisfies.
4
+ *
5
+ * Kept in its own module because the declaration merge below has to be visible
6
+ * to both the registration site and the component, and importing the component
7
+ * from the registration site (or the reverse) would make that a cycle.
8
+ * @module @tivility/dsh-session-share/client/namespace
9
+ */
10
+
11
+ import type { ShareKey } from './locales.js'
12
+
13
+ /** Locale namespace for the session-header share control. */
14
+ export const SHARE_NS = 'session.share'
15
+
16
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
17
+ interface LocaleNamespaceMap {
18
+ /** The share control's copy. */
19
+ 'session.share': ShareKey
20
+ }
21
+ }