dsh-prompt-pocket 1.0.0 → 1.0.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/client.js +2 -2
- package/package.json +1 -1
- package/scripts/client-smoke.mjs +133 -133
package/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
window.__ModuleLoader__.load({
|
|
2
|
-
id: 'dsh-prompt-
|
|
2
|
+
id: 'dsh-prompt-pocket',
|
|
3
3
|
factory(require) {
|
|
4
4
|
const React = require('react');
|
|
5
5
|
const { createPortal } = require('react-dom');
|
|
@@ -963,7 +963,7 @@ window.__ModuleLoader__.load({
|
|
|
963
963
|
const t = ctx.locale.bind(NS);
|
|
964
964
|
const Bound = (props) => h(Pocket, { ...props, t });
|
|
965
965
|
ctx.slots.inject('conversation.input.overlay', () =>
|
|
966
|
-
ctx.slots.register({ name: 'conversation.input.overlay', id: 'dsh-prompt-
|
|
966
|
+
ctx.slots.register({ name: 'conversation.input.overlay', id: 'dsh-prompt-pocket', order: 20 }, Bound)
|
|
967
967
|
);
|
|
968
968
|
const ReplyBound = (props) => h(ReplySaveAction, { ...props, t });
|
|
969
969
|
ctx.slots.inject('conversation.chat.assistant-actions', () =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-prompt-pocket",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A prompt pocket that floats in the corner: save the draft or the selected text with Ctrl+Shift+S, click a saved prompt to drop it back at the caret.",
|
package/scripts/client-smoke.mjs
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
// Client-half regression: loads the real bundle, checks both slot registrations,
|
|
2
|
-
// the i18n parity, and that the pocket renders without touching the network.
|
|
3
|
-
// Run: node scripts/client-smoke.mjs
|
|
4
|
-
import assert from 'node:assert/strict';
|
|
5
|
-
|
|
6
|
-
const ok = [];
|
|
7
|
-
const pass = (n) => ok.push(n);
|
|
8
|
-
|
|
9
|
-
function useState(init) {
|
|
10
|
-
return [typeof init === 'function' ? init() : init, () => {}];
|
|
11
|
-
}
|
|
12
|
-
function useEffect() {}
|
|
13
|
-
function useMemo(fn) {
|
|
14
|
-
return fn();
|
|
15
|
-
}
|
|
16
|
-
function useCallback(fn) {
|
|
17
|
-
return fn;
|
|
18
|
-
}
|
|
19
|
-
function useRef(v) {
|
|
20
|
-
return { current: v === undefined ? null : v };
|
|
21
|
-
}
|
|
22
|
-
function createElement(type, props, ...children) {
|
|
23
|
-
return { type, props: props || {}, children: children.flat() };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const React = { createElement, useState, useEffect, useMemo, useCallback, useRef };
|
|
27
|
-
const ReactDom = { createPortal: (node, container) => ({ type: 'portal', container, node }) };
|
|
28
|
-
|
|
29
|
-
let loaded = null;
|
|
30
|
-
globalThis.window = {
|
|
31
|
-
innerWidth: 1200,
|
|
32
|
-
innerHeight: 800,
|
|
33
|
-
getSelection: () => ({ toString: () => '' }),
|
|
34
|
-
__ModuleLoader__: { load: (c) => (loaded = c) },
|
|
35
|
-
};
|
|
36
|
-
globalThis.document = { body: {}, addEventListener() {}, removeEventListener() {} };
|
|
37
|
-
const store = {};
|
|
38
|
-
globalThis.localStorage = {
|
|
39
|
-
getItem: (k) => (k in store ? store[k] : null),
|
|
40
|
-
setItem: (k, v) => {
|
|
41
|
-
store[k] = String(v);
|
|
42
|
-
},
|
|
43
|
-
removeItem: (k) => {
|
|
44
|
-
delete store[k];
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
let fetchCalls = 0;
|
|
48
|
-
globalThis.fetch = () => {
|
|
49
|
-
fetchCalls += 1;
|
|
50
|
-
return Promise.reject(new Error('no network in test'));
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
await import('../client.js');
|
|
54
|
-
|
|
55
|
-
assert.ok(loaded, 'bundle 应调用 __ModuleLoader__.load');
|
|
56
|
-
assert.equal(loaded.id, 'dsh-prompt-
|
|
57
|
-
pass('bundle 以正确 id 注册');
|
|
58
|
-
|
|
59
|
-
const mod = loaded.factory((name) => {
|
|
60
|
-
if (name === 'react') return React;
|
|
61
|
-
if (name === 'react-dom') return ReactDom;
|
|
62
|
-
throw new Error('unexpected import: ' + name);
|
|
63
|
-
});
|
|
64
|
-
assert.equal(typeof mod.apply, 'function');
|
|
65
|
-
assert.deepEqual(mod.inject, ['slots', 'locale']);
|
|
66
|
-
pass('factory 返回 apply 与 slots/locale 注入声明');
|
|
67
|
-
|
|
68
|
-
const slots = [];
|
|
69
|
-
let dict = null;
|
|
70
|
-
mod.apply({
|
|
71
|
-
effect(fn) {
|
|
72
|
-
return fn();
|
|
73
|
-
},
|
|
74
|
-
locale: {
|
|
75
|
-
register(ns, d) {
|
|
76
|
-
dict = { ns, d };
|
|
77
|
-
return () => {};
|
|
78
|
-
},
|
|
79
|
-
bind() {
|
|
80
|
-
return (k) => k;
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
slots: {
|
|
84
|
-
inject(name, fn) {
|
|
85
|
-
return fn();
|
|
86
|
-
},
|
|
87
|
-
register(meta, component) {
|
|
88
|
-
slots.push({ meta, component });
|
|
89
|
-
return () => {};
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
assert.equal(slots.length, 2, '应当挂两个位置:输入框浮层 + 回复动作');
|
|
95
|
-
assert.equal(slots[0].meta.name, 'conversation.input.overlay');
|
|
96
|
-
assert.equal(slots[0].meta.id, 'dsh-prompt-
|
|
97
|
-
assert.equal(slots[1].meta.name, 'conversation.chat.assistant-actions');
|
|
98
|
-
assert.equal(slots[1].meta.order, 30);
|
|
99
|
-
pass('挂到输入框浮层与回复动作行');
|
|
100
|
-
|
|
101
|
-
assert.ok(dict && dict.d.zh && dict.d.en, '中英两套字典都要有');
|
|
102
|
-
assert.equal(Object.keys(dict.d.zh).length, Object.keys(dict.d.en).length, '中英条目数一致');
|
|
103
|
-
pass('中英字典条目对齐');
|
|
104
|
-
|
|
105
|
-
const props = {
|
|
106
|
-
sessionId: 'session-a',
|
|
107
|
-
useInput: () => '',
|
|
108
|
-
useWorkspaces: () => [],
|
|
109
|
-
inputActions: {
|
|
110
|
-
captureInsertion: () => ({ draftRev: 1 }),
|
|
111
|
-
insertText: () => true,
|
|
112
|
-
setDraft: () => {},
|
|
113
|
-
focus: () => {},
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const outer = slots[0].component(props);
|
|
118
|
-
const rendered = outer.type(outer.props);
|
|
119
|
-
const tree = JSON.stringify(rendered);
|
|
120
|
-
assert.ok(tree.includes('data-dsh-prompt-stash'), '浮点要带自己的标记');
|
|
121
|
-
assert.ok(tree.includes('portal'), '固定定位必须 portal 到 body');
|
|
122
|
-
assert.equal(fetchCalls, 0, '渲染期不该发请求');
|
|
123
|
-
pass('渲染出可拖动的浮点并 portal 到 body');
|
|
124
|
-
|
|
125
|
-
// The reply action must not fire a request until it is clicked.
|
|
126
|
-
const actionOuter = slots[1].component({ sessionId: 'session-a', messageId: 'm-1', useWorkspaces: () => [] });
|
|
127
|
-
const action = actionOuter.type(actionOuter.props);
|
|
128
|
-
assert.equal(JSON.stringify(action).includes('button'), true);
|
|
129
|
-
assert.equal(fetchCalls, 0, '回复按钮点之前不发请求');
|
|
130
|
-
pass('回复动作渲染时不发请求');
|
|
131
|
-
|
|
132
|
-
console.log('通过 ' + ok.length + ' 项:');
|
|
133
|
-
ok.forEach((n, i) => console.log(' ' + (i + 1) + '. ' + n));
|
|
1
|
+
// Client-half regression: loads the real bundle, checks both slot registrations,
|
|
2
|
+
// the i18n parity, and that the pocket renders without touching the network.
|
|
3
|
+
// Run: node scripts/client-smoke.mjs
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
|
|
6
|
+
const ok = [];
|
|
7
|
+
const pass = (n) => ok.push(n);
|
|
8
|
+
|
|
9
|
+
function useState(init) {
|
|
10
|
+
return [typeof init === 'function' ? init() : init, () => {}];
|
|
11
|
+
}
|
|
12
|
+
function useEffect() {}
|
|
13
|
+
function useMemo(fn) {
|
|
14
|
+
return fn();
|
|
15
|
+
}
|
|
16
|
+
function useCallback(fn) {
|
|
17
|
+
return fn;
|
|
18
|
+
}
|
|
19
|
+
function useRef(v) {
|
|
20
|
+
return { current: v === undefined ? null : v };
|
|
21
|
+
}
|
|
22
|
+
function createElement(type, props, ...children) {
|
|
23
|
+
return { type, props: props || {}, children: children.flat() };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const React = { createElement, useState, useEffect, useMemo, useCallback, useRef };
|
|
27
|
+
const ReactDom = { createPortal: (node, container) => ({ type: 'portal', container, node }) };
|
|
28
|
+
|
|
29
|
+
let loaded = null;
|
|
30
|
+
globalThis.window = {
|
|
31
|
+
innerWidth: 1200,
|
|
32
|
+
innerHeight: 800,
|
|
33
|
+
getSelection: () => ({ toString: () => '' }),
|
|
34
|
+
__ModuleLoader__: { load: (c) => (loaded = c) },
|
|
35
|
+
};
|
|
36
|
+
globalThis.document = { body: {}, addEventListener() {}, removeEventListener() {} };
|
|
37
|
+
const store = {};
|
|
38
|
+
globalThis.localStorage = {
|
|
39
|
+
getItem: (k) => (k in store ? store[k] : null),
|
|
40
|
+
setItem: (k, v) => {
|
|
41
|
+
store[k] = String(v);
|
|
42
|
+
},
|
|
43
|
+
removeItem: (k) => {
|
|
44
|
+
delete store[k];
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
let fetchCalls = 0;
|
|
48
|
+
globalThis.fetch = () => {
|
|
49
|
+
fetchCalls += 1;
|
|
50
|
+
return Promise.reject(new Error('no network in test'));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
await import('../client.js');
|
|
54
|
+
|
|
55
|
+
assert.ok(loaded, 'bundle 应调用 __ModuleLoader__.load');
|
|
56
|
+
assert.equal(loaded.id, 'dsh-prompt-pocket');
|
|
57
|
+
pass('bundle 以正确 id 注册');
|
|
58
|
+
|
|
59
|
+
const mod = loaded.factory((name) => {
|
|
60
|
+
if (name === 'react') return React;
|
|
61
|
+
if (name === 'react-dom') return ReactDom;
|
|
62
|
+
throw new Error('unexpected import: ' + name);
|
|
63
|
+
});
|
|
64
|
+
assert.equal(typeof mod.apply, 'function');
|
|
65
|
+
assert.deepEqual(mod.inject, ['slots', 'locale']);
|
|
66
|
+
pass('factory 返回 apply 与 slots/locale 注入声明');
|
|
67
|
+
|
|
68
|
+
const slots = [];
|
|
69
|
+
let dict = null;
|
|
70
|
+
mod.apply({
|
|
71
|
+
effect(fn) {
|
|
72
|
+
return fn();
|
|
73
|
+
},
|
|
74
|
+
locale: {
|
|
75
|
+
register(ns, d) {
|
|
76
|
+
dict = { ns, d };
|
|
77
|
+
return () => {};
|
|
78
|
+
},
|
|
79
|
+
bind() {
|
|
80
|
+
return (k) => k;
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
slots: {
|
|
84
|
+
inject(name, fn) {
|
|
85
|
+
return fn();
|
|
86
|
+
},
|
|
87
|
+
register(meta, component) {
|
|
88
|
+
slots.push({ meta, component });
|
|
89
|
+
return () => {};
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
assert.equal(slots.length, 2, '应当挂两个位置:输入框浮层 + 回复动作');
|
|
95
|
+
assert.equal(slots[0].meta.name, 'conversation.input.overlay');
|
|
96
|
+
assert.equal(slots[0].meta.id, 'dsh-prompt-pocket');
|
|
97
|
+
assert.equal(slots[1].meta.name, 'conversation.chat.assistant-actions');
|
|
98
|
+
assert.equal(slots[1].meta.order, 30);
|
|
99
|
+
pass('挂到输入框浮层与回复动作行');
|
|
100
|
+
|
|
101
|
+
assert.ok(dict && dict.d.zh && dict.d.en, '中英两套字典都要有');
|
|
102
|
+
assert.equal(Object.keys(dict.d.zh).length, Object.keys(dict.d.en).length, '中英条目数一致');
|
|
103
|
+
pass('中英字典条目对齐');
|
|
104
|
+
|
|
105
|
+
const props = {
|
|
106
|
+
sessionId: 'session-a',
|
|
107
|
+
useInput: () => '',
|
|
108
|
+
useWorkspaces: () => [],
|
|
109
|
+
inputActions: {
|
|
110
|
+
captureInsertion: () => ({ draftRev: 1 }),
|
|
111
|
+
insertText: () => true,
|
|
112
|
+
setDraft: () => {},
|
|
113
|
+
focus: () => {},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const outer = slots[0].component(props);
|
|
118
|
+
const rendered = outer.type(outer.props);
|
|
119
|
+
const tree = JSON.stringify(rendered);
|
|
120
|
+
assert.ok(tree.includes('data-dsh-prompt-stash'), '浮点要带自己的标记');
|
|
121
|
+
assert.ok(tree.includes('portal'), '固定定位必须 portal 到 body');
|
|
122
|
+
assert.equal(fetchCalls, 0, '渲染期不该发请求');
|
|
123
|
+
pass('渲染出可拖动的浮点并 portal 到 body');
|
|
124
|
+
|
|
125
|
+
// The reply action must not fire a request until it is clicked.
|
|
126
|
+
const actionOuter = slots[1].component({ sessionId: 'session-a', messageId: 'm-1', useWorkspaces: () => [] });
|
|
127
|
+
const action = actionOuter.type(actionOuter.props);
|
|
128
|
+
assert.equal(JSON.stringify(action).includes('button'), true);
|
|
129
|
+
assert.equal(fetchCalls, 0, '回复按钮点之前不发请求');
|
|
130
|
+
pass('回复动作渲染时不发请求');
|
|
131
|
+
|
|
132
|
+
console.log('通过 ' + ok.length + ' 项:');
|
|
133
|
+
ok.forEach((n, i) => console.log(' ' + (i + 1) + '. ' + n));
|