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.
- package/LICENSE +21 -0
- package/NOTICE.md +29 -0
- package/README.md +98 -2
- package/client/diagnostics.tsx +397 -0
- package/client/setup.tsx +347 -0
- package/icon.svg +1 -0
- package/index.client.tsx +22 -0
- package/index.server.ts +21 -0
- package/package.json +75 -4
- package/paseo-plugin.json +6 -0
- package/server/attachments.ts +150 -0
- package/server/build-info.ts +2 -0
- package/server/conversation.ts +319 -0
- package/server/diagnostics.ts +235 -0
- package/server/discovery/discover.ts +225 -0
- package/server/discovery/manifest.ts +36 -0
- package/server/discovery/types.ts +30 -0
- package/server/errors.ts +36 -0
- package/server/host/bridge.ts +463 -0
- package/server/host/schemas.ts +119 -0
- package/server/logger.ts +19 -0
- package/server/mapping.ts +270 -0
- package/server/models.ts +68 -0
- package/server/persistence.ts +146 -0
- package/server/presentation.ts +428 -0
- package/server/provider.ts +831 -0
- package/server/runtime/managed.ts +501 -0
- package/server/runtime/pins.ts +72 -0
- package/server/runtime-setup.ts +102 -0
- package/server/session-types.ts +49 -0
- package/server/session.ts +866 -0
- package/server/status.ts +89 -0
- package/server/timeline.ts +18 -0
- package/server/vendor/zcode/LICENSE +202 -0
- package/server/vendor/zcode/NOTICE.md +70 -0
- package/server/vendor/zcode/THIRD-PARTY-NOTICES.md +37 -0
- package/server/vendor/zcode/packages/model-option-map/src/compiler.ts +92 -0
- package/server/vendor/zcode/packages/model-option-map/src/evaluator.ts +214 -0
- package/server/vendor/zcode/packages/model-option-map/src/index.ts +5 -0
- package/server/vendor/zcode/packages/model-option-map/src/merge-patch.ts +97 -0
- package/server/vendor/zcode/packages/model-option-map/src/option-maps.ts +42 -0
- package/server/vendor/zcode/packages/model-option-map/src/parser.ts +240 -0
- package/server/vendor/zcode/packages/model-option-map/src/tokenizer.ts +141 -0
- package/server/vendor/zcode/packages/model-option-map/src/types.ts +36 -0
- package/server/vendor/zcode/packages/rpc/src/buffer.ts +88 -0
- package/server/vendor/zcode/packages/rpc/src/channelClient.ts +275 -0
- package/server/vendor/zcode/packages/rpc/src/channelServer.ts +283 -0
- package/server/vendor/zcode/packages/rpc/src/channels.shared.ts +66 -0
- package/server/vendor/zcode/packages/rpc/src/channels.ts +4 -0
- package/server/vendor/zcode/packages/rpc/src/delayedChannel.ts +17 -0
- package/server/vendor/zcode/packages/rpc/src/foundation.ts +260 -0
- package/server/vendor/zcode/packages/rpc/src/protocol.ts +397 -0
- package/server/vendor/zcode/packages/rpc/src/proxy-channel.ts +213 -0
- package/server/vendor/zcode/packages/rpc/src/serialization.ts +291 -0
- package/server/vendor/zcode/packages/shared/src/account-provider-state.ts +13 -0
- package/server/vendor/zcode/packages/shared/src/background-bash-output.ts +24 -0
- package/server/vendor/zcode/packages/shared/src/background-task-controls.ts +404 -0
- package/server/vendor/zcode/packages/shared/src/bash-output-display.ts +11 -0
- package/server/vendor/zcode/packages/shared/src/bots.ts +558 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/backend.ts +80 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/command-metadata.ts +170 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/commands.ts +588 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/result.ts +130 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/snapshot.ts +77 -0
- package/server/vendor/zcode/packages/shared/src/command-types.ts +96 -0
- package/server/vendor/zcode/packages/shared/src/config-schema.ts +8 -0
- package/server/vendor/zcode/packages/shared/src/cuaAccessibilitySettings.ts +41 -0
- package/server/vendor/zcode/packages/shared/src/database-startup.ts +178 -0
- package/server/vendor/zcode/packages/shared/src/env.ts +63 -0
- package/server/vendor/zcode/packages/shared/src/execution-output-preview.ts +14 -0
- package/server/vendor/zcode/packages/shared/src/localTtft.ts +192 -0
- package/server/vendor/zcode/packages/shared/src/model-config.ts +123 -0
- package/server/vendor/zcode/packages/shared/src/model-execution.ts +23 -0
- package/server/vendor/zcode/packages/shared/src/model-provider-family.ts +171 -0
- package/server/vendor/zcode/packages/shared/src/model-provider-types.ts +81 -0
- package/server/vendor/zcode/packages/shared/src/model-selection.ts +60 -0
- package/server/vendor/zcode/packages/shared/src/oauth.ts +203 -0
- package/server/vendor/zcode/packages/shared/src/official-mcp-auth.ts +272 -0
- package/server/vendor/zcode/packages/shared/src/official-mcp-tool-error.ts +68 -0
- package/server/vendor/zcode/packages/shared/src/process-diagnostic.ts +42 -0
- package/server/vendor/zcode/packages/shared/src/protocol.ts +369 -0
- package/server/vendor/zcode/packages/shared/src/provider-family-connection-selection.ts +32 -0
- package/server/vendor/zcode/packages/shared/src/remoteAssetInstallMode.ts +11 -0
- package/server/vendor/zcode/packages/shared/src/remoteResourcePackages.ts +91 -0
- package/server/vendor/zcode/packages/shared/src/runtimeEnv.ts +315 -0
- package/server/vendor/zcode/packages/shared/src/settings-source.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/usage-quota.ts +74 -0
- package/server/vendor/zcode/packages/shared/src/usage-stats.ts +462 -0
- package/server/vendor/zcode/packages/shared/src/validationAppSettings.ts +562 -0
- package/server/vendor/zcode/packages/shared/src/workspacePurpose.ts +2 -0
- package/server/vendor/zcode/packages/shared/src/wslUserValidation.ts +33 -0
- package/server/vendor/zcode/packages/shared/src/zcode-agent-policy.ts +25 -0
- package/server/vendor/zcode/packages/shared/src/zcode-media-policy.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol/index.ts +3720 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-legacy-types.ts +529 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/apply.ts +218 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/attachment-ref.ts +14 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/command.ts +482 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/core.ts +100 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/create-workflow-display.ts +156 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/cuaPermission.ts +41 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/delta.ts +147 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/input-intent.ts +69 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/rows.ts +432 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/session-config.ts +43 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index-workflow-activity.ts +195 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index.ts +85 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-import.ts +38 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-ref.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/snapshot.ts +509 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/submission.ts +5 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/toolDisplay.ts +264 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/transport.ts +1152 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-assembler.ts +574 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-binary.ts +65 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-codec.ts +240 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-fault.ts +39 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire.ts +159 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-artifacts.ts +291 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-observation-display.ts +281 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-row-meta.ts +163 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-run-settings-command.ts +62 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs-delta.ts +517 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs.ts +512 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-config.ts +81 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-hook-review.ts +210 -0
- package/server/vendor/zcode/packages/shared/src/zcode-task-mode-schema.ts +6 -0
- package/server/vendor/zcode/packages/shared/src/zcode-task-types-core.ts +1187 -0
- package/server/vendor/zcode/packages/shared/src/zcodeEndpoint.ts +296 -0
- package/server/vendor/zcode/provenance.json +405 -0
- package/shared/diagnostics.ts +52 -0
- package/shared/runtime-setup.ts +75 -0
- package/vendor/acp-registry/LICENSE +176 -0
- package/vendor/paseo/LICENSE +211 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProviderPermissionAction,
|
|
3
|
+
ProviderPermissionRequest,
|
|
4
|
+
ProviderPermissionResponse,
|
|
5
|
+
ProviderTimelineItem,
|
|
6
|
+
ProviderToolCallDetail,
|
|
7
|
+
ProviderUsage,
|
|
8
|
+
} from "@getpaseo/plugin/server/provider";
|
|
9
|
+
import type {
|
|
10
|
+
ConversationRow,
|
|
11
|
+
TimelineMarkerPayload,
|
|
12
|
+
} from "./vendor/zcode/packages/shared/src/zcode-protocol-v4/rows.js";
|
|
13
|
+
import type {
|
|
14
|
+
ConversationSnapshot,
|
|
15
|
+
PendingInteraction,
|
|
16
|
+
} from "./vendor/zcode/packages/shared/src/zcode-protocol-v4/snapshot.js";
|
|
17
|
+
import { AdapterError } from "./errors.js";
|
|
18
|
+
import { jsonValue, record, planMarkdown } from "./mapping.js";
|
|
19
|
+
|
|
20
|
+
export function rowTimeline(
|
|
21
|
+
row: ConversationRow,
|
|
22
|
+
clientMessageId?: string,
|
|
23
|
+
): ProviderTimelineItem | undefined {
|
|
24
|
+
const id = `zcode:row:${row.rowId}`;
|
|
25
|
+
switch (row.kind) {
|
|
26
|
+
case "turnHeader":
|
|
27
|
+
return;
|
|
28
|
+
case "userInput":
|
|
29
|
+
return row.origin === "realUser"
|
|
30
|
+
? {
|
|
31
|
+
id,
|
|
32
|
+
type: "user_message",
|
|
33
|
+
text: [
|
|
34
|
+
row.text,
|
|
35
|
+
...(row.attachments ?? []).map(
|
|
36
|
+
(a) =>
|
|
37
|
+
`[Attachment: ${a.fileName} (${a.mime}, ${a.bytes} bytes)]`,
|
|
38
|
+
),
|
|
39
|
+
]
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.join("\n\n"),
|
|
42
|
+
messageId: row.sourceCommandId ?? row.entityId,
|
|
43
|
+
...(clientMessageId ? { clientMessageId } : {}),
|
|
44
|
+
}
|
|
45
|
+
: { id, type: "notification", level: "info", message: row.text };
|
|
46
|
+
case "assistantText":
|
|
47
|
+
return {
|
|
48
|
+
id,
|
|
49
|
+
type: "assistant_message",
|
|
50
|
+
text: row.text,
|
|
51
|
+
messageId: row.assistantResponseId ?? row.entityId,
|
|
52
|
+
};
|
|
53
|
+
case "reasoning":
|
|
54
|
+
return { id, type: "reasoning", text: row.text };
|
|
55
|
+
case "toolCall": {
|
|
56
|
+
const input = record(row.input);
|
|
57
|
+
const truncated =
|
|
58
|
+
!!row.output?.truncated ||
|
|
59
|
+
(row.output?.display?.kind === "bash_output" &&
|
|
60
|
+
row.output.display.truncated);
|
|
61
|
+
const text =
|
|
62
|
+
(row.output?.text ?? row.error?.message ?? "") +
|
|
63
|
+
(truncated
|
|
64
|
+
? "\n[ZCode truncated this output; the full result has not been loaded.]"
|
|
65
|
+
: "");
|
|
66
|
+
let detail: ProviderToolCallDetail;
|
|
67
|
+
if (row.toolName === "Bash" && typeof input.command === "string")
|
|
68
|
+
detail = { type: "shell", command: input.command, output: text };
|
|
69
|
+
else if (row.toolName === "Read" && typeof input.file_path === "string")
|
|
70
|
+
detail = { type: "read", filePath: input.file_path, content: text };
|
|
71
|
+
else if (row.toolName === "Write" && typeof input.file_path === "string")
|
|
72
|
+
detail = {
|
|
73
|
+
type: "write",
|
|
74
|
+
filePath: input.file_path,
|
|
75
|
+
...(typeof input.content === "string"
|
|
76
|
+
? { content: input.content }
|
|
77
|
+
: {}),
|
|
78
|
+
};
|
|
79
|
+
else if (row.toolName === "Edit" && typeof input.file_path === "string")
|
|
80
|
+
detail = {
|
|
81
|
+
type: "edit",
|
|
82
|
+
filePath: input.file_path,
|
|
83
|
+
...(typeof input.old_string === "string"
|
|
84
|
+
? { oldString: input.old_string }
|
|
85
|
+
: {}),
|
|
86
|
+
...(typeof input.new_string === "string"
|
|
87
|
+
? { newString: input.new_string }
|
|
88
|
+
: {}),
|
|
89
|
+
};
|
|
90
|
+
else
|
|
91
|
+
detail = {
|
|
92
|
+
type: "unknown",
|
|
93
|
+
input: jsonValue(row.input ?? row.inputText),
|
|
94
|
+
output: jsonValue({
|
|
95
|
+
text,
|
|
96
|
+
...(row.output?.display ? { display: row.output.display } : {}),
|
|
97
|
+
truncated,
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
const base = {
|
|
101
|
+
id,
|
|
102
|
+
type: "tool_call" as const,
|
|
103
|
+
callId: row.toolCallId,
|
|
104
|
+
name: row.toolName,
|
|
105
|
+
detail,
|
|
106
|
+
metadata: {
|
|
107
|
+
truncated,
|
|
108
|
+
...(row.backgrounded ? { backgrounded: true } : {}),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
return row.status === "error"
|
|
112
|
+
? { ...base, status: "failed", error: jsonValue(row.error ?? text) }
|
|
113
|
+
: {
|
|
114
|
+
...base,
|
|
115
|
+
status:
|
|
116
|
+
row.status === "success"
|
|
117
|
+
? "completed"
|
|
118
|
+
: row.status === "cancelled"
|
|
119
|
+
? "canceled"
|
|
120
|
+
: "running",
|
|
121
|
+
error: null,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
case "subagent": {
|
|
125
|
+
const base = {
|
|
126
|
+
id,
|
|
127
|
+
type: "tool_call" as const,
|
|
128
|
+
callId: row.entityId ?? `subagent:${row.rowId}`,
|
|
129
|
+
name: row.subagentType,
|
|
130
|
+
detail: {
|
|
131
|
+
type: "sub_agent" as const,
|
|
132
|
+
subAgentType: row.subagentType,
|
|
133
|
+
log: row.summaryText,
|
|
134
|
+
},
|
|
135
|
+
metadata: {
|
|
136
|
+
backgrounded: row.backgrounded === true,
|
|
137
|
+
...(row.childSessionId
|
|
138
|
+
? { zcodeChildSessionId: row.childSessionId }
|
|
139
|
+
: {}),
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
return row.status === "failed"
|
|
143
|
+
? { ...base, status: "failed", error: row.summaryText }
|
|
144
|
+
: {
|
|
145
|
+
...base,
|
|
146
|
+
status:
|
|
147
|
+
row.status === "success"
|
|
148
|
+
? "completed"
|
|
149
|
+
: row.status === "cancelled"
|
|
150
|
+
? "canceled"
|
|
151
|
+
: "running",
|
|
152
|
+
error: null,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
case "artifact":
|
|
156
|
+
return {
|
|
157
|
+
id,
|
|
158
|
+
type: "notification",
|
|
159
|
+
level: "info",
|
|
160
|
+
message: `${row.displayName} (${row.artifactType}, ${row.sizeBytes} bytes)`,
|
|
161
|
+
};
|
|
162
|
+
case "hookInvocation":
|
|
163
|
+
return {
|
|
164
|
+
id,
|
|
165
|
+
type: "notification",
|
|
166
|
+
level: "info",
|
|
167
|
+
message: `${row.hookEventName}: ${row.executions.map((h) => `${h.displayName} (${h.outcome ?? h.state})`).join(", ")}`,
|
|
168
|
+
};
|
|
169
|
+
case "timelineMarker":
|
|
170
|
+
return {
|
|
171
|
+
id,
|
|
172
|
+
type: "notification",
|
|
173
|
+
level: "info",
|
|
174
|
+
message: markerText(row.marker),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export function usage(state: ConversationSnapshot): ProviderUsage {
|
|
179
|
+
return {
|
|
180
|
+
inputTokens: state.usage.cumulative.inputTokens,
|
|
181
|
+
cachedInputTokens: state.usage.cumulative.cacheReadTokens,
|
|
182
|
+
outputTokens: state.usage.cumulative.outputTokens,
|
|
183
|
+
...(state.usage.contextWindow
|
|
184
|
+
? {
|
|
185
|
+
contextWindowUsedTokens: state.usage.contextWindow.usedTokens,
|
|
186
|
+
contextWindowMaxTokens: state.usage.contextWindow.maxTokens,
|
|
187
|
+
}
|
|
188
|
+
: {}),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export interface PresentedInteraction {
|
|
192
|
+
request: ProviderPermissionRequest;
|
|
193
|
+
answer(response: ProviderPermissionResponse): Record<string, unknown>;
|
|
194
|
+
}
|
|
195
|
+
export function presentInteraction(
|
|
196
|
+
interaction: PendingInteraction,
|
|
197
|
+
): PresentedInteraction | undefined {
|
|
198
|
+
const p = interaction.payload,
|
|
199
|
+
id = interaction.interactionId;
|
|
200
|
+
if (p.kind === "workspaceHookReview") return;
|
|
201
|
+
if (p.kind === "permission") {
|
|
202
|
+
const options = p.options.filter((o) => o.optionId !== "fullAccess");
|
|
203
|
+
const actions: ProviderPermissionAction[] = options.map((o) => {
|
|
204
|
+
const behavior =
|
|
205
|
+
o.response?.decision ??
|
|
206
|
+
(o.kind === "deny"
|
|
207
|
+
? "deny"
|
|
208
|
+
: o.kind === "allowOnce" || o.kind === "allowAlways"
|
|
209
|
+
? "allow"
|
|
210
|
+
: undefined);
|
|
211
|
+
if (behavior !== "allow" && behavior !== "deny")
|
|
212
|
+
throw new AdapterError(
|
|
213
|
+
"INTERACTION_UNSUPPORTED",
|
|
214
|
+
"ZCode permission option cannot be represented",
|
|
215
|
+
);
|
|
216
|
+
return {
|
|
217
|
+
id: o.optionId,
|
|
218
|
+
label: o.label,
|
|
219
|
+
behavior,
|
|
220
|
+
variant: behavior === "allow" ? "primary" : "danger",
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
if (!actions.some((a) => a.behavior === "deny"))
|
|
224
|
+
throw new AdapterError(
|
|
225
|
+
"NATIVE_PROTOCOL_ERROR",
|
|
226
|
+
"ZCode permission has no deny option",
|
|
227
|
+
);
|
|
228
|
+
const plan = p.toolName === "ExitPlanMode";
|
|
229
|
+
const markdown = plan ? planMarkdown(p.detail) : undefined;
|
|
230
|
+
return {
|
|
231
|
+
request: {
|
|
232
|
+
id,
|
|
233
|
+
name: plan ? "ZCodePlanApproval" : p.toolName,
|
|
234
|
+
kind: plan ? "plan" : "tool",
|
|
235
|
+
title: plan ? "Plan" : p.toolName,
|
|
236
|
+
description: p.summary,
|
|
237
|
+
actions,
|
|
238
|
+
...(markdown
|
|
239
|
+
? {
|
|
240
|
+
input: { plan: markdown },
|
|
241
|
+
metadata: { planText: markdown, source: "zcode_plan_approval" },
|
|
242
|
+
}
|
|
243
|
+
: {
|
|
244
|
+
detail: {
|
|
245
|
+
type: "unknown",
|
|
246
|
+
input: jsonValue(p.detail ?? null),
|
|
247
|
+
output: null,
|
|
248
|
+
},
|
|
249
|
+
}),
|
|
250
|
+
},
|
|
251
|
+
answer(response) {
|
|
252
|
+
const action = actions.find((a) => a.id === response.selectedActionId);
|
|
253
|
+
if (!action || action.behavior !== response.behavior)
|
|
254
|
+
throw new AdapterError(
|
|
255
|
+
"INVALID_CONFIGURATION",
|
|
256
|
+
"Permission response does not match an offered action",
|
|
257
|
+
);
|
|
258
|
+
return { optionId: action.id };
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (p.sensitive)
|
|
263
|
+
throw new AdapterError(
|
|
264
|
+
"INTERACTION_UNSUPPORTED",
|
|
265
|
+
"Sensitive ZCode input must be completed in the official CLI",
|
|
266
|
+
);
|
|
267
|
+
const questions = p.questions;
|
|
268
|
+
if (!questions?.length)
|
|
269
|
+
throw new AdapterError(
|
|
270
|
+
"INTERACTION_UNSUPPORTED",
|
|
271
|
+
"ZCode question has no representable fields",
|
|
272
|
+
);
|
|
273
|
+
const headers = new Set<string>();
|
|
274
|
+
const prompts = new Set<string>();
|
|
275
|
+
for (const q of questions) {
|
|
276
|
+
if (
|
|
277
|
+
headers.has(q.header) ||
|
|
278
|
+
prompts.has(q.question) ||
|
|
279
|
+
new Set(q.options.map((o) => o.label)).size !== q.options.length ||
|
|
280
|
+
new Set(q.options.map((o) => o.value)).size !== q.options.length ||
|
|
281
|
+
q.options.some((o) => q.multiSelect && o.label.includes(", "))
|
|
282
|
+
)
|
|
283
|
+
throw new AdapterError(
|
|
284
|
+
"INTERACTION_UNSUPPORTED",
|
|
285
|
+
"ZCode question has ambiguous labels",
|
|
286
|
+
);
|
|
287
|
+
headers.add(q.header);
|
|
288
|
+
prompts.add(q.question);
|
|
289
|
+
}
|
|
290
|
+
const plan = record(p.schema).interaction === "plan_approval";
|
|
291
|
+
const answerContent = (answers: Record<string, unknown>) => {
|
|
292
|
+
const content: Record<string, unknown> = {},
|
|
293
|
+
nativeAnswers: Record<string, string[]> = {};
|
|
294
|
+
questions.forEach((q, i) => {
|
|
295
|
+
const value = answers[q.header];
|
|
296
|
+
if (typeof value !== "string")
|
|
297
|
+
throw new AdapterError(
|
|
298
|
+
"INVALID_CONFIGURATION",
|
|
299
|
+
"A ZCode question answer is missing",
|
|
300
|
+
);
|
|
301
|
+
const labels =
|
|
302
|
+
value === "" ? [] : q.multiSelect ? value.split(", ") : [value];
|
|
303
|
+
if (new Set(labels).size !== labels.length)
|
|
304
|
+
throw new AdapterError(
|
|
305
|
+
"INVALID_CONFIGURATION",
|
|
306
|
+
"Duplicate question answer",
|
|
307
|
+
);
|
|
308
|
+
const values = labels.map((label) => {
|
|
309
|
+
const option = q.options.find((o) => o.label === label);
|
|
310
|
+
if (option) return option.value;
|
|
311
|
+
if (p.freeText) return label;
|
|
312
|
+
throw new AdapterError(
|
|
313
|
+
"INVALID_CONFIGURATION",
|
|
314
|
+
"Unknown question option",
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
nativeAnswers[q.question] = values;
|
|
318
|
+
content[`answer_${i}`] = q.multiSelect ? values : (values[0] ?? "");
|
|
319
|
+
if (i === 0) content.answer = content[`answer_${i}`];
|
|
320
|
+
});
|
|
321
|
+
return { ...content, answers: nativeAnswers };
|
|
322
|
+
};
|
|
323
|
+
if (plan) {
|
|
324
|
+
if (questions.length !== 1 || questions[0]!.multiSelect)
|
|
325
|
+
throw new AdapterError(
|
|
326
|
+
"INTERACTION_UNSUPPORTED",
|
|
327
|
+
"Unsupported ZCode Plan approval fields",
|
|
328
|
+
);
|
|
329
|
+
const question = questions[0]!,
|
|
330
|
+
markdown = planMarkdown(p.input);
|
|
331
|
+
const actions: ProviderPermissionAction[] = [
|
|
332
|
+
...question.options.map((o) => ({
|
|
333
|
+
id: o.value,
|
|
334
|
+
label: o.label,
|
|
335
|
+
behavior: "allow" as const,
|
|
336
|
+
variant: "primary" as const,
|
|
337
|
+
intent: "implement" as const,
|
|
338
|
+
})),
|
|
339
|
+
{
|
|
340
|
+
id: `dismiss:${id}`,
|
|
341
|
+
label: "Dismiss",
|
|
342
|
+
behavior: "deny",
|
|
343
|
+
intent: "dismiss",
|
|
344
|
+
variant: "danger",
|
|
345
|
+
},
|
|
346
|
+
];
|
|
347
|
+
return {
|
|
348
|
+
request: {
|
|
349
|
+
id,
|
|
350
|
+
name: "ZCodePlanApproval",
|
|
351
|
+
kind: "plan",
|
|
352
|
+
title: "Plan",
|
|
353
|
+
description: p.prompt,
|
|
354
|
+
input: { plan: markdown },
|
|
355
|
+
metadata: { planText: markdown, source: "zcode_plan_approval" },
|
|
356
|
+
actions,
|
|
357
|
+
},
|
|
358
|
+
answer(response) {
|
|
359
|
+
const action = actions.find((a) => a.id === response.selectedActionId);
|
|
360
|
+
if (!action || action.behavior !== response.behavior)
|
|
361
|
+
throw new AdapterError(
|
|
362
|
+
"INVALID_CONFIGURATION",
|
|
363
|
+
"Plan response does not match an offered action",
|
|
364
|
+
);
|
|
365
|
+
if (action.behavior === "deny") return { action: "decline" };
|
|
366
|
+
return {
|
|
367
|
+
action: "accept",
|
|
368
|
+
content: {
|
|
369
|
+
answer_0: action.id,
|
|
370
|
+
answer: action.id,
|
|
371
|
+
answers: { [question.question]: [action.id] },
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
request: {
|
|
379
|
+
id,
|
|
380
|
+
name: "ZCodeQuestion",
|
|
381
|
+
kind: "question",
|
|
382
|
+
title: p.prompt,
|
|
383
|
+
input: {
|
|
384
|
+
questions: questions.map((q) => ({
|
|
385
|
+
question: q.question,
|
|
386
|
+
header: q.header,
|
|
387
|
+
options: q.options.map((o) => ({
|
|
388
|
+
label: o.label,
|
|
389
|
+
...(o.description ? { description: o.description } : {}),
|
|
390
|
+
})),
|
|
391
|
+
multiSelect: q.multiSelect === true,
|
|
392
|
+
allowOther: p.freeText,
|
|
393
|
+
allowEmpty: true,
|
|
394
|
+
dismissLabel: "Dismiss",
|
|
395
|
+
})),
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
answer(response) {
|
|
399
|
+
return response.behavior === "deny"
|
|
400
|
+
? { action: response.interrupt ? "cancel" : "decline" }
|
|
401
|
+
: {
|
|
402
|
+
action: "accept",
|
|
403
|
+
content: answerContent(record(response.updatedInput?.answers)),
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function markerText(marker: TimelineMarkerPayload): string {
|
|
410
|
+
switch (marker.type) {
|
|
411
|
+
case "compact":
|
|
412
|
+
return `Context compaction: ${marker.status}`;
|
|
413
|
+
case "modelChange":
|
|
414
|
+
return `Model: ${marker.toModel} (${marker.toThought})`;
|
|
415
|
+
case "forkNotice":
|
|
416
|
+
return "Conversation continued from a parent conversation.";
|
|
417
|
+
case "forkCreated":
|
|
418
|
+
return "ZCode created a child conversation.";
|
|
419
|
+
case "goalSet":
|
|
420
|
+
return `Goal: ${marker.objective}`;
|
|
421
|
+
case "goalVerify":
|
|
422
|
+
return `Goal verification: ${marker.outcome}${marker.detail ? ` — ${marker.detail}` : ""}`;
|
|
423
|
+
case "retryNotice":
|
|
424
|
+
return `ZCode is retrying the model request (attempt ${marker.attempt}).`;
|
|
425
|
+
case "checkpointRestored":
|
|
426
|
+
return "ZCode restored a file checkpoint.";
|
|
427
|
+
}
|
|
428
|
+
}
|