@jetcrab/pi-desk-sdk 0.0.0-stage → 1.0.1-dev.9001
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/LICENSE +201 -0
- package/README.md +4 -2
- package/dist/browser.d.ts +388 -0
- package/dist/browser.js +66 -0
- package/dist/capabilities.d.ts +104 -0
- package/dist/capabilities.js +89 -0
- package/dist/entry.d.ts +137 -0
- package/dist/entry.js +11 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +14 -0
- package/dist/host-runtime/base.js +284 -0
- package/dist/host-runtime/markdown.js +130 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/react-base.d.ts +33 -0
- package/dist/react-base.js +120 -0
- package/dist/react-log.d.ts +12 -0
- package/dist/react-log.js +99 -0
- package/dist/react-markdown.d.ts +5 -0
- package/dist/react-markdown.js +16 -0
- package/dist/react-ui.d.ts +197 -0
- package/dist/react-ui.js +310 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +2 -0
- package/dist/session.d.ts +155 -0
- package/dist/session.js +167 -0
- package/dist/settings.d.ts +24 -0
- package/dist/settings.js +22 -0
- package/dist/shared.d.ts +31 -0
- package/dist/shared.js +11 -0
- package/package.json +118 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pi Desk SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
包名:`@jetcrab/pi-desk-sdk`。公开接口以本版本 `package.json` 的 exports 和对应 TypeScript 声明为准。
|
|
4
|
+
|
|
5
|
+
本包自有代码使用 Apache-2.0,见 [LICENSE](./LICENSE)。第三方代码继续遵循其原有许可,构建时保留上游法律注释。
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import type { BrowserApplicationContext, PluginDisposer, PluginJsonObject, PluginNotificationLevel, PluginSource, PluginWorkSession } from './shared.js';
|
|
2
|
+
import type { PluginPushMessage } from './entry.js';
|
|
3
|
+
import type { HostSettings } from './settings.js';
|
|
4
|
+
export type { HostRegion, HostSettings, HostSettingsSnapshot } from './settings.js';
|
|
5
|
+
export type { BrowserApplicationContext, BrowserBuiltinIconName, BrowserContributionIcon, PluginDisposer, PluginJsonObject, PluginJsonValue, PluginNotificationLevel, PluginSource, PluginWorkSession } from './shared.js';
|
|
6
|
+
export type { PluginPushMessage, PluginPushTarget } from './entry.js';
|
|
7
|
+
export type BrowserContributionKind = 'application' | 'composer-panel' | 'settings-page' | 'message-view' | 'session-sidebar-tab';
|
|
8
|
+
export type BrowserEntryStatus = 'unloaded' | 'loading' | 'ready' | 'failed';
|
|
9
|
+
export type BrowserContributionLoadStatus = 'unloaded' | 'loading' | 'ready' | 'failed';
|
|
10
|
+
export interface BrowserEntryRuntime {
|
|
11
|
+
readonly pluginName: string;
|
|
12
|
+
dispose(): void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export type BrowserEntryState = {
|
|
15
|
+
status: 'unloaded';
|
|
16
|
+
} | {
|
|
17
|
+
status: 'loading';
|
|
18
|
+
promise: Promise<BrowserEntryRuntime>;
|
|
19
|
+
} | {
|
|
20
|
+
status: 'ready';
|
|
21
|
+
runtime: BrowserEntryRuntime;
|
|
22
|
+
} | {
|
|
23
|
+
status: 'failed';
|
|
24
|
+
error: Error;
|
|
25
|
+
};
|
|
26
|
+
export type BrowserContributionLoadState = {
|
|
27
|
+
status: 'unloaded';
|
|
28
|
+
} | {
|
|
29
|
+
status: 'loading';
|
|
30
|
+
promise: Promise<BrowserContributionImplementation>;
|
|
31
|
+
} | {
|
|
32
|
+
status: 'ready';
|
|
33
|
+
implementation: BrowserContributionImplementation;
|
|
34
|
+
} | {
|
|
35
|
+
status: 'failed';
|
|
36
|
+
error: Error;
|
|
37
|
+
};
|
|
38
|
+
export interface BrowserConnectionSnapshot {
|
|
39
|
+
status: 'connecting' | 'ready' | 'disconnected';
|
|
40
|
+
error: string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface BrowserConnectionHost {
|
|
43
|
+
getSnapshot(): BrowserConnectionSnapshot;
|
|
44
|
+
subscribe(listener: () => void): PluginDisposer;
|
|
45
|
+
}
|
|
46
|
+
export interface BrowserWorkSessionCreateInput {
|
|
47
|
+
cwd: string;
|
|
48
|
+
}
|
|
49
|
+
export type BrowserWorkSessionGoToInput = {
|
|
50
|
+
workId: string;
|
|
51
|
+
sessionId?: never;
|
|
52
|
+
cwd?: never;
|
|
53
|
+
} | {
|
|
54
|
+
sessionId: string;
|
|
55
|
+
cwd?: string;
|
|
56
|
+
workId?: never;
|
|
57
|
+
};
|
|
58
|
+
export interface BrowserWorkSessionHost {
|
|
59
|
+
getSnapshot(): readonly PluginWorkSession[];
|
|
60
|
+
subscribe(listener: () => void): PluginDisposer;
|
|
61
|
+
create(input: BrowserWorkSessionCreateInput): Promise<PluginWorkSession>;
|
|
62
|
+
goTo(input: BrowserWorkSessionGoToInput): Promise<PluginWorkSession>;
|
|
63
|
+
}
|
|
64
|
+
export interface BrowserThemeSnapshot {
|
|
65
|
+
readonly mode: 'light' | 'dark';
|
|
66
|
+
}
|
|
67
|
+
export interface BrowserLocaleHost {
|
|
68
|
+
getSnapshot(): {
|
|
69
|
+
readonly locale: 'zh-CN' | 'en';
|
|
70
|
+
readonly timeZone?: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface BrowserThemeHost {
|
|
74
|
+
getSnapshot(): BrowserThemeSnapshot;
|
|
75
|
+
subscribe(listener: () => void): PluginDisposer;
|
|
76
|
+
}
|
|
77
|
+
export interface BrowserPluginLogSnapshot {
|
|
78
|
+
text: string;
|
|
79
|
+
truncated: boolean;
|
|
80
|
+
loading: boolean;
|
|
81
|
+
error: string | null;
|
|
82
|
+
}
|
|
83
|
+
export interface BrowserPluginLogHandle {
|
|
84
|
+
getSnapshot(): BrowserPluginLogSnapshot;
|
|
85
|
+
subscribe(listener: () => void): PluginDisposer;
|
|
86
|
+
retry(): void;
|
|
87
|
+
dispose(): void;
|
|
88
|
+
}
|
|
89
|
+
export interface BrowserPluginLogHost {
|
|
90
|
+
open(path: string): BrowserPluginLogHandle;
|
|
91
|
+
}
|
|
92
|
+
export interface PiDeskBrowserChannel {
|
|
93
|
+
invokeGlobal(method: string, input: PluginJsonObject): Promise<PluginJsonObject>;
|
|
94
|
+
invokeSession(source: PluginSource, method: string, input: PluginJsonObject): Promise<PluginJsonObject>;
|
|
95
|
+
}
|
|
96
|
+
export type PiPromptImageMimeType = 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif';
|
|
97
|
+
export interface PiPromptImage {
|
|
98
|
+
mimeType: PiPromptImageMimeType;
|
|
99
|
+
data: string;
|
|
100
|
+
width: number;
|
|
101
|
+
height: number;
|
|
102
|
+
}
|
|
103
|
+
export interface PiPromptInput {
|
|
104
|
+
mode: 'auto' | 'follow_up';
|
|
105
|
+
text: string;
|
|
106
|
+
images?: readonly PiPromptImage[];
|
|
107
|
+
}
|
|
108
|
+
export interface PiPromptResult {
|
|
109
|
+
tempId: string;
|
|
110
|
+
}
|
|
111
|
+
export interface PiCommandInfo {
|
|
112
|
+
name: string;
|
|
113
|
+
description: string | null;
|
|
114
|
+
}
|
|
115
|
+
export interface PiNativeCommandChannel {
|
|
116
|
+
list(source: PluginSource): Promise<readonly PiCommandInfo[]>;
|
|
117
|
+
execute(source: PluginSource, command: string, args?: string): Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
export interface PiToolInfo {
|
|
120
|
+
name: string;
|
|
121
|
+
description: string;
|
|
122
|
+
parameters: PluginJsonObject;
|
|
123
|
+
active: boolean;
|
|
124
|
+
exposure?: 'direct' | 'model-only' | 'codemode' | 'deferred' | 'hidden';
|
|
125
|
+
source?: string | null;
|
|
126
|
+
blockedByMode?: boolean;
|
|
127
|
+
}
|
|
128
|
+
export interface PiNativeToolMetadataChannel {
|
|
129
|
+
list(source: PluginSource): Promise<readonly PiToolInfo[]>;
|
|
130
|
+
}
|
|
131
|
+
export interface PiBashExecuteInput {
|
|
132
|
+
command: string;
|
|
133
|
+
excludeFromContext: boolean;
|
|
134
|
+
}
|
|
135
|
+
export interface PiBashResult {
|
|
136
|
+
output: string;
|
|
137
|
+
exitCode: number | null;
|
|
138
|
+
cancelled: boolean;
|
|
139
|
+
truncated: boolean;
|
|
140
|
+
fullOutputPath: string | null;
|
|
141
|
+
}
|
|
142
|
+
export interface PiNativeBashChannel {
|
|
143
|
+
execute(source: PluginSource, input: PiBashExecuteInput): Promise<PiBashResult>;
|
|
144
|
+
abort(source: PluginSource): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
export interface PiNativeBrowserChannel {
|
|
147
|
+
prompt(source: PluginSource, input: PiPromptInput): Promise<PiPromptResult>;
|
|
148
|
+
readonly commands: PiNativeCommandChannel;
|
|
149
|
+
readonly tools: PiNativeToolMetadataChannel;
|
|
150
|
+
readonly bash: PiNativeBashChannel;
|
|
151
|
+
interrupt(source: PluginSource): Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
export type BrowserNotificationLevel = PluginNotificationLevel;
|
|
154
|
+
export interface BrowserNotificationInput {
|
|
155
|
+
level: BrowserNotificationLevel;
|
|
156
|
+
title: string;
|
|
157
|
+
description?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface BrowserPluginGlobalStateHost {
|
|
160
|
+
getSnapshot(): PluginJsonObject | null;
|
|
161
|
+
subscribe(listener: () => void): PluginDisposer;
|
|
162
|
+
}
|
|
163
|
+
export interface BrowserPluginHost {
|
|
164
|
+
readonly settings: HostSettings;
|
|
165
|
+
notify(input: BrowserNotificationInput): void;
|
|
166
|
+
readonly globalState: BrowserPluginGlobalStateHost;
|
|
167
|
+
readonly piDesk: PiDeskBrowserChannel;
|
|
168
|
+
readonly pi: PiNativeBrowserChannel;
|
|
169
|
+
readonly workSessions: BrowserWorkSessionHost;
|
|
170
|
+
readonly workSessionFiles: BrowserWorkSessionFileHost;
|
|
171
|
+
readonly projects: {
|
|
172
|
+
preview(directory: string): void;
|
|
173
|
+
};
|
|
174
|
+
readonly terminals?: {
|
|
175
|
+
open(input: {
|
|
176
|
+
cwd: string;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
};
|
|
179
|
+
readonly logs: BrowserPluginLogHost;
|
|
180
|
+
readonly theme: BrowserThemeHost;
|
|
181
|
+
readonly connection: BrowserConnectionHost;
|
|
182
|
+
readonly locale?: BrowserLocaleHost;
|
|
183
|
+
}
|
|
184
|
+
export type BrowserMount<TTarget> = (context: {
|
|
185
|
+
container: HTMLElement;
|
|
186
|
+
target: TTarget;
|
|
187
|
+
host: BrowserPluginHost;
|
|
188
|
+
signal: AbortSignal;
|
|
189
|
+
}) => void | PluginDisposer | Promise<void | PluginDisposer>;
|
|
190
|
+
export interface BrowserApplicationTarget {
|
|
191
|
+
kind: 'application';
|
|
192
|
+
initialContext: BrowserApplicationContext | null;
|
|
193
|
+
close(): void;
|
|
194
|
+
}
|
|
195
|
+
export interface BrowserComposerPanelTarget {
|
|
196
|
+
kind: 'composer-panel';
|
|
197
|
+
source: PluginSource;
|
|
198
|
+
close(): void;
|
|
199
|
+
}
|
|
200
|
+
export type BrowserBeforeLeaveHandler = () => boolean | Promise<boolean>;
|
|
201
|
+
export interface BrowserSettingsPageTarget {
|
|
202
|
+
kind: 'settings-page';
|
|
203
|
+
close(): void;
|
|
204
|
+
setBeforeLeave(handler: BrowserBeforeLeaveHandler | null): void;
|
|
205
|
+
}
|
|
206
|
+
export type BrowserFilePreviewMode = 'session' | 'expanded' | 'standalone';
|
|
207
|
+
export interface BrowserFilePreviewOptions {
|
|
208
|
+
mode?: BrowserFilePreviewMode;
|
|
209
|
+
imagePaths?: readonly string[];
|
|
210
|
+
}
|
|
211
|
+
export interface BrowserWorkSessionFileHost {
|
|
212
|
+
preview(source: PluginSource, path: string, options?: BrowserFilePreviewOptions): void;
|
|
213
|
+
reveal(source: PluginSource, path: string): Promise<void>;
|
|
214
|
+
readImage(source: PluginSource, path: string, signal?: AbortSignal): Promise<Blob | null>;
|
|
215
|
+
}
|
|
216
|
+
export interface BrowserSessionFileHost {
|
|
217
|
+
preview(path: string, options?: BrowserFilePreviewOptions): void;
|
|
218
|
+
reveal(path: string): Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
export interface BrowserSessionSidebarTabTarget {
|
|
221
|
+
kind: 'session-sidebar-tab';
|
|
222
|
+
source: PluginSource;
|
|
223
|
+
cwd: string;
|
|
224
|
+
files: BrowserSessionFileHost;
|
|
225
|
+
}
|
|
226
|
+
export interface TemporaryMessageLocation {
|
|
227
|
+
tempId: string;
|
|
228
|
+
}
|
|
229
|
+
export interface DurableMessageLocation {
|
|
230
|
+
index: number;
|
|
231
|
+
entryId: string;
|
|
232
|
+
}
|
|
233
|
+
export interface PublicMessageUsage {
|
|
234
|
+
inputTokens: number;
|
|
235
|
+
outputTokens: number;
|
|
236
|
+
cacheReadTokens: number;
|
|
237
|
+
costUsd: number;
|
|
238
|
+
}
|
|
239
|
+
export interface PublicMessageFixed {
|
|
240
|
+
timestampMs: number | null;
|
|
241
|
+
viewKey: string;
|
|
242
|
+
type: string;
|
|
243
|
+
status?: 'running' | 'completed' | 'error' | 'aborted';
|
|
244
|
+
hasDetail: boolean;
|
|
245
|
+
usage?: PublicMessageUsage | null;
|
|
246
|
+
}
|
|
247
|
+
export type PublicMessageSnapshot = {
|
|
248
|
+
location: TemporaryMessageLocation | DurableMessageLocation;
|
|
249
|
+
fixed: PublicMessageFixed;
|
|
250
|
+
summary: PluginJsonObject;
|
|
251
|
+
detail?: PluginJsonObject | null;
|
|
252
|
+
};
|
|
253
|
+
export type BrowserMessageHandleListener = () => void;
|
|
254
|
+
export interface BrowserMessageHandle {
|
|
255
|
+
getSnapshot(): PublicMessageSnapshot;
|
|
256
|
+
subscribe(listener: BrowserMessageHandleListener): PluginDisposer;
|
|
257
|
+
loadDetail(): Promise<PluginJsonObject | null>;
|
|
258
|
+
}
|
|
259
|
+
export interface BrowserMessageViewTarget {
|
|
260
|
+
kind: 'message-view';
|
|
261
|
+
message: BrowserMessageHandle;
|
|
262
|
+
reportError(error: unknown): void;
|
|
263
|
+
}
|
|
264
|
+
export interface BrowserApplicationImplementation {
|
|
265
|
+
mount: BrowserMount<BrowserApplicationTarget>;
|
|
266
|
+
}
|
|
267
|
+
export interface BrowserComposerPanelImplementation {
|
|
268
|
+
mount: BrowserMount<BrowserComposerPanelTarget>;
|
|
269
|
+
}
|
|
270
|
+
export interface BrowserSettingsPageImplementation {
|
|
271
|
+
mount: BrowserMount<BrowserSettingsPageTarget>;
|
|
272
|
+
}
|
|
273
|
+
export interface BrowserMessageViewImplementation {
|
|
274
|
+
mount: BrowserMount<BrowserMessageViewTarget>;
|
|
275
|
+
}
|
|
276
|
+
export interface BrowserSessionSidebarTabImplementation {
|
|
277
|
+
mount: BrowserMount<BrowserSessionSidebarTabTarget>;
|
|
278
|
+
}
|
|
279
|
+
export type BrowserContributionImplementation = BrowserApplicationImplementation | BrowserComposerPanelImplementation | BrowserSettingsPageImplementation | BrowserMessageViewImplementation | BrowserSessionSidebarTabImplementation;
|
|
280
|
+
export interface BrowserApplicationResolveContext {
|
|
281
|
+
readonly workSessions: readonly PluginWorkSession[];
|
|
282
|
+
readonly host: BrowserPluginHost;
|
|
283
|
+
readonly signal: AbortSignal;
|
|
284
|
+
}
|
|
285
|
+
export interface BrowserApplicationContributionDefinition {
|
|
286
|
+
label: string;
|
|
287
|
+
title?: string;
|
|
288
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
289
|
+
chrome?: 'host' | 'none';
|
|
290
|
+
resolve?(context: BrowserApplicationResolveContext): boolean | Promise<boolean>;
|
|
291
|
+
load(): Promise<BrowserApplicationImplementation>;
|
|
292
|
+
}
|
|
293
|
+
export interface BrowserComposerPanelContributionDefinition {
|
|
294
|
+
label: string;
|
|
295
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
296
|
+
load(): Promise<BrowserComposerPanelImplementation>;
|
|
297
|
+
}
|
|
298
|
+
export interface BrowserSettingsPageContributionDefinition {
|
|
299
|
+
label: string;
|
|
300
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
301
|
+
load(): Promise<BrowserSettingsPageImplementation>;
|
|
302
|
+
}
|
|
303
|
+
export interface BrowserMessageViewContributionDefinition {
|
|
304
|
+
viewKey: string;
|
|
305
|
+
priority: number;
|
|
306
|
+
load(): Promise<BrowserMessageViewImplementation>;
|
|
307
|
+
}
|
|
308
|
+
export interface BrowserSessionSidebarTabContributionDefinition {
|
|
309
|
+
label: string;
|
|
310
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
311
|
+
load(): Promise<BrowserSessionSidebarTabImplementation>;
|
|
312
|
+
}
|
|
313
|
+
export interface BrowserContributionDefinitionMap {
|
|
314
|
+
application: BrowserApplicationContributionDefinition;
|
|
315
|
+
'composer-panel': BrowserComposerPanelContributionDefinition;
|
|
316
|
+
'settings-page': BrowserSettingsPageContributionDefinition;
|
|
317
|
+
'message-view': BrowserMessageViewContributionDefinition;
|
|
318
|
+
'session-sidebar-tab': BrowserSessionSidebarTabContributionDefinition;
|
|
319
|
+
}
|
|
320
|
+
export interface BrowserContributionImplementationMap {
|
|
321
|
+
application: BrowserApplicationImplementation;
|
|
322
|
+
'composer-panel': BrowserComposerPanelImplementation;
|
|
323
|
+
'settings-page': BrowserSettingsPageImplementation;
|
|
324
|
+
'message-view': BrowserMessageViewImplementation;
|
|
325
|
+
'session-sidebar-tab': BrowserSessionSidebarTabImplementation;
|
|
326
|
+
}
|
|
327
|
+
export type BrowserContributionDescriptor = {
|
|
328
|
+
kind: 'application';
|
|
329
|
+
contributionName: string;
|
|
330
|
+
label: string;
|
|
331
|
+
title: string;
|
|
332
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
333
|
+
chrome: 'host' | 'none';
|
|
334
|
+
} | {
|
|
335
|
+
kind: 'composer-panel';
|
|
336
|
+
contributionName: string;
|
|
337
|
+
label: string;
|
|
338
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
339
|
+
} | {
|
|
340
|
+
kind: 'settings-page';
|
|
341
|
+
contributionName: string;
|
|
342
|
+
label: string;
|
|
343
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
344
|
+
} | {
|
|
345
|
+
kind: 'message-view';
|
|
346
|
+
contributionName: string;
|
|
347
|
+
viewKey: string;
|
|
348
|
+
priority: number;
|
|
349
|
+
} | {
|
|
350
|
+
kind: 'session-sidebar-tab';
|
|
351
|
+
contributionName: string;
|
|
352
|
+
label: string;
|
|
353
|
+
icon?: import('./shared.js').BrowserContributionIcon;
|
|
354
|
+
};
|
|
355
|
+
export interface BrowserPluginNotificationEvent {
|
|
356
|
+
notificationId: string;
|
|
357
|
+
data: PluginJsonObject;
|
|
358
|
+
}
|
|
359
|
+
export type BrowserPluginNotificationEventListener = (event: BrowserPluginNotificationEvent) => void | Promise<void>;
|
|
360
|
+
export interface BrowserPluginNotifications {
|
|
361
|
+
onEvent(name: string, listener: BrowserPluginNotificationEventListener): PluginDisposer;
|
|
362
|
+
}
|
|
363
|
+
export interface BrowserPluginFacade {
|
|
364
|
+
readonly name: string;
|
|
365
|
+
readonly host: BrowserPluginHost;
|
|
366
|
+
readonly notifications: BrowserPluginNotifications;
|
|
367
|
+
notify(input: BrowserNotificationInput): void;
|
|
368
|
+
registerContribution<K extends BrowserContributionKind>(kind: K, contributionName: string, definition: BrowserContributionDefinitionMap[K]): void;
|
|
369
|
+
onPush(listener: (message: PluginPushMessage) => void): PluginDisposer;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* 在用户操作中复制文本,优先使用 Clipboard API,并兼容不安全上下文和旧 WebView。
|
|
373
|
+
*/
|
|
374
|
+
export declare function copyBrowserText(text: string): Promise<boolean>;
|
|
375
|
+
export type BrowserEntryFactory = (plugin: BrowserPluginFacade) => void | PluginDisposer;
|
|
376
|
+
export declare function defineBrowserEntry(factory: BrowserEntryFactory): BrowserEntryFactory;
|
|
377
|
+
export declare class BrowserPluginError extends Error {
|
|
378
|
+
readonly pluginName: string;
|
|
379
|
+
readonly contributionName: string | null;
|
|
380
|
+
readonly phase: string;
|
|
381
|
+
constructor(input: {
|
|
382
|
+
pluginName: string;
|
|
383
|
+
contributionName?: string | null;
|
|
384
|
+
phase: string;
|
|
385
|
+
message: string;
|
|
386
|
+
cause?: unknown;
|
|
387
|
+
});
|
|
388
|
+
}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function copyWithLegacyCommand(text) {
|
|
2
|
+
if (typeof document === 'undefined' || !document.body)
|
|
3
|
+
return false;
|
|
4
|
+
const activeElement = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
5
|
+
const textarea = document.createElement('textarea');
|
|
6
|
+
textarea.value = text;
|
|
7
|
+
textarea.setAttribute('readonly', '');
|
|
8
|
+
textarea.setAttribute('aria-hidden', 'true');
|
|
9
|
+
textarea.style.position = 'fixed';
|
|
10
|
+
textarea.style.top = '-9999px';
|
|
11
|
+
textarea.style.left = '-9999px';
|
|
12
|
+
textarea.style.width = '1px';
|
|
13
|
+
textarea.style.height = '1px';
|
|
14
|
+
textarea.style.opacity = '0';
|
|
15
|
+
try {
|
|
16
|
+
document.body.append(textarea);
|
|
17
|
+
textarea.select();
|
|
18
|
+
textarea.setSelectionRange(0, textarea.value.length);
|
|
19
|
+
return document.execCommand('copy');
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
textarea.remove();
|
|
26
|
+
try {
|
|
27
|
+
activeElement?.focus();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// 焦点恢复失败不影响已完成的复制。
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 在用户操作中复制文本,优先使用 Clipboard API,并兼容不安全上下文和旧 WebView。
|
|
36
|
+
*/
|
|
37
|
+
export async function copyBrowserText(text) {
|
|
38
|
+
const clipboard = typeof navigator === 'undefined' ? undefined : navigator.clipboard;
|
|
39
|
+
if (clipboard?.writeText) {
|
|
40
|
+
try {
|
|
41
|
+
await clipboard.writeText(text);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Clipboard API 被权限或运行环境拒绝时,继续尝试旧版浏览器能力。
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return copyWithLegacyCommand(text);
|
|
49
|
+
}
|
|
50
|
+
export function defineBrowserEntry(factory) {
|
|
51
|
+
if (typeof factory !== 'function')
|
|
52
|
+
throw new Error('Browser Entry factory must be a function');
|
|
53
|
+
return factory;
|
|
54
|
+
}
|
|
55
|
+
export class BrowserPluginError extends Error {
|
|
56
|
+
pluginName;
|
|
57
|
+
contributionName;
|
|
58
|
+
phase;
|
|
59
|
+
constructor(input) {
|
|
60
|
+
super(input.message, { cause: input.cause });
|
|
61
|
+
this.name = 'PiDeskBrowserPluginError';
|
|
62
|
+
this.pluginName = input.pluginName;
|
|
63
|
+
this.contributionName = input.contributionName ?? null;
|
|
64
|
+
this.phase = input.phase;
|
|
65
|
+
}
|
|
66
|
+
}
|