paseo-plugin-zcode-provider 0.0.0-stage → 0.1.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.
Files changed (134) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +29 -0
  3. package/README.md +98 -2
  4. package/client/diagnostics.tsx +397 -0
  5. package/client/setup.tsx +347 -0
  6. package/icon.svg +1 -0
  7. package/index.client.tsx +22 -0
  8. package/index.server.ts +21 -0
  9. package/package.json +75 -4
  10. package/paseo-plugin.json +6 -0
  11. package/server/attachments.ts +150 -0
  12. package/server/build-info.ts +2 -0
  13. package/server/conversation.ts +319 -0
  14. package/server/diagnostics.ts +235 -0
  15. package/server/discovery/discover.ts +225 -0
  16. package/server/discovery/manifest.ts +36 -0
  17. package/server/discovery/types.ts +30 -0
  18. package/server/errors.ts +36 -0
  19. package/server/host/bridge.ts +463 -0
  20. package/server/host/schemas.ts +119 -0
  21. package/server/logger.ts +19 -0
  22. package/server/mapping.ts +270 -0
  23. package/server/models.ts +68 -0
  24. package/server/persistence.ts +146 -0
  25. package/server/presentation.ts +428 -0
  26. package/server/provider.ts +831 -0
  27. package/server/runtime/managed.ts +501 -0
  28. package/server/runtime/pins.ts +72 -0
  29. package/server/runtime-setup.ts +102 -0
  30. package/server/session-types.ts +49 -0
  31. package/server/session.ts +866 -0
  32. package/server/status.ts +89 -0
  33. package/server/timeline.ts +18 -0
  34. package/server/vendor/zcode/LICENSE +202 -0
  35. package/server/vendor/zcode/NOTICE.md +70 -0
  36. package/server/vendor/zcode/THIRD-PARTY-NOTICES.md +37 -0
  37. package/server/vendor/zcode/packages/model-option-map/src/compiler.ts +92 -0
  38. package/server/vendor/zcode/packages/model-option-map/src/evaluator.ts +214 -0
  39. package/server/vendor/zcode/packages/model-option-map/src/index.ts +5 -0
  40. package/server/vendor/zcode/packages/model-option-map/src/merge-patch.ts +97 -0
  41. package/server/vendor/zcode/packages/model-option-map/src/option-maps.ts +42 -0
  42. package/server/vendor/zcode/packages/model-option-map/src/parser.ts +240 -0
  43. package/server/vendor/zcode/packages/model-option-map/src/tokenizer.ts +141 -0
  44. package/server/vendor/zcode/packages/model-option-map/src/types.ts +36 -0
  45. package/server/vendor/zcode/packages/rpc/src/buffer.ts +88 -0
  46. package/server/vendor/zcode/packages/rpc/src/channelClient.ts +275 -0
  47. package/server/vendor/zcode/packages/rpc/src/channelServer.ts +283 -0
  48. package/server/vendor/zcode/packages/rpc/src/channels.shared.ts +66 -0
  49. package/server/vendor/zcode/packages/rpc/src/channels.ts +4 -0
  50. package/server/vendor/zcode/packages/rpc/src/delayedChannel.ts +17 -0
  51. package/server/vendor/zcode/packages/rpc/src/foundation.ts +260 -0
  52. package/server/vendor/zcode/packages/rpc/src/protocol.ts +397 -0
  53. package/server/vendor/zcode/packages/rpc/src/proxy-channel.ts +213 -0
  54. package/server/vendor/zcode/packages/rpc/src/serialization.ts +291 -0
  55. package/server/vendor/zcode/packages/shared/src/account-provider-state.ts +13 -0
  56. package/server/vendor/zcode/packages/shared/src/background-bash-output.ts +24 -0
  57. package/server/vendor/zcode/packages/shared/src/background-task-controls.ts +404 -0
  58. package/server/vendor/zcode/packages/shared/src/bash-output-display.ts +11 -0
  59. package/server/vendor/zcode/packages/shared/src/bots.ts +558 -0
  60. package/server/vendor/zcode/packages/shared/src/browser-use/backend.ts +80 -0
  61. package/server/vendor/zcode/packages/shared/src/browser-use/command-metadata.ts +170 -0
  62. package/server/vendor/zcode/packages/shared/src/browser-use/commands.ts +588 -0
  63. package/server/vendor/zcode/packages/shared/src/browser-use/result.ts +130 -0
  64. package/server/vendor/zcode/packages/shared/src/browser-use/snapshot.ts +77 -0
  65. package/server/vendor/zcode/packages/shared/src/command-types.ts +96 -0
  66. package/server/vendor/zcode/packages/shared/src/config-schema.ts +8 -0
  67. package/server/vendor/zcode/packages/shared/src/cuaAccessibilitySettings.ts +41 -0
  68. package/server/vendor/zcode/packages/shared/src/database-startup.ts +178 -0
  69. package/server/vendor/zcode/packages/shared/src/env.ts +63 -0
  70. package/server/vendor/zcode/packages/shared/src/execution-output-preview.ts +14 -0
  71. package/server/vendor/zcode/packages/shared/src/localTtft.ts +192 -0
  72. package/server/vendor/zcode/packages/shared/src/model-config.ts +123 -0
  73. package/server/vendor/zcode/packages/shared/src/model-execution.ts +23 -0
  74. package/server/vendor/zcode/packages/shared/src/model-provider-family.ts +171 -0
  75. package/server/vendor/zcode/packages/shared/src/model-provider-types.ts +81 -0
  76. package/server/vendor/zcode/packages/shared/src/model-selection.ts +60 -0
  77. package/server/vendor/zcode/packages/shared/src/oauth.ts +203 -0
  78. package/server/vendor/zcode/packages/shared/src/official-mcp-auth.ts +272 -0
  79. package/server/vendor/zcode/packages/shared/src/official-mcp-tool-error.ts +68 -0
  80. package/server/vendor/zcode/packages/shared/src/process-diagnostic.ts +42 -0
  81. package/server/vendor/zcode/packages/shared/src/protocol.ts +369 -0
  82. package/server/vendor/zcode/packages/shared/src/provider-family-connection-selection.ts +32 -0
  83. package/server/vendor/zcode/packages/shared/src/remoteAssetInstallMode.ts +11 -0
  84. package/server/vendor/zcode/packages/shared/src/remoteResourcePackages.ts +91 -0
  85. package/server/vendor/zcode/packages/shared/src/runtimeEnv.ts +315 -0
  86. package/server/vendor/zcode/packages/shared/src/settings-source.ts +10 -0
  87. package/server/vendor/zcode/packages/shared/src/usage-quota.ts +74 -0
  88. package/server/vendor/zcode/packages/shared/src/usage-stats.ts +462 -0
  89. package/server/vendor/zcode/packages/shared/src/validationAppSettings.ts +562 -0
  90. package/server/vendor/zcode/packages/shared/src/workspacePurpose.ts +2 -0
  91. package/server/vendor/zcode/packages/shared/src/wslUserValidation.ts +33 -0
  92. package/server/vendor/zcode/packages/shared/src/zcode-agent-policy.ts +25 -0
  93. package/server/vendor/zcode/packages/shared/src/zcode-media-policy.ts +10 -0
  94. package/server/vendor/zcode/packages/shared/src/zcode-protocol/index.ts +3720 -0
  95. package/server/vendor/zcode/packages/shared/src/zcode-protocol-legacy-types.ts +529 -0
  96. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/apply.ts +218 -0
  97. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/attachment-ref.ts +14 -0
  98. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/command.ts +482 -0
  99. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/core.ts +100 -0
  100. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/create-workflow-display.ts +156 -0
  101. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/cuaPermission.ts +41 -0
  102. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/delta.ts +147 -0
  103. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/input-intent.ts +69 -0
  104. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/rows.ts +432 -0
  105. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/session-config.ts +43 -0
  106. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index-workflow-activity.ts +195 -0
  107. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index.ts +85 -0
  108. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-import.ts +38 -0
  109. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-ref.ts +10 -0
  110. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/snapshot.ts +509 -0
  111. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/submission.ts +5 -0
  112. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/toolDisplay.ts +264 -0
  113. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/transport.ts +1152 -0
  114. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-assembler.ts +574 -0
  115. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-binary.ts +65 -0
  116. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-codec.ts +240 -0
  117. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-fault.ts +39 -0
  118. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire.ts +159 -0
  119. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-artifacts.ts +291 -0
  120. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-observation-display.ts +281 -0
  121. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-row-meta.ts +163 -0
  122. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-run-settings-command.ts +62 -0
  123. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs-delta.ts +517 -0
  124. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs.ts +512 -0
  125. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-config.ts +81 -0
  126. package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-hook-review.ts +210 -0
  127. package/server/vendor/zcode/packages/shared/src/zcode-task-mode-schema.ts +6 -0
  128. package/server/vendor/zcode/packages/shared/src/zcode-task-types-core.ts +1187 -0
  129. package/server/vendor/zcode/packages/shared/src/zcodeEndpoint.ts +296 -0
  130. package/server/vendor/zcode/provenance.json +405 -0
  131. package/shared/diagnostics.ts +52 -0
  132. package/shared/runtime-setup.ts +75 -0
  133. package/vendor/acp-registry/LICENSE +176 -0
  134. package/vendor/paseo/LICENSE +211 -0
@@ -0,0 +1,347 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { Platform, Text, View } from "react-native";
3
+ import { type PluginSurfaceProps, useRpc } from "@getpaseo/plugin/client";
4
+ import {
5
+ SettingsAction,
6
+ SettingsCard,
7
+ SettingsRow,
8
+ SettingsSection,
9
+ } from "@getpaseo/plugin/client/ui";
10
+ import {
11
+ zcodeRuntimeInstall,
12
+ zcodeRuntimeRemove,
13
+ zcodeRuntimeStatus,
14
+ type RuntimeSetupStatus,
15
+ } from "../shared/runtime-setup";
16
+
17
+ type Theme = PluginSurfaceProps["theme"];
18
+ type Job = RuntimeSetupStatus["job"];
19
+
20
+ function Value({
21
+ children,
22
+ color,
23
+ compact,
24
+ }: {
25
+ children: string;
26
+ color: string;
27
+ compact: boolean;
28
+ }) {
29
+ return (
30
+ <Text
31
+ selectable
32
+ style={{ color, fontSize: compact ? 13 : 14, lineHeight: 20 }}
33
+ >
34
+ {children}
35
+ </Text>
36
+ );
37
+ }
38
+
39
+ const megabytes = (bytes: number) => `${(bytes / 1_000_000).toFixed(1)} MB`;
40
+
41
+ function jobLabel(job: Job): string {
42
+ switch (job.state) {
43
+ case "idle":
44
+ return "Not started";
45
+ case "succeeded":
46
+ return "Completed";
47
+ case "failed":
48
+ return `Failed (${job.code})`;
49
+ case "running": {
50
+ const name = job.component === "node" ? "Node.js" : "ZCode runtime";
51
+ if (job.phase !== "download") return `${name}: ${job.phase}ing`;
52
+ const percent =
53
+ job.totalBytes > 0
54
+ ? Math.floor((job.receivedBytes / job.totalBytes) * 100)
55
+ : 0;
56
+ return `${name}: downloading ${percent}% of ${megabytes(job.totalBytes)}`;
57
+ }
58
+ }
59
+ }
60
+
61
+ function Components({
62
+ status,
63
+ theme,
64
+ compact,
65
+ }: {
66
+ status: RuntimeSetupStatus;
67
+ theme: Theme;
68
+ compact: boolean;
69
+ }) {
70
+ return (
71
+ <>
72
+ {status.components.map((component) => (
73
+ <SettingsSection
74
+ key={component.id}
75
+ title={`${component.name} ${component.version}`}
76
+ >
77
+ <SettingsCard>
78
+ <SettingsRow label="Status">
79
+ <Value
80
+ color={
81
+ component.installed
82
+ ? theme.colors.statusSuccess
83
+ : theme.colors.foregroundMuted
84
+ }
85
+ compact={compact}
86
+ >
87
+ {component.installed ? "Installed" : "Not installed"}
88
+ </Value>
89
+ </SettingsRow>
90
+ <SettingsRow label="Source" hint={megabytes(component.sizeBytes)}>
91
+ <Value color={theme.colors.foregroundMuted} compact={compact}>
92
+ {component.url}
93
+ </Value>
94
+ </SettingsRow>
95
+ <SettingsRow label="SHA-256" hint="Checked before extraction">
96
+ <Value color={theme.colors.foregroundMuted} compact={compact}>
97
+ {component.sha256}
98
+ </Value>
99
+ </SettingsRow>
100
+ <SettingsRow label="License">
101
+ <Value color={theme.colors.foregroundMuted} compact={compact}>
102
+ {component.license}
103
+ </Value>
104
+ </SettingsRow>
105
+ </SettingsCard>
106
+ </SettingsSection>
107
+ ))}
108
+ </>
109
+ );
110
+ }
111
+
112
+ export function SetupScreen({ theme, layout }: PluginSurfaceProps) {
113
+ const fetchStatus = useRpc(zcodeRuntimeStatus);
114
+ const install = useRpc(zcodeRuntimeInstall);
115
+ const remove = useRpc(zcodeRuntimeRemove);
116
+ const [status, setStatus] = useState<RuntimeSetupStatus | null>(null);
117
+ const [requestError, setRequestError] = useState<string | null>(null);
118
+ const [removeMessage, setRemoveMessage] = useState<string | null>(null);
119
+ const [confirmRemove, setConfirmRemove] = useState(false);
120
+ const [pending, setPending] = useState(false);
121
+ const compact = layout.compact;
122
+
123
+ const refresh = useCallback(async () => {
124
+ try {
125
+ setStatus(await fetchStatus({}));
126
+ setRequestError(null);
127
+ } catch (cause) {
128
+ setRequestError(
129
+ cause instanceof Error ? cause.message : "The setup request failed.",
130
+ );
131
+ }
132
+ }, [fetchStatus]);
133
+
134
+ useEffect(() => {
135
+ void refresh();
136
+ }, [refresh]);
137
+
138
+ const running = status?.job.state === "running";
139
+ useEffect(() => {
140
+ if (!running) return;
141
+ const timer = setInterval(() => void refresh(), 1000);
142
+ return () => clearInterval(timer);
143
+ }, [running, refresh]);
144
+
145
+ const run = useCallback(
146
+ async (action: () => Promise<unknown>) => {
147
+ setPending(true);
148
+ try {
149
+ await action();
150
+ } catch (cause) {
151
+ setRequestError(
152
+ cause instanceof Error ? cause.message : "The setup request failed.",
153
+ );
154
+ } finally {
155
+ setPending(false);
156
+ await refresh();
157
+ }
158
+ },
159
+ [refresh],
160
+ );
161
+
162
+ if (status === null)
163
+ return (
164
+ <SettingsSection title="ZCode runtime setup">
165
+ <SettingsCard>
166
+ <SettingsRow label="Status">
167
+ <Value color={theme.colors.foregroundMuted} compact={compact}>
168
+ {requestError ?? "Checking the managed runtime…"}
169
+ </Value>
170
+ </SettingsRow>
171
+ </SettingsCard>
172
+ </SettingsSection>
173
+ );
174
+
175
+ const installed =
176
+ status.components.length > 0 &&
177
+ status.components.every((component) => component.installed);
178
+ const total = status.components
179
+ .filter((component) => !component.installed)
180
+ .reduce((sum, component) => sum + component.sizeBytes, 0);
181
+ const busy = pending || running;
182
+
183
+ return (
184
+ <View style={{ gap: compact ? 16 : 24 }}>
185
+ <SettingsSection title="ZCode runtime setup">
186
+ <SettingsCard>
187
+ <SettingsRow label="Downloads from">
188
+ <Value color={theme.colors.foreground} compact={compact}>
189
+ nodejs.org and this plugin's GitHub releases
190
+ </Value>
191
+ </SettingsRow>
192
+ <SettingsRow
193
+ label="ZCode build"
194
+ hint="ZCode does not publish its CLI; CI builds the unmodified source."
195
+ >
196
+ <Value color={theme.colors.foreground} compact={compact}>
197
+ Unofficial, not endorsed by ZCode or Z.ai
198
+ </Value>
199
+ </SettingsRow>
200
+ <SettingsRow label="Runs as">
201
+ <Value color={theme.colors.foreground} compact={compact}>
202
+ The daemon user, on the daemon machine
203
+ </Value>
204
+ </SettingsRow>
205
+ <SettingsRow label="Changes">
206
+ <Value color={theme.colors.foreground} compact={compact}>
207
+ Only the destination below; PATH is untouched
208
+ </Value>
209
+ </SettingsRow>
210
+ <SettingsRow label="Destination">
211
+ <Value color={theme.colors.foregroundMuted} compact={compact}>
212
+ {status.directory}
213
+ </Value>
214
+ </SettingsRow>
215
+ <SettingsRow label="Platform">
216
+ <Value
217
+ color={
218
+ status.supported
219
+ ? theme.colors.foregroundMuted
220
+ : theme.colors.statusDanger
221
+ }
222
+ compact={compact}
223
+ >
224
+ {status.supported
225
+ ? status.platform
226
+ : `${status.platform} is not supported. Set PASEO_ZCODE_RUNTIME and PASEO_ZCODE_NODE instead.`}
227
+ </Value>
228
+ </SettingsRow>
229
+ {status.override ? (
230
+ <SettingsRow
231
+ label="Environment override"
232
+ hint="Unset both variables and restart the daemon to use the managed runtime."
233
+ >
234
+ <Value color={theme.colors.statusWarning} compact={compact}>
235
+ PASEO_ZCODE_RUNTIME / PASEO_ZCODE_NODE are set, so sessions use
236
+ them instead of this runtime.
237
+ </Value>
238
+ </SettingsRow>
239
+ ) : null}
240
+ <SettingsRow
241
+ label="Progress"
242
+ error={status.job.state === "failed" ? status.job.message : null}
243
+ >
244
+ <Value
245
+ color={
246
+ status.job.state === "failed"
247
+ ? theme.colors.statusDanger
248
+ : theme.colors.foregroundMuted
249
+ }
250
+ compact={compact}
251
+ >
252
+ {jobLabel(status.job)}
253
+ </Value>
254
+ </SettingsRow>
255
+ </SettingsCard>
256
+ {status.supported ? (
257
+ <SettingsAction
258
+ label={installed ? "Runtime installed" : "Install runtime"}
259
+ hint={installed ? undefined : `Downloads ${megabytes(total)}`}
260
+ actionLabel={
261
+ running
262
+ ? "Installing…"
263
+ : installed
264
+ ? "Installed"
265
+ : "Download and install"
266
+ }
267
+ disabled={busy || installed}
268
+ onPress={() => void run(() => install({}))}
269
+ />
270
+ ) : null}
271
+ </SettingsSection>
272
+ <Components status={status} theme={theme} compact={compact} />
273
+ {status.loginCommand === undefined ? null : (
274
+ <SettingsSection title="Sign in to ZCode">
275
+ <SettingsCard>
276
+ <SettingsRow label="Run it">
277
+ <Value color={theme.colors.foreground} compact={compact}>
278
+ In a terminal on the daemon machine
279
+ </Value>
280
+ </SettingsRow>
281
+ <SettingsRow label="Authorization">
282
+ <Value color={theme.colors.foreground} compact={compact}>
283
+ Opens a browser; add --no-browser to print the URL
284
+ </Value>
285
+ </SettingsRow>
286
+ {/* A full-width block: a row value would squeeze the label column. */}
287
+ <View style={{ padding: compact ? 12 : 16 }}>
288
+ <Text
289
+ selectable
290
+ style={{
291
+ color: theme.colors.foreground,
292
+ fontFamily: Platform.select({
293
+ ios: "Menlo",
294
+ default: "monospace",
295
+ }),
296
+ fontSize: compact ? 12 : 13,
297
+ lineHeight: 20,
298
+ }}
299
+ >
300
+ {status.loginCommand}
301
+ </Text>
302
+ </View>
303
+ </SettingsCard>
304
+ </SettingsSection>
305
+ )}
306
+ <SettingsSection title="Remove">
307
+ <SettingsAction
308
+ label="Managed runtime"
309
+ hint={
310
+ removeMessage ??
311
+ "Deletes the destination directory. Stop ZCode sessions first. ZCode settings, logins and conversations are kept."
312
+ }
313
+ actionLabel={confirmRemove ? "Confirm removal" : "Remove"}
314
+ disabled={busy}
315
+ onPress={() => {
316
+ if (!confirmRemove) {
317
+ setConfirmRemove(true);
318
+ return;
319
+ }
320
+ setConfirmRemove(false);
321
+ void run(async () => {
322
+ const result = await remove({});
323
+ setRemoveMessage(
324
+ result.status === "removed"
325
+ ? "Removed."
326
+ : `Removal failed: ${result.message}`,
327
+ );
328
+ });
329
+ }}
330
+ />
331
+ </SettingsSection>
332
+ {requestError === null ? null : (
333
+ <SettingsSection title="Last request">
334
+ <Text
335
+ accessibilityRole="alert"
336
+ style={{
337
+ color: theme.colors.statusDanger,
338
+ fontSize: compact ? 13 : 14,
339
+ }}
340
+ >
341
+ {requestError}
342
+ </Text>
343
+ </SettingsSection>
344
+ )}
345
+ </View>
346
+ );
347
+ }
package/icon.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" fill-rule="evenodd"><title>Z.ai</title><path d="M8.07 1.333L6.618 3.302H.435L1.887 1.333h6.184zM15.503 12.699L14.052 14.667h-6.161l1.449-1.968h6.163zM16 1.333L6.176 14.667H0L9.824 1.333H16z"/></svg>
@@ -0,0 +1,22 @@
1
+ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { DiagnosticsScreen } from "./client/diagnostics";
3
+ import { SetupScreen } from "./client/setup";
4
+
5
+ export default function contribute(client: PluginClientContext): () => void {
6
+ const removeSetup = client.addSettingsScreen({
7
+ id: "setup",
8
+ title: "Setup",
9
+ icon: "Download",
10
+ Component: SetupScreen,
11
+ });
12
+ const removeDiagnostics = client.addSettingsScreen({
13
+ id: "diagnostics",
14
+ title: "Diagnostics",
15
+ icon: "Activity",
16
+ Component: DiagnosticsScreen,
17
+ });
18
+ return () => {
19
+ removeSetup();
20
+ removeDiagnostics();
21
+ };
22
+ }
@@ -0,0 +1,21 @@
1
+ import type { PluginServerContext } from "@getpaseo/plugin/server";
2
+ import { createZCodeProvider } from "./server/provider.js";
3
+ import { ManagedRuntimeInstaller } from "./server/runtime/managed.js";
4
+ import { createRuntimeSetupHandlers } from "./server/runtime-setup.js";
5
+ import { createDiagnosticsHandler } from "./server/status.js";
6
+ import { zcodeDiagnostics } from "./shared/diagnostics.js";
7
+ import {
8
+ zcodeRuntimeInstall,
9
+ zcodeRuntimeRemove,
10
+ zcodeRuntimeStatus,
11
+ } from "./shared/runtime-setup.js";
12
+
13
+ export default function contribute(server: PluginServerContext): () => void {
14
+ server.registerProvider(createZCodeProvider());
15
+ server.handle(zcodeDiagnostics, createDiagnosticsHandler());
16
+ const setup = createRuntimeSetupHandlers(new ManagedRuntimeInstaller());
17
+ server.handle(zcodeRuntimeStatus, setup.status);
18
+ server.handle(zcodeRuntimeInstall, setup.install);
19
+ server.handle(zcodeRuntimeRemove, setup.remove);
20
+ return () => {};
21
+ }
package/package.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "name": "paseo-plugin-zcode-provider",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Unofficial Paseo provider plugin for ZCode, using the official stdio Services Server of the integrated ZCode CLI.",
5
+ "keywords": [
6
+ "paseo",
7
+ "paseo-plugin",
8
+ "zcode",
9
+ "z.ai",
10
+ "glm"
11
+ ],
12
+ "homepage": "https://github.com/supermomonga/paseo-plugin-zcode-provider#readme",
13
+ "bugs": "https://github.com/supermomonga/paseo-plugin-zcode-provider/issues",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/supermomonga/paseo-plugin-zcode-provider.git"
17
+ },
18
+ "license": "MIT",
19
+ "type": "module",
20
+ "files": [
21
+ "paseo-plugin.json",
22
+ "index.client.tsx",
23
+ "index.server.ts",
24
+ "icon.svg",
25
+ "client/",
26
+ "server/",
27
+ "shared/",
28
+ "NOTICE.md",
29
+ "vendor/",
30
+ "!**/*.test.ts"
31
+ ],
32
+ "engines": {
33
+ "node": ">=22.12.0"
34
+ },
35
+ "scripts": {
36
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.client.json",
37
+ "test": "vitest run",
38
+ "test:upstream": "node scripts/check-upstream.mjs",
39
+ "test:runtime": "node scripts/check-runtime.mjs",
40
+ "test:steering-runtime": "node scripts/check-steering-runtime.mjs",
41
+ "build": "node scripts/build.mjs",
42
+ "format": "prettier --write index.client.tsx index.server.ts client server shared scripts test docs README.md NOTICE.md package.json tsconfig.json tsconfig.client.json vitest.config.ts paseo-plugin.json .github/workflows",
43
+ "format:check": "prettier --check index.client.tsx index.server.ts client server shared scripts test docs README.md NOTICE.md package.json tsconfig.json tsconfig.client.json vitest.config.ts paseo-plugin.json .github/workflows",
44
+ "check:zcode-releases": "node scripts/check-zcode-releases.mjs",
45
+ "check:paseo-releases": "node scripts/check-paseo-releases.mjs",
46
+ "prepare": "node scripts/generate-build-info.mjs",
47
+ "prebuild": "node scripts/generate-build-info.mjs",
48
+ "test:model-plan-runtime": "node scripts/check-model-plan-runtime.mjs",
49
+ "test:e2e": "node scripts/check-e2e.mjs",
50
+ "check:zcode-source": "node scripts/sync-zcode-source.mjs",
51
+ "test:stdio-runtime": "node scripts/check-stdio-runtime.mjs",
52
+ "test:native-restore": "node scripts/check-stdio-runtime.mjs --check-native-restore",
53
+ "setup:managed-runtime": "node scripts/install-managed-runtime.mjs",
54
+ "prepack": "node scripts/pack-manifest.mjs prepack",
55
+ "postpack": "node scripts/pack-manifest.mjs postpack"
56
+ },
57
+ "dependencies": {
58
+ "semver": "7.8.5"
59
+ },
60
+ "devDependencies": {
61
+ "@getpaseo/client": "0.9.0-beta.1",
62
+ "@getpaseo/plugin": "0.9.0-beta.1",
63
+ "@getpaseo/protocol": "0.9.0-beta.1",
64
+ "@types/node": "22.18.3",
65
+ "@types/react": "~19.2.0",
66
+ "@types/semver": "7.8.0",
67
+ "cheerio": "1.2.0",
68
+ "esbuild": "0.25.12",
69
+ "prettier": "3.6.2",
70
+ "react": "19.1.0",
71
+ "react-native": "0.81.5",
72
+ "turndown": "7.2.4",
73
+ "typescript": "5.9.2",
74
+ "vitest": "3.2.7",
75
+ "zod": "4.4.3"
76
+ }
77
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "zcode-provider",
3
+ "requirements": {
4
+ "paseo": ">=0.8.0"
5
+ }
6
+ }
@@ -0,0 +1,150 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { readFile } from "node:fs/promises";
3
+ import { z } from "zod";
4
+ import type { HostBridge } from "./host/bridge.js";
5
+ import type { NativePrompt } from "./mapping.js";
6
+ import { AdapterError } from "./errors.js";
7
+
8
+ const progress = z.object({
9
+ uploadId: z.string(),
10
+ nextChunkIndex: z.number().int().nonnegative(),
11
+ });
12
+ const begun = z.discriminatedUnion("state", [
13
+ progress.extend({ state: z.literal("staging") }),
14
+ progress.extend({ state: z.literal("committed"), ref: z.string().min(1) }),
15
+ ]);
16
+ const reference = z.object({ ref: z.string().min(1) }).strict();
17
+ const metadata = z.object({
18
+ fileName: z
19
+ .string()
20
+ .min(1)
21
+ .max(255)
22
+ .regex(/^[^\0\r\n]+$/),
23
+ mime: z
24
+ .string()
25
+ .min(3)
26
+ .max(255)
27
+ .regex(
28
+ /^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$/,
29
+ ),
30
+ bytes: z
31
+ .number()
32
+ .int()
33
+ .min(0)
34
+ .max(20 * 1024 * 1024),
35
+ });
36
+ const chunkBytes = 512 * 1024;
37
+
38
+ /** Transfer validated input to ZCode's persisted attachment store before admission. */
39
+ export async function uploadAttachments(
40
+ bridge: HostBridge,
41
+ workspacePath: string,
42
+ sessionId: string,
43
+ attachments: NativePrompt["attachments"],
44
+ assertSending: () => void,
45
+ ) {
46
+ const refs: Array<z.infer<typeof metadata> & { ref: string }> = [];
47
+ for (const attachment of attachments) {
48
+ assertSending();
49
+ const info = metadata.safeParse({
50
+ fileName: attachment.filename,
51
+ mime: attachment.mimeType,
52
+ bytes: attachment.sizeBytes,
53
+ });
54
+ if (!info.success)
55
+ throw new AdapterError(
56
+ "UNSUPPORTED_CONTENT",
57
+ "Attachment exceeds ZCode's size limit or has invalid metadata",
58
+ );
59
+ if (
60
+ !attachment.localPath &&
61
+ (attachment.dataBase64 === undefined ||
62
+ !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(
63
+ attachment.dataBase64,
64
+ ))
65
+ )
66
+ throw new AdapterError(
67
+ "UNSUPPORTED_CONTENT",
68
+ "Attachment has invalid base64 data",
69
+ );
70
+ const data = attachment.localPath
71
+ ? await readFile(attachment.localPath)
72
+ : Buffer.from(attachment.dataBase64!, "base64");
73
+ if (data.length !== info.data.bytes)
74
+ throw new AdapterError(
75
+ "UNSUPPORTED_CONTENT",
76
+ "Attachment changed after validation",
77
+ );
78
+ const uploadId = randomUUID();
79
+ const target = { workspacePath, sessionId, uploadId };
80
+ try {
81
+ const start = await bridge.request(
82
+ "attachmentBeginV4",
83
+ {
84
+ ...target,
85
+ fileName: info.data.fileName,
86
+ mime: info.data.mime,
87
+ totalBytes: data.length,
88
+ totalChunks: Math.ceil(data.length / chunkBytes),
89
+ checksum: `sha256:${createHash("sha256").update(data).digest("hex")}`,
90
+ },
91
+ begun,
92
+ );
93
+ if (
94
+ start.uploadId !== uploadId ||
95
+ start.state !== "staging" ||
96
+ start.nextChunkIndex !== 0
97
+ )
98
+ throw new AdapterError(
99
+ "NATIVE_PROTOCOL_ERROR",
100
+ "Unexpected attachment upload acknowledgement",
101
+ );
102
+ for (
103
+ let offset = 0, chunkIndex = 0;
104
+ offset < data.length;
105
+ offset += chunkBytes, chunkIndex++
106
+ ) {
107
+ assertSending();
108
+ const chunk = await bridge.request(
109
+ "attachmentChunkV4",
110
+ {
111
+ ...target,
112
+ chunkIndex,
113
+ dataBase64: data
114
+ .subarray(offset, offset + chunkBytes)
115
+ .toString("base64"),
116
+ },
117
+ progress,
118
+ );
119
+ if (
120
+ chunk.uploadId !== uploadId ||
121
+ chunk.nextChunkIndex !== chunkIndex + 1
122
+ )
123
+ throw new AdapterError(
124
+ "NATIVE_PROTOCOL_ERROR",
125
+ "Unexpected attachment chunk acknowledgement",
126
+ );
127
+ }
128
+ assertSending();
129
+ const committed = await bridge.request(
130
+ "attachmentCommitV4",
131
+ target,
132
+ reference,
133
+ );
134
+ refs.push({ ...info.data, ref: committed.ref });
135
+ } catch (error) {
136
+ // Abort staged bytes; never retry a command whose result is unknown.
137
+ try {
138
+ await bridge.request(
139
+ "attachmentAbortV4",
140
+ target,
141
+ z.object({}).strict(),
142
+ );
143
+ } catch {
144
+ /* The host expires staging storage after disconnection. */
145
+ }
146
+ throw error;
147
+ }
148
+ }
149
+ return refs;
150
+ }
@@ -0,0 +1,2 @@
1
+ // Generated from package.json by npm prepare / prebuild.
2
+ export const PROVIDER_VERSION = "0.1.0";