@spotpatch/shared 1.12.0 → 1.13.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/dist/annotation-C0Me9mN2.d.cts +102 -0
- package/dist/annotation-C0Me9mN2.d.ts +102 -0
- package/dist/chunk-C2PJ4UUU.js +195 -0
- package/dist/chunk-C2PJ4UUU.js.map +1 -0
- package/dist/chunk-DYTWEIES.js +89 -0
- package/dist/chunk-DYTWEIES.js.map +1 -0
- package/dist/{chunk-JGOIBOFI.js → chunk-FPDSZDP2.js} +16 -2
- package/dist/chunk-FPDSZDP2.js.map +1 -0
- package/dist/chunk-IUTOVI5G.js +584 -0
- package/dist/chunk-IUTOVI5G.js.map +1 -0
- package/dist/{chunk-JU5HIWX7.js → chunk-YQ5GL523.js} +8 -173
- package/dist/chunk-YQ5GL523.js.map +1 -0
- package/dist/contextual-ask-B0mCFn92.d.cts +1451 -0
- package/dist/contextual-ask-B0mCFn92.d.ts +1451 -0
- package/dist/contextual-ask-browser.cjs +200 -0
- package/dist/contextual-ask-browser.cjs.map +1 -0
- package/dist/contextual-ask-browser.d.cts +31 -0
- package/dist/contextual-ask-browser.d.ts +31 -0
- package/dist/contextual-ask-browser.js +66 -0
- package/dist/contextual-ask-browser.js.map +1 -0
- package/dist/contextual-ask-node.cjs +968 -0
- package/dist/contextual-ask-node.cjs.map +1 -0
- package/dist/contextual-ask-node.d.cts +14 -0
- package/dist/contextual-ask-node.d.ts +14 -0
- package/dist/contextual-ask-node.js +122 -0
- package/dist/contextual-ask-node.js.map +1 -0
- package/dist/{data-flow-runtime-oq9m21IP.d.cts → data-flow-runtime-D8HPSb2i.d.cts} +13 -13
- package/dist/{data-flow-runtime-BelOgo8s.d.ts → data-flow-runtime-vKeEaJgT.d.ts} +13 -13
- package/dist/data-flow-runtime.cjs +2 -0
- package/dist/data-flow-runtime.cjs.map +1 -1
- package/dist/data-flow-runtime.d.cts +2 -2
- package/dist/data-flow-runtime.d.ts +2 -2
- package/dist/data-flow-runtime.js +1 -1
- package/dist/{endpoints-GedF44M2.d.cts → endpoints-O3ohYyAo.d.cts} +7 -1
- package/dist/{endpoints-GedF44M2.d.ts → endpoints-O3ohYyAo.d.ts} +7 -1
- package/dist/error-code-DRz2eqcB.d.cts +63 -0
- package/dist/error-code-DRz2eqcB.d.ts +63 -0
- package/dist/external-agent-node.cjs +142 -121
- package/dist/external-agent-node.cjs.map +1 -1
- package/dist/external-agent-node.d.cts +27 -26
- package/dist/external-agent-node.d.ts +27 -26
- package/dist/external-agent-node.js +4 -2
- package/dist/external-agent-node.js.map +1 -1
- package/dist/{external-handoff-BNUyMfNb.d.ts → external-handoff-DighrWn8.d.ts} +30 -130
- package/dist/{external-handoff-BNUyMfNb.d.cts → external-handoff-DwtFFR6F.d.cts} +30 -130
- package/dist/external-handoff-browser.cjs +2 -0
- package/dist/external-handoff-browser.cjs.map +1 -1
- package/dist/external-handoff-browser.d.cts +4 -3
- package/dist/external-handoff-browser.d.ts +4 -3
- package/dist/external-handoff-browser.js +1 -1
- package/dist/index.cjs +1144 -422
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -178
- package/dist/index.d.ts +126 -178
- package/dist/index.js +97 -16
- package/dist/index.js.map +1 -1
- package/package.json +29 -2
- package/dist/chunk-JGOIBOFI.js.map +0 -1
- package/dist/chunk-JU5HIWX7.js.map +0 -1
- package/dist/{external-agent-control-BMoSq_xI.d.cts → external-agent-control-CRBbjDDk.d.cts} +46 -46
- package/dist/{external-agent-control-BMoSq_xI.d.ts → external-agent-control-CRBbjDDk.d.ts} +46 -46
|
@@ -0,0 +1,968 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/contextual-ask-node.ts
|
|
21
|
+
var contextual_ask_node_exports = {};
|
|
22
|
+
__export(contextual_ask_node_exports, {
|
|
23
|
+
ASK_ANSWER_WARNING_CODES: () => ASK_ANSWER_WARNING_CODES,
|
|
24
|
+
ASK_EXECUTOR_ANSWER_WARNING_CODES: () => ASK_EXECUTOR_ANSWER_WARNING_CODES,
|
|
25
|
+
ASK_FILE_COUNT_BUCKETS: () => ASK_FILE_COUNT_BUCKETS,
|
|
26
|
+
ASK_JOB_STATUSES: () => ASK_JOB_STATUSES,
|
|
27
|
+
ASK_READ_ACTIVITY_STATES: () => ASK_READ_ACTIVITY_STATES,
|
|
28
|
+
ASK_SOURCE_CONFIDENCES: () => ASK_SOURCE_CONFIDENCES,
|
|
29
|
+
CONTEXTUAL_ASK_ERROR_CODES: () => CONTEXTUAL_ASK_ERROR_CODES,
|
|
30
|
+
CONTEXTUAL_ASK_EXECUTOR_KINDS: () => CONTEXTUAL_ASK_EXECUTOR_KINDS,
|
|
31
|
+
CONTEXTUAL_ASK_EXECUTOR_STATES: () => CONTEXTUAL_ASK_EXECUTOR_STATES,
|
|
32
|
+
CONTEXTUAL_ASK_LIMITS: () => CONTEXTUAL_ASK_LIMITS,
|
|
33
|
+
CONTEXTUAL_ASK_PERMISSION_PROFILE: () => CONTEXTUAL_ASK_PERMISSION_PROFILE,
|
|
34
|
+
CONTEXTUAL_ASK_SCHEMA_VERSION: () => CONTEXTUAL_ASK_SCHEMA_VERSION,
|
|
35
|
+
SPOTPATCH_ENDPOINTS: () => SPOTPATCH_ENDPOINTS,
|
|
36
|
+
SPOTPATCH_TOKEN_HEADER: () => SPOTPATCH_TOKEN_HEADER,
|
|
37
|
+
adaptChangeEnvelopeToSpotAnnotationV3: () => adaptChangeEnvelopeToSpotAnnotationV3,
|
|
38
|
+
askAnswerBlockSchema: () => askAnswerBlockSchema,
|
|
39
|
+
askAnswerDraftBlockSchema: () => askAnswerDraftBlockSchema,
|
|
40
|
+
askAnswerDraftSchema: () => askAnswerDraftSchema,
|
|
41
|
+
askAnswerResultSchema: () => askAnswerResultSchema,
|
|
42
|
+
askAnswerWarningSchema: () => askAnswerWarningSchema,
|
|
43
|
+
askDraftCitationSchema: () => askDraftCitationSchema,
|
|
44
|
+
askDraftOriginSchema: () => askDraftOriginSchema,
|
|
45
|
+
askJobActionRequestSchema: () => askJobActionRequestSchema,
|
|
46
|
+
askJobCreateRequestSchema: () => askJobCreateRequestSchema,
|
|
47
|
+
askJobEventSchema: () => askJobEventSchema,
|
|
48
|
+
askJobEventsRequestSchema: () => askJobEventsRequestSchema,
|
|
49
|
+
askJobResultResponseSchema: () => askJobResultResponseSchema,
|
|
50
|
+
askJobSnapshotSchema: () => askJobSnapshotSchema,
|
|
51
|
+
askSourceReferenceSchema: () => askSourceReferenceSchema,
|
|
52
|
+
contextualAskCapabilityRequestSchema: () => contextualAskCapabilityRequestSchema,
|
|
53
|
+
contextualAskCapabilitySchema: () => contextualAskCapabilitySchema,
|
|
54
|
+
contextualAskExecutorCapabilitySchema: () => contextualAskExecutorCapabilitySchema,
|
|
55
|
+
contextualAskExecutorPreferenceSchema: () => contextualAskExecutorPreferenceSchema,
|
|
56
|
+
contextualAskOptionsSchema: () => contextualAskOptionsSchema,
|
|
57
|
+
getAskJobEndpoint: () => getAskJobEndpoint,
|
|
58
|
+
spotAskTaskEnvelopeSchema: () => spotAskTaskEnvelopeSchema,
|
|
59
|
+
spotChangeTaskEnvelopeSchema: () => spotChangeTaskEnvelopeSchema,
|
|
60
|
+
spotSelectionContextSchema: () => spotSelectionContextSchema,
|
|
61
|
+
spotSelectionTargetSchema: () => spotSelectionTargetSchema,
|
|
62
|
+
spotTaskEnvelopeSchema: () => spotTaskEnvelopeSchema
|
|
63
|
+
});
|
|
64
|
+
module.exports = __toCommonJS(contextual_ask_node_exports);
|
|
65
|
+
|
|
66
|
+
// src/model/context-schema.ts
|
|
67
|
+
var import_zod = require("zod");
|
|
68
|
+
|
|
69
|
+
// src/model/annotation.ts
|
|
70
|
+
var MAX_ANNOTATION_TARGETS = 20;
|
|
71
|
+
var MAX_TARGET_INSTRUCTION_CHARACTERS = 2e3;
|
|
72
|
+
var MAX_ANNOTATION_INSTRUCTION_CHARACTERS = 4e3;
|
|
73
|
+
var SPOTPATCH_LOCALES = Object.freeze(["en-US", "zh-CN"]);
|
|
74
|
+
var SPOTPATCH_LOCALE_PREFERENCES = Object.freeze([
|
|
75
|
+
"auto",
|
|
76
|
+
...SPOTPATCH_LOCALES
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
// src/model/context-schema.ts
|
|
80
|
+
var boundedString = (maximum) => import_zod.z.string().max(maximum);
|
|
81
|
+
var sourceRefSchema = import_zod.z.strictObject({
|
|
82
|
+
fileId: boundedString(128).optional(),
|
|
83
|
+
relativePath: boundedString(1024).optional(),
|
|
84
|
+
line: import_zod.z.number().int().positive().optional(),
|
|
85
|
+
column: import_zod.z.number().int().positive().optional(),
|
|
86
|
+
origin: import_zod.z.enum(["jsx-host", "react-fiber", "dom-ancestor", "none"]),
|
|
87
|
+
confidence: import_zod.z.enum(["exact", "probable", "approximate", "unknown"])
|
|
88
|
+
});
|
|
89
|
+
var matchedStyleRuleSchema = import_zod.z.strictObject({
|
|
90
|
+
selector: boundedString(2048),
|
|
91
|
+
declarations: boundedString(8192),
|
|
92
|
+
source: boundedString(1024).optional(),
|
|
93
|
+
media: boundedString(1024).optional()
|
|
94
|
+
});
|
|
95
|
+
var codeContextSchema = import_zod.z.strictObject({
|
|
96
|
+
relativePath: boundedString(1024),
|
|
97
|
+
language: import_zod.z.enum(["tsx", "jsx"]),
|
|
98
|
+
startLine: import_zod.z.number().int().positive(),
|
|
99
|
+
endLine: import_zod.z.number().int().positive(),
|
|
100
|
+
excerpt: boundedString(16e3),
|
|
101
|
+
boundary: import_zod.z.enum(["component", "nearby-lines"])
|
|
102
|
+
});
|
|
103
|
+
var pageContextSchema = import_zod.z.strictObject({
|
|
104
|
+
url: boundedString(2048),
|
|
105
|
+
pathname: boundedString(2048),
|
|
106
|
+
title: boundedString(1024),
|
|
107
|
+
viewportWidth: import_zod.z.number().nonnegative(),
|
|
108
|
+
viewportHeight: import_zod.z.number().nonnegative(),
|
|
109
|
+
devicePixelRatio: import_zod.z.number().positive()
|
|
110
|
+
});
|
|
111
|
+
var spotTargetContextSchema = import_zod.z.strictObject({
|
|
112
|
+
instruction: import_zod.z.string().trim().min(1).max(MAX_TARGET_INSTRUCTION_CHARACTERS),
|
|
113
|
+
page: pageContextSchema.optional(),
|
|
114
|
+
source: sourceRefSchema,
|
|
115
|
+
react: import_zod.z.strictObject({
|
|
116
|
+
supported: import_zod.z.boolean(),
|
|
117
|
+
version: boundedString(64).optional(),
|
|
118
|
+
componentName: boundedString(256).optional(),
|
|
119
|
+
componentSourceId: boundedString(128).optional(),
|
|
120
|
+
sourceVersion: boundedString(128).optional(),
|
|
121
|
+
componentStack: import_zod.z.array(boundedString(256)).max(64),
|
|
122
|
+
source: sourceRefSchema.optional()
|
|
123
|
+
}),
|
|
124
|
+
element: import_zod.z.strictObject({
|
|
125
|
+
tagName: boundedString(128),
|
|
126
|
+
selector: boundedString(2048),
|
|
127
|
+
sanitizedHtml: boundedString(8192),
|
|
128
|
+
textPreview: boundedString(2048).optional(),
|
|
129
|
+
role: boundedString(256).optional(),
|
|
130
|
+
rect: import_zod.z.strictObject({
|
|
131
|
+
x: import_zod.z.number(),
|
|
132
|
+
y: import_zod.z.number(),
|
|
133
|
+
width: import_zod.z.number().nonnegative(),
|
|
134
|
+
height: import_zod.z.number().nonnegative()
|
|
135
|
+
})
|
|
136
|
+
}),
|
|
137
|
+
styles: import_zod.z.strictObject({
|
|
138
|
+
classNames: import_zod.z.array(boundedString(512)).max(256),
|
|
139
|
+
inlineStyle: boundedString(8192).optional(),
|
|
140
|
+
matchedRules: import_zod.z.array(matchedStyleRuleSchema).max(256),
|
|
141
|
+
computed: import_zod.z.record(boundedString(256), boundedString(2048)),
|
|
142
|
+
warnings: import_zod.z.array(boundedString(1024)).max(64)
|
|
143
|
+
}),
|
|
144
|
+
code: codeContextSchema.optional(),
|
|
145
|
+
warnings: import_zod.z.array(boundedString(1024)).max(64)
|
|
146
|
+
});
|
|
147
|
+
var spotAnnotationSchema = import_zod.z.strictObject({
|
|
148
|
+
schemaVersion: import_zod.z.literal(3),
|
|
149
|
+
id: boundedString(128),
|
|
150
|
+
locale: import_zod.z.enum(SPOTPATCH_LOCALES),
|
|
151
|
+
page: pageContextSchema,
|
|
152
|
+
targets: import_zod.z.array(spotTargetContextSchema).min(1).max(MAX_ANNOTATION_TARGETS),
|
|
153
|
+
createdAt: import_zod.z.iso.datetime()
|
|
154
|
+
}).superRefine((annotation, context) => {
|
|
155
|
+
const total = annotation.targets.reduce(
|
|
156
|
+
(characters, target) => characters + target.instruction.length,
|
|
157
|
+
0
|
|
158
|
+
);
|
|
159
|
+
if (total > MAX_ANNOTATION_INSTRUCTION_CHARACTERS) {
|
|
160
|
+
context.addIssue({
|
|
161
|
+
code: "custom",
|
|
162
|
+
message: "Combined target instructions exceed the annotation limit.",
|
|
163
|
+
path: ["targets"]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// src/model/contextual-ask.ts
|
|
169
|
+
var import_zod2 = require("zod");
|
|
170
|
+
|
|
171
|
+
// src/errors/error-code.ts
|
|
172
|
+
var ERROR_CODES = {
|
|
173
|
+
INVALID_REQUEST: "INVALID_REQUEST",
|
|
174
|
+
INVALID_TOKEN: "INVALID_TOKEN",
|
|
175
|
+
ORIGIN_NOT_ALLOWED: "ORIGIN_NOT_ALLOWED",
|
|
176
|
+
SOURCE_NOT_FOUND: "SOURCE_NOT_FOUND",
|
|
177
|
+
SOURCE_OUTSIDE_ROOT: "SOURCE_OUTSIDE_ROOT",
|
|
178
|
+
SOURCE_TOO_LARGE: "SOURCE_TOO_LARGE",
|
|
179
|
+
EDITOR_OPEN_FAILED: "EDITOR_OPEN_FAILED",
|
|
180
|
+
DATA_FLOW_DISABLED: "DATA_FLOW_DISABLED",
|
|
181
|
+
DATA_FLOW_SOURCE_STALE: "DATA_FLOW_SOURCE_STALE",
|
|
182
|
+
DATA_FLOW_ANALYSIS_CANCELLED: "DATA_FLOW_ANALYSIS_CANCELLED",
|
|
183
|
+
AI_DISABLED: "AI_DISABLED",
|
|
184
|
+
PROVIDER_NOT_CONFIGURED: "PROVIDER_NOT_CONFIGURED",
|
|
185
|
+
PROVIDER_AUTH_FAILED: "PROVIDER_AUTH_FAILED",
|
|
186
|
+
PROVIDER_PROTOCOL_UNSUPPORTED: "PROVIDER_PROTOCOL_UNSUPPORTED",
|
|
187
|
+
MODEL_NOT_ALLOWED: "MODEL_NOT_ALLOWED",
|
|
188
|
+
MODEL_TOOL_CALL_UNSUPPORTED: "MODEL_TOOL_CALL_UNSUPPORTED",
|
|
189
|
+
PROVIDER_RATE_LIMITED: "PROVIDER_RATE_LIMITED",
|
|
190
|
+
AGENT_BUSY: "AGENT_BUSY",
|
|
191
|
+
AGENT_LIMIT_EXCEEDED: "AGENT_LIMIT_EXCEEDED",
|
|
192
|
+
AGENT_CANCELLED: "AGENT_CANCELLED",
|
|
193
|
+
EXTERNAL_HANDOFF_DISABLED: "EXTERNAL_HANDOFF_DISABLED",
|
|
194
|
+
EXTERNAL_HANDOFF_UNAVAILABLE: "EXTERNAL_HANDOFF_UNAVAILABLE",
|
|
195
|
+
HANDOFF_VALIDATION_FAILED: "HANDOFF_VALIDATION_FAILED",
|
|
196
|
+
HANDOFF_SOURCE_STALE: "HANDOFF_SOURCE_STALE",
|
|
197
|
+
HANDOFF_NOT_FOUND: "HANDOFF_NOT_FOUND",
|
|
198
|
+
HANDOFF_EXPIRED: "HANDOFF_EXPIRED",
|
|
199
|
+
HANDOFF_CURSOR_INVALID: "HANDOFF_CURSOR_INVALID",
|
|
200
|
+
HANDOFF_RESPONSE_TOO_LARGE: "HANDOFF_RESPONSE_TOO_LARGE",
|
|
201
|
+
BRIDGE_UNAUTHORIZED: "BRIDGE_UNAUTHORIZED",
|
|
202
|
+
BRIDGE_PROTOCOL_MISMATCH: "BRIDGE_PROTOCOL_MISMATCH",
|
|
203
|
+
BRIDGE_BUSY: "BRIDGE_BUSY",
|
|
204
|
+
EXTERNAL_AGENT_BUSY: "EXTERNAL_AGENT_BUSY",
|
|
205
|
+
ACTIVE_ADAPTER_CONFLICT: "ACTIVE_ADAPTER_CONFLICT",
|
|
206
|
+
ACTIVE_ADAPTER_LEASE_INVALID: "ACTIVE_ADAPTER_LEASE_INVALID",
|
|
207
|
+
ACTIVE_DISPATCH_INVALID: "ACTIVE_DISPATCH_INVALID",
|
|
208
|
+
SESSION_NOT_FOUND: "SESSION_NOT_FOUND",
|
|
209
|
+
SESSION_AMBIGUOUS: "SESSION_AMBIGUOUS",
|
|
210
|
+
SESSION_CLOSED: "SESSION_CLOSED",
|
|
211
|
+
WORKTREE_DIRTY: "WORKTREE_DIRTY",
|
|
212
|
+
WORKTREE_NOT_REPOSITORY: "WORKTREE_NOT_REPOSITORY",
|
|
213
|
+
WORKTREE_OPERATION_IN_PROGRESS: "WORKTREE_OPERATION_IN_PROGRESS",
|
|
214
|
+
WORKTREE_CONFLICTED: "WORKTREE_CONFLICTED",
|
|
215
|
+
WORKTREE_LOCAL_CHANGES_TOO_LARGE: "WORKTREE_LOCAL_CHANGES_TOO_LARGE",
|
|
216
|
+
WORKTREE_UNTRACKED_UNSUPPORTED: "WORKTREE_UNTRACKED_UNSUPPORTED",
|
|
217
|
+
WORKTREE_LOCAL_CHANGES_UNSUPPORTED: "WORKTREE_LOCAL_CHANGES_UNSUPPORTED",
|
|
218
|
+
TOOL_DENIED: "TOOL_DENIED",
|
|
219
|
+
TOOL_INPUT_INVALID: "TOOL_INPUT_INVALID",
|
|
220
|
+
TOOL_ARGUMENTS_INVALID: "TOOL_ARGUMENTS_INVALID",
|
|
221
|
+
TOOL_CALL_ID_CONFLICT: "TOOL_CALL_ID_CONFLICT",
|
|
222
|
+
TOOL_PATH_DENIED: "TOOL_PATH_DENIED",
|
|
223
|
+
PATCH_REJECTED: "PATCH_REJECTED",
|
|
224
|
+
VALIDATION_FAILED: "VALIDATION_FAILED",
|
|
225
|
+
APPLY_CONFLICT: "APPLY_CONFLICT",
|
|
226
|
+
INTERNAL_ERROR: "INTERNAL_ERROR"
|
|
227
|
+
};
|
|
228
|
+
var CONTEXTUAL_ASK_ERROR_CODES = Object.freeze([
|
|
229
|
+
"ASK_DISABLED",
|
|
230
|
+
"ASK_SELECTION_REQUIRED",
|
|
231
|
+
"ASK_SELECTION_STALE",
|
|
232
|
+
"ASK_QUESTION_INVALID",
|
|
233
|
+
"ASK_EXECUTOR_UNAVAILABLE",
|
|
234
|
+
"ASK_TIMEOUT",
|
|
235
|
+
"ASK_CONSENT_REQUIRED",
|
|
236
|
+
"ASK_BUSY",
|
|
237
|
+
"ASK_IDEMPOTENCY_CONFLICT",
|
|
238
|
+
"ASK_SOURCE_SCOPE_DENIED",
|
|
239
|
+
"ASK_LIMIT_EXCEEDED",
|
|
240
|
+
"ASK_ANSWER_INVALID",
|
|
241
|
+
"ASK_WRITE_ATTEMPTED",
|
|
242
|
+
"ASK_CANCELLED",
|
|
243
|
+
"ASK_RESULT_EXPIRED",
|
|
244
|
+
"ASK_PROTOCOL_INCOMPATIBLE"
|
|
245
|
+
]);
|
|
246
|
+
var ERROR_CODE_VALUES = Object.freeze(Object.values(ERROR_CODES));
|
|
247
|
+
|
|
248
|
+
// src/protocol/contextual-ask-constants.ts
|
|
249
|
+
var CONTEXTUAL_ASK_SCHEMA_VERSION = 1;
|
|
250
|
+
var CONTEXTUAL_ASK_LIMITS = Object.freeze({
|
|
251
|
+
maximumTargets: 20,
|
|
252
|
+
maximumQuestionCharacters: 4e3,
|
|
253
|
+
maximumAnswerCharacters: 4e4,
|
|
254
|
+
maximumAnswerBlocks: 40,
|
|
255
|
+
maximumSources: 64,
|
|
256
|
+
maximumReadFiles: 32,
|
|
257
|
+
maximumReadBytesPerFile: 64 * 1024,
|
|
258
|
+
maximumReadBytesTotal: 512 * 1024,
|
|
259
|
+
maximumToolCalls: 48,
|
|
260
|
+
maximumModelTurns: 12,
|
|
261
|
+
jobTimeoutMs: 3e5,
|
|
262
|
+
resultTtlMs: 9e5,
|
|
263
|
+
maximumActiveJobsPerSession: 1,
|
|
264
|
+
maximumRetainedResultsPerSession: 1,
|
|
265
|
+
maximumRetainedEvents: 256,
|
|
266
|
+
maximumEventSubscribers: 4,
|
|
267
|
+
eventHeartbeatMs: 15e3,
|
|
268
|
+
maximumRequestBodyBytes: 256 * 1024,
|
|
269
|
+
maximumSearchQueryCharacters: 256,
|
|
270
|
+
maximumSearchResults: 64,
|
|
271
|
+
maximumSearchPreviewCharacters: 500,
|
|
272
|
+
capabilityTimeoutMs: 3e4,
|
|
273
|
+
maximumIdCharacters: 128,
|
|
274
|
+
maximumProfileIdCharacters: 64,
|
|
275
|
+
maximumLabelCharacters: 256,
|
|
276
|
+
maximumRelativePathCharacters: 1024,
|
|
277
|
+
maximumLanguageCharacters: 64,
|
|
278
|
+
maximumPhaseMessageCharacters: 1024,
|
|
279
|
+
maximumExecutors: 32,
|
|
280
|
+
contentHashHexCharacters: 64
|
|
281
|
+
});
|
|
282
|
+
var CONTEXTUAL_ASK_EXECUTOR_KINDS = Object.freeze([
|
|
283
|
+
"configured-key",
|
|
284
|
+
"managed-codex"
|
|
285
|
+
]);
|
|
286
|
+
var CONTEXTUAL_ASK_EXECUTOR_STATES = Object.freeze([
|
|
287
|
+
"ready",
|
|
288
|
+
"degraded",
|
|
289
|
+
"unavailable"
|
|
290
|
+
]);
|
|
291
|
+
var ASK_JOB_STATUSES = Object.freeze([
|
|
292
|
+
"queued",
|
|
293
|
+
"authorizing",
|
|
294
|
+
"running",
|
|
295
|
+
"cancelling",
|
|
296
|
+
"answered",
|
|
297
|
+
"cancelled",
|
|
298
|
+
"failed"
|
|
299
|
+
]);
|
|
300
|
+
var ASK_ANSWER_WARNING_CODES = Object.freeze([
|
|
301
|
+
"insufficient-evidence",
|
|
302
|
+
"partial-context",
|
|
303
|
+
"source-truncated",
|
|
304
|
+
"source-stale"
|
|
305
|
+
]);
|
|
306
|
+
var ASK_EXECUTOR_ANSWER_WARNING_CODES = Object.freeze([
|
|
307
|
+
"insufficient-evidence",
|
|
308
|
+
"partial-context"
|
|
309
|
+
]);
|
|
310
|
+
var ASK_READ_ACTIVITY_STATES = Object.freeze([
|
|
311
|
+
"started",
|
|
312
|
+
"succeeded",
|
|
313
|
+
"failed"
|
|
314
|
+
]);
|
|
315
|
+
var ASK_FILE_COUNT_BUCKETS = Object.freeze(["one", "few", "many"]);
|
|
316
|
+
var ASK_SOURCE_CONFIDENCES = Object.freeze([
|
|
317
|
+
"exact",
|
|
318
|
+
"probable",
|
|
319
|
+
"approximate"
|
|
320
|
+
]);
|
|
321
|
+
var CONTEXTUAL_ASK_PERMISSION_PROFILE = "spotpatch-ask-readonly";
|
|
322
|
+
|
|
323
|
+
// src/model/contextual-ask.ts
|
|
324
|
+
var limits = CONTEXTUAL_ASK_LIMITS;
|
|
325
|
+
var contextualAskBoundedText = (maximum) => import_zod2.z.string().trim().min(1).max(maximum);
|
|
326
|
+
var contextualAskOpaqueIdSchema = import_zod2.z.string().min(1).max(limits.maximumIdCharacters).regex(/^[A-Za-z0-9_-]+$/u);
|
|
327
|
+
var profileIdSchema = import_zod2.z.string().min(1).max(limits.maximumProfileIdCharacters).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/u);
|
|
328
|
+
var contentHashSchema = import_zod2.z.string().length(limits.contentHashHexCharacters).regex(/^[a-f0-9]+$/u);
|
|
329
|
+
var contextualAskRelativePathSchema = import_zod2.z.string().min(1).max(limits.maximumRelativePathCharacters).refine(
|
|
330
|
+
(value) => !value.startsWith("/") && !value.includes("\\") && !Array.from(value).some((character) => {
|
|
331
|
+
const codePoint = character.codePointAt(0);
|
|
332
|
+
return codePoint !== void 0 && (codePoint <= 31 || codePoint === 127);
|
|
333
|
+
}) && !/^[A-Za-z]:/u.test(value) && value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== ".."),
|
|
334
|
+
{ message: "Expected a safe project-relative POSIX path." }
|
|
335
|
+
);
|
|
336
|
+
var contextualAskExecutorPreferenceSchema = import_zod2.z.discriminatedUnion("kind", [
|
|
337
|
+
import_zod2.z.strictObject({
|
|
338
|
+
kind: import_zod2.z.literal("configured-key"),
|
|
339
|
+
providerProfileId: profileIdSchema,
|
|
340
|
+
modelProfileId: profileIdSchema
|
|
341
|
+
}),
|
|
342
|
+
import_zod2.z.strictObject({ kind: import_zod2.z.literal("managed-codex") })
|
|
343
|
+
]);
|
|
344
|
+
var contextualAskOptionsSchema = import_zod2.z.union([
|
|
345
|
+
import_zod2.z.boolean(),
|
|
346
|
+
import_zod2.z.strictObject({
|
|
347
|
+
defaultExecutor: contextualAskExecutorPreferenceSchema.optional()
|
|
348
|
+
})
|
|
349
|
+
]);
|
|
350
|
+
var spotSelectionTargetSchema = spotTargetContextSchema.omit({ instruction: true, page: true }).extend({
|
|
351
|
+
targetId: contextualAskOpaqueIdSchema,
|
|
352
|
+
page: pageContextSchema
|
|
353
|
+
}).strict();
|
|
354
|
+
var spotSelectionContextSchema = import_zod2.z.strictObject({
|
|
355
|
+
schemaVersion: import_zod2.z.literal(CONTEXTUAL_ASK_SCHEMA_VERSION),
|
|
356
|
+
selectionId: contextualAskOpaqueIdSchema,
|
|
357
|
+
locale: import_zod2.z.enum(SPOTPATCH_LOCALES),
|
|
358
|
+
targets: import_zod2.z.array(spotSelectionTargetSchema).min(1).max(limits.maximumTargets),
|
|
359
|
+
createdAt: import_zod2.z.iso.datetime()
|
|
360
|
+
}).superRefine((selection, context) => {
|
|
361
|
+
const targetIds = selection.targets.map((target) => target.targetId);
|
|
362
|
+
if (new Set(targetIds).size !== targetIds.length) {
|
|
363
|
+
context.addIssue({
|
|
364
|
+
code: "custom",
|
|
365
|
+
message: "Selection target IDs must be unique.",
|
|
366
|
+
path: ["targets"]
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
var askDraftOriginSchema = import_zod2.z.strictObject({
|
|
371
|
+
kind: import_zod2.z.literal("contextual-ask"),
|
|
372
|
+
askJobId: contextualAskOpaqueIdSchema,
|
|
373
|
+
question: contextualAskBoundedText(limits.maximumQuestionCharacters),
|
|
374
|
+
answerDigest: contextualAskBoundedText(limits.maximumQuestionCharacters),
|
|
375
|
+
sourceIds: import_zod2.z.array(contextualAskOpaqueIdSchema).max(limits.maximumSources)
|
|
376
|
+
}).superRefine((origin, context) => {
|
|
377
|
+
if (new Set(origin.sourceIds).size !== origin.sourceIds.length) {
|
|
378
|
+
context.addIssue({
|
|
379
|
+
code: "custom",
|
|
380
|
+
message: "Ask origin source IDs must be unique.",
|
|
381
|
+
path: ["sourceIds"]
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
var askTaskSchema = import_zod2.z.strictObject({
|
|
386
|
+
kind: import_zod2.z.literal("ask"),
|
|
387
|
+
question: contextualAskBoundedText(limits.maximumQuestionCharacters)
|
|
388
|
+
});
|
|
389
|
+
var changeInstructionSchema = import_zod2.z.strictObject({
|
|
390
|
+
targetId: contextualAskOpaqueIdSchema,
|
|
391
|
+
instruction: contextualAskBoundedText(MAX_TARGET_INSTRUCTION_CHARACTERS)
|
|
392
|
+
});
|
|
393
|
+
var changeTaskSchema = import_zod2.z.strictObject({
|
|
394
|
+
kind: import_zod2.z.literal("change"),
|
|
395
|
+
instructions: import_zod2.z.array(changeInstructionSchema).min(1).max(limits.maximumTargets),
|
|
396
|
+
origin: askDraftOriginSchema.optional()
|
|
397
|
+
});
|
|
398
|
+
var envelopeBaseShape = {
|
|
399
|
+
schemaVersion: import_zod2.z.literal(CONTEXTUAL_ASK_SCHEMA_VERSION),
|
|
400
|
+
taskId: contextualAskOpaqueIdSchema,
|
|
401
|
+
selection: spotSelectionContextSchema,
|
|
402
|
+
createdAt: import_zod2.z.iso.datetime()
|
|
403
|
+
};
|
|
404
|
+
var spotAskTaskEnvelopeSchema = import_zod2.z.strictObject({
|
|
405
|
+
...envelopeBaseShape,
|
|
406
|
+
task: askTaskSchema
|
|
407
|
+
});
|
|
408
|
+
var spotChangeTaskEnvelopeSchema = import_zod2.z.strictObject({
|
|
409
|
+
...envelopeBaseShape,
|
|
410
|
+
task: changeTaskSchema
|
|
411
|
+
}).superRefine((envelope, context) => {
|
|
412
|
+
const targetIds = envelope.selection.targets.map((target) => target.targetId);
|
|
413
|
+
const instructionIds = envelope.task.instructions.map(
|
|
414
|
+
(instruction) => instruction.targetId
|
|
415
|
+
);
|
|
416
|
+
if (new Set(instructionIds).size !== instructionIds.length || instructionIds.length !== targetIds.length || targetIds.some((targetId) => !instructionIds.includes(targetId))) {
|
|
417
|
+
context.addIssue({
|
|
418
|
+
code: "custom",
|
|
419
|
+
message: "Change instructions must map one-to-one to selection targets.",
|
|
420
|
+
path: ["task", "instructions"]
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
const total = envelope.task.instructions.reduce(
|
|
424
|
+
(characters, instruction) => characters + instruction.instruction.length,
|
|
425
|
+
0
|
|
426
|
+
);
|
|
427
|
+
if (total > MAX_ANNOTATION_INSTRUCTION_CHARACTERS) {
|
|
428
|
+
context.addIssue({
|
|
429
|
+
code: "custom",
|
|
430
|
+
message: "Combined change instructions exceed the task limit.",
|
|
431
|
+
path: ["task", "instructions"]
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
var spotTaskEnvelopeSchema = import_zod2.z.union([
|
|
436
|
+
spotAskTaskEnvelopeSchema,
|
|
437
|
+
spotChangeTaskEnvelopeSchema
|
|
438
|
+
]);
|
|
439
|
+
var askAnswerWarningSchema = import_zod2.z.strictObject({
|
|
440
|
+
code: import_zod2.z.enum(ASK_ANSWER_WARNING_CODES)
|
|
441
|
+
});
|
|
442
|
+
var askExecutorAnswerWarningSchema = import_zod2.z.strictObject({
|
|
443
|
+
code: import_zod2.z.enum(ASK_EXECUTOR_ANSWER_WARNING_CODES)
|
|
444
|
+
});
|
|
445
|
+
var askDraftCitationSchema = import_zod2.z.strictObject({
|
|
446
|
+
handleId: contextualAskOpaqueIdSchema,
|
|
447
|
+
startLine: import_zod2.z.number().int().positive(),
|
|
448
|
+
endLine: import_zod2.z.number().int().positive()
|
|
449
|
+
}).refine((citation) => citation.endLine >= citation.startLine, {
|
|
450
|
+
message: "Citation endLine must not precede startLine."
|
|
451
|
+
});
|
|
452
|
+
var draftCitationListSchema = import_zod2.z.array(askDraftCitationSchema).max(limits.maximumSources);
|
|
453
|
+
var draftParagraphBlockSchema = import_zod2.z.strictObject({
|
|
454
|
+
kind: import_zod2.z.literal("paragraph"),
|
|
455
|
+
text: contextualAskBoundedText(limits.maximumAnswerCharacters),
|
|
456
|
+
citations: draftCitationListSchema
|
|
457
|
+
});
|
|
458
|
+
var draftListBlockSchema = import_zod2.z.strictObject({
|
|
459
|
+
kind: import_zod2.z.literal("list"),
|
|
460
|
+
items: import_zod2.z.array(
|
|
461
|
+
import_zod2.z.strictObject({
|
|
462
|
+
text: contextualAskBoundedText(limits.maximumAnswerCharacters),
|
|
463
|
+
citations: draftCitationListSchema
|
|
464
|
+
})
|
|
465
|
+
).min(1).max(limits.maximumAnswerBlocks)
|
|
466
|
+
});
|
|
467
|
+
var draftCodeBlockSchema = import_zod2.z.strictObject({
|
|
468
|
+
kind: import_zod2.z.literal("code"),
|
|
469
|
+
code: import_zod2.z.string().min(1).max(limits.maximumAnswerCharacters),
|
|
470
|
+
language: contextualAskBoundedText(limits.maximumLanguageCharacters).optional(),
|
|
471
|
+
citations: draftCitationListSchema
|
|
472
|
+
});
|
|
473
|
+
var askAnswerDraftBlockSchema = import_zod2.z.discriminatedUnion("kind", [
|
|
474
|
+
draftParagraphBlockSchema,
|
|
475
|
+
draftListBlockSchema,
|
|
476
|
+
draftCodeBlockSchema
|
|
477
|
+
]);
|
|
478
|
+
function draftCharacters(blocks) {
|
|
479
|
+
return blocks.reduce((total, block) => {
|
|
480
|
+
if (block.kind === "paragraph") return total + block.text.length;
|
|
481
|
+
if (block.kind === "code") return total + block.code.length;
|
|
482
|
+
return total + block.items.reduce((itemTotal, item) => itemTotal + item.text.length, 0);
|
|
483
|
+
}, 0);
|
|
484
|
+
}
|
|
485
|
+
var askAnswerDraftSchema = import_zod2.z.strictObject({
|
|
486
|
+
blocks: import_zod2.z.array(askAnswerDraftBlockSchema).min(1).max(limits.maximumAnswerBlocks),
|
|
487
|
+
warnings: import_zod2.z.array(askExecutorAnswerWarningSchema).max(limits.maximumAnswerBlocks)
|
|
488
|
+
}).superRefine((answer, context) => {
|
|
489
|
+
if (draftCharacters(answer.blocks) > limits.maximumAnswerCharacters) {
|
|
490
|
+
context.addIssue({
|
|
491
|
+
code: "custom",
|
|
492
|
+
message: "Combined answer text exceeds the answer limit.",
|
|
493
|
+
path: ["blocks"]
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
const citations = answer.blocks.flatMap(
|
|
497
|
+
(block) => block.kind === "list" ? block.items.flatMap((item) => item.citations) : block.citations
|
|
498
|
+
);
|
|
499
|
+
if (citations.length === 0 && !answer.warnings.some((warning) => warning.code === "insufficient-evidence")) {
|
|
500
|
+
context.addIssue({
|
|
501
|
+
code: "custom",
|
|
502
|
+
message: "An uncited answer draft must declare insufficient evidence.",
|
|
503
|
+
path: ["warnings"]
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
const distinct = new Set(
|
|
507
|
+
citations.map(
|
|
508
|
+
(citation) => `${citation.handleId}:${String(citation.startLine)}:${String(citation.endLine)}`
|
|
509
|
+
)
|
|
510
|
+
);
|
|
511
|
+
if (distinct.size > limits.maximumSources) {
|
|
512
|
+
context.addIssue({
|
|
513
|
+
code: "custom",
|
|
514
|
+
message: "Answer references exceed the source limit.",
|
|
515
|
+
path: ["blocks"]
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
var sourceIdListSchema = import_zod2.z.array(contextualAskOpaqueIdSchema).max(limits.maximumSources);
|
|
520
|
+
var paragraphBlockSchema = import_zod2.z.strictObject({
|
|
521
|
+
kind: import_zod2.z.literal("paragraph"),
|
|
522
|
+
text: contextualAskBoundedText(limits.maximumAnswerCharacters),
|
|
523
|
+
sourceIds: sourceIdListSchema
|
|
524
|
+
});
|
|
525
|
+
var listBlockSchema = import_zod2.z.strictObject({
|
|
526
|
+
kind: import_zod2.z.literal("list"),
|
|
527
|
+
items: import_zod2.z.array(
|
|
528
|
+
import_zod2.z.strictObject({
|
|
529
|
+
text: contextualAskBoundedText(limits.maximumAnswerCharacters),
|
|
530
|
+
sourceIds: sourceIdListSchema
|
|
531
|
+
})
|
|
532
|
+
).min(1).max(limits.maximumAnswerBlocks)
|
|
533
|
+
});
|
|
534
|
+
var codeBlockSchema = import_zod2.z.strictObject({
|
|
535
|
+
kind: import_zod2.z.literal("code"),
|
|
536
|
+
code: import_zod2.z.string().min(1).max(limits.maximumAnswerCharacters),
|
|
537
|
+
language: contextualAskBoundedText(limits.maximumLanguageCharacters).optional(),
|
|
538
|
+
sourceIds: sourceIdListSchema
|
|
539
|
+
});
|
|
540
|
+
var askAnswerBlockSchema = import_zod2.z.discriminatedUnion("kind", [
|
|
541
|
+
paragraphBlockSchema,
|
|
542
|
+
listBlockSchema,
|
|
543
|
+
codeBlockSchema
|
|
544
|
+
]);
|
|
545
|
+
var askSourceReferenceSchema = import_zod2.z.strictObject({
|
|
546
|
+
sourceId: contextualAskOpaqueIdSchema,
|
|
547
|
+
label: contextualAskBoundedText(limits.maximumLabelCharacters),
|
|
548
|
+
relativePath: contextualAskRelativePathSchema,
|
|
549
|
+
fileId: contextualAskOpaqueIdSchema,
|
|
550
|
+
startLine: import_zod2.z.number().int().positive(),
|
|
551
|
+
endLine: import_zod2.z.number().int().positive(),
|
|
552
|
+
confidence: import_zod2.z.enum(ASK_SOURCE_CONFIDENCES),
|
|
553
|
+
targetIds: import_zod2.z.array(contextualAskOpaqueIdSchema).min(1).max(limits.maximumTargets),
|
|
554
|
+
sourceVersion: contextualAskBoundedText(limits.maximumIdCharacters).optional(),
|
|
555
|
+
contentHash: contentHashSchema
|
|
556
|
+
}).superRefine((source, context) => {
|
|
557
|
+
if (source.endLine < source.startLine) {
|
|
558
|
+
context.addIssue({
|
|
559
|
+
code: "custom",
|
|
560
|
+
message: "Source endLine must not precede startLine.",
|
|
561
|
+
path: ["endLine"]
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
if (new Set(source.targetIds).size !== source.targetIds.length) {
|
|
565
|
+
context.addIssue({
|
|
566
|
+
code: "custom",
|
|
567
|
+
message: "Source target IDs must be unique.",
|
|
568
|
+
path: ["targetIds"]
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
function resultBlockCharacters(blocks) {
|
|
573
|
+
return blocks.reduce((total, block) => {
|
|
574
|
+
if (block.kind === "paragraph") return total + block.text.length;
|
|
575
|
+
if (block.kind === "code") return total + block.code.length;
|
|
576
|
+
return total + block.items.reduce((itemTotal, item) => itemTotal + item.text.length, 0);
|
|
577
|
+
}, 0);
|
|
578
|
+
}
|
|
579
|
+
var askAnswerResultSchema = import_zod2.z.strictObject({
|
|
580
|
+
schemaVersion: import_zod2.z.literal(CONTEXTUAL_ASK_SCHEMA_VERSION),
|
|
581
|
+
jobId: contextualAskOpaqueIdSchema,
|
|
582
|
+
selectionId: contextualAskOpaqueIdSchema,
|
|
583
|
+
contextHash: contentHashSchema,
|
|
584
|
+
executor: import_zod2.z.strictObject({
|
|
585
|
+
executorId: contextualAskOpaqueIdSchema,
|
|
586
|
+
kind: import_zod2.z.enum(CONTEXTUAL_ASK_EXECUTOR_KINDS),
|
|
587
|
+
label: contextualAskBoundedText(limits.maximumLabelCharacters),
|
|
588
|
+
modelLabel: contextualAskBoundedText(limits.maximumLabelCharacters)
|
|
589
|
+
}),
|
|
590
|
+
blocks: import_zod2.z.array(askAnswerBlockSchema).min(1).max(limits.maximumAnswerBlocks),
|
|
591
|
+
sources: import_zod2.z.array(askSourceReferenceSchema).max(limits.maximumSources),
|
|
592
|
+
warnings: import_zod2.z.array(askAnswerWarningSchema).max(limits.maximumAnswerBlocks),
|
|
593
|
+
createdAt: import_zod2.z.iso.datetime(),
|
|
594
|
+
expiresAt: import_zod2.z.iso.datetime()
|
|
595
|
+
}).superRefine((answer, context) => {
|
|
596
|
+
if (Date.parse(answer.expiresAt) <= Date.parse(answer.createdAt)) {
|
|
597
|
+
context.addIssue({
|
|
598
|
+
code: "custom",
|
|
599
|
+
message: "Answer expiry must follow creation.",
|
|
600
|
+
path: ["expiresAt"]
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
if (resultBlockCharacters(answer.blocks) > limits.maximumAnswerCharacters) {
|
|
604
|
+
context.addIssue({
|
|
605
|
+
code: "custom",
|
|
606
|
+
message: "Combined answer text exceeds the answer limit.",
|
|
607
|
+
path: ["blocks"]
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
const sourceIds = answer.sources.map((source) => source.sourceId);
|
|
611
|
+
if (new Set(sourceIds).size !== sourceIds.length) {
|
|
612
|
+
context.addIssue({
|
|
613
|
+
code: "custom",
|
|
614
|
+
message: "Answer source IDs must be unique.",
|
|
615
|
+
path: ["sources"]
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
const available = new Set(sourceIds);
|
|
619
|
+
const references = answer.blocks.flatMap(
|
|
620
|
+
(block) => block.kind === "list" ? block.items.flatMap((item) => item.sourceIds) : block.sourceIds
|
|
621
|
+
);
|
|
622
|
+
if (references.length === 0 && !answer.warnings.some((warning) => warning.code === "insufficient-evidence")) {
|
|
623
|
+
context.addIssue({
|
|
624
|
+
code: "custom",
|
|
625
|
+
message: "An uncited answer must declare insufficient evidence.",
|
|
626
|
+
path: ["warnings"]
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
if (references.some((sourceId) => !available.has(sourceId))) {
|
|
630
|
+
context.addIssue({
|
|
631
|
+
code: "custom",
|
|
632
|
+
message: "Answer blocks reference an unknown source ID.",
|
|
633
|
+
path: ["blocks"]
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
if (sourceIds.some((sourceId) => !references.includes(sourceId))) {
|
|
637
|
+
context.addIssue({
|
|
638
|
+
code: "custom",
|
|
639
|
+
message: "Answer sources must be referenced by at least one block.",
|
|
640
|
+
path: ["sources"]
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
var contextualAskExecutorCapabilitySchema = import_zod2.z.strictObject({
|
|
645
|
+
executorId: contextualAskOpaqueIdSchema,
|
|
646
|
+
kind: import_zod2.z.enum(CONTEXTUAL_ASK_EXECUTOR_KINDS),
|
|
647
|
+
label: contextualAskBoundedText(limits.maximumLabelCharacters),
|
|
648
|
+
requestedModelLabel: contextualAskBoundedText(limits.maximumLabelCharacters),
|
|
649
|
+
effectiveModelLabel: contextualAskBoundedText(limits.maximumLabelCharacters),
|
|
650
|
+
state: import_zod2.z.enum(CONTEXTUAL_ASK_EXECUTOR_STATES),
|
|
651
|
+
providerDataConsentRequired: import_zod2.z.boolean(),
|
|
652
|
+
readOnlyProven: import_zod2.z.boolean(),
|
|
653
|
+
errorCode: import_zod2.z.enum(CONTEXTUAL_ASK_ERROR_CODES).optional()
|
|
654
|
+
}).superRefine((executor, context) => {
|
|
655
|
+
if (executor.state === "ready" && (!executor.readOnlyProven || executor.errorCode !== void 0) || executor.state !== "ready" && executor.errorCode === void 0) {
|
|
656
|
+
context.addIssue({
|
|
657
|
+
code: "custom",
|
|
658
|
+
message: "Executor capability fields are inconsistent."
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
var contextualAskCapabilitySchema = import_zod2.z.strictObject({
|
|
663
|
+
schemaVersion: import_zod2.z.literal(CONTEXTUAL_ASK_SCHEMA_VERSION),
|
|
664
|
+
enabled: import_zod2.z.boolean(),
|
|
665
|
+
executors: import_zod2.z.array(contextualAskExecutorCapabilitySchema).max(limits.maximumExecutors),
|
|
666
|
+
safety: import_zod2.z.strictObject({
|
|
667
|
+
selectionRequired: import_zod2.z.literal(true),
|
|
668
|
+
singleTurn: import_zod2.z.literal(true),
|
|
669
|
+
writesAllowed: import_zod2.z.literal(false),
|
|
670
|
+
historyStored: import_zod2.z.literal(false)
|
|
671
|
+
}),
|
|
672
|
+
checkedAt: import_zod2.z.iso.datetime()
|
|
673
|
+
}).superRefine((capability, context) => {
|
|
674
|
+
if (!capability.enabled && capability.executors.length > 0 || new Set(capability.executors.map((executor) => executor.executorId)).size !== capability.executors.length) {
|
|
675
|
+
context.addIssue({
|
|
676
|
+
code: "custom",
|
|
677
|
+
message: "Contextual Ask capability fields are inconsistent.",
|
|
678
|
+
path: ["executors"]
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
// src/protocol/contextual-ask.ts
|
|
684
|
+
var import_zod3 = require("zod");
|
|
685
|
+
var limits2 = CONTEXTUAL_ASK_LIMITS;
|
|
686
|
+
var timestampSchema = import_zod3.z.iso.datetime();
|
|
687
|
+
var contextualAskCapabilityRequestSchema = import_zod3.z.strictObject({});
|
|
688
|
+
var askJobCreateRequestSchema = import_zod3.z.strictObject({
|
|
689
|
+
schemaVersion: import_zod3.z.literal(CONTEXTUAL_ASK_SCHEMA_VERSION),
|
|
690
|
+
requestId: contextualAskOpaqueIdSchema,
|
|
691
|
+
envelope: spotAskTaskEnvelopeSchema,
|
|
692
|
+
executorId: contextualAskOpaqueIdSchema,
|
|
693
|
+
providerDataConsent: import_zod3.z.literal(true)
|
|
694
|
+
});
|
|
695
|
+
var askJobActionRequestSchema = import_zod3.z.strictObject({});
|
|
696
|
+
var askJobEventsRequestSchema = import_zod3.z.strictObject({
|
|
697
|
+
afterSequence: import_zod3.z.number().int().nonnegative().optional()
|
|
698
|
+
});
|
|
699
|
+
var askJobExecutorSnapshotSchema = import_zod3.z.strictObject({
|
|
700
|
+
executorId: contextualAskOpaqueIdSchema,
|
|
701
|
+
kind: import_zod3.z.enum(CONTEXTUAL_ASK_EXECUTOR_KINDS),
|
|
702
|
+
label: contextualAskBoundedText(limits2.maximumLabelCharacters),
|
|
703
|
+
modelLabel: contextualAskBoundedText(limits2.maximumLabelCharacters)
|
|
704
|
+
});
|
|
705
|
+
var askJobSnapshotSchema = import_zod3.z.strictObject({
|
|
706
|
+
schemaVersion: import_zod3.z.literal(CONTEXTUAL_ASK_SCHEMA_VERSION),
|
|
707
|
+
jobId: contextualAskOpaqueIdSchema,
|
|
708
|
+
selectionId: contextualAskOpaqueIdSchema,
|
|
709
|
+
status: import_zod3.z.enum(ASK_JOB_STATUSES),
|
|
710
|
+
executor: askJobExecutorSnapshotSchema,
|
|
711
|
+
phaseMessage: contextualAskBoundedText(
|
|
712
|
+
limits2.maximumPhaseMessageCharacters
|
|
713
|
+
).optional(),
|
|
714
|
+
createdAt: timestampSchema,
|
|
715
|
+
updatedAt: timestampSchema,
|
|
716
|
+
canCancel: import_zod3.z.boolean(),
|
|
717
|
+
errorCode: import_zod3.z.enum(CONTEXTUAL_ASK_ERROR_CODES).optional()
|
|
718
|
+
}).superRefine((snapshot, context) => {
|
|
719
|
+
if (Date.parse(snapshot.updatedAt) < Date.parse(snapshot.createdAt)) {
|
|
720
|
+
context.addIssue({
|
|
721
|
+
code: "custom",
|
|
722
|
+
message: "Job updatedAt must not precede createdAt.",
|
|
723
|
+
path: ["updatedAt"]
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
const cancellable = ["queued", "authorizing", "running"].includes(snapshot.status);
|
|
727
|
+
if (snapshot.canCancel !== cancellable) {
|
|
728
|
+
context.addIssue({
|
|
729
|
+
code: "custom",
|
|
730
|
+
message: "Job canCancel does not match its status.",
|
|
731
|
+
path: ["canCancel"]
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
if (snapshot.status === "failed" && snapshot.errorCode === void 0 || snapshot.status === "failed" && snapshot.errorCode === "ASK_CANCELLED" || snapshot.status === "cancelled" && snapshot.errorCode !== "ASK_CANCELLED" || snapshot.status !== "failed" && snapshot.status !== "cancelled" && snapshot.errorCode !== void 0) {
|
|
735
|
+
context.addIssue({
|
|
736
|
+
code: "custom",
|
|
737
|
+
message: "Job errorCode does not match its terminal status.",
|
|
738
|
+
path: ["errorCode"]
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
var askJobResultResponseSchema = import_zod3.z.strictObject({
|
|
743
|
+
snapshot: askJobSnapshotSchema,
|
|
744
|
+
result: askAnswerResultSchema.optional()
|
|
745
|
+
}).superRefine((response, context) => {
|
|
746
|
+
const answered = response.snapshot.status === "answered";
|
|
747
|
+
if (answered !== (response.result !== void 0)) {
|
|
748
|
+
context.addIssue({
|
|
749
|
+
code: "custom",
|
|
750
|
+
message: "Only an answered job must contain an answer result.",
|
|
751
|
+
path: ["result"]
|
|
752
|
+
});
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
if (response.result !== void 0 && (response.result.jobId !== response.snapshot.jobId || response.result.selectionId !== response.snapshot.selectionId || response.result.executor.executorId !== response.snapshot.executor.executorId)) {
|
|
756
|
+
context.addIssue({
|
|
757
|
+
code: "custom",
|
|
758
|
+
message: "Answer result identity does not match the job snapshot.",
|
|
759
|
+
path: ["result"]
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
var askJobEventBaseShape = {
|
|
764
|
+
schemaVersion: import_zod3.z.literal(CONTEXTUAL_ASK_SCHEMA_VERSION),
|
|
765
|
+
sequence: import_zod3.z.number().int().positive(),
|
|
766
|
+
jobId: contextualAskOpaqueIdSchema,
|
|
767
|
+
status: import_zod3.z.enum(ASK_JOB_STATUSES),
|
|
768
|
+
timestamp: timestampSchema
|
|
769
|
+
};
|
|
770
|
+
var askJobSnapshotEventSchema = import_zod3.z.strictObject({
|
|
771
|
+
...askJobEventBaseShape,
|
|
772
|
+
type: import_zod3.z.literal("snapshot"),
|
|
773
|
+
snapshot: askJobSnapshotSchema
|
|
774
|
+
});
|
|
775
|
+
var askJobPhaseEventSchema = import_zod3.z.strictObject({
|
|
776
|
+
...askJobEventBaseShape,
|
|
777
|
+
type: import_zod3.z.literal("phase"),
|
|
778
|
+
message: contextualAskBoundedText(limits2.maximumPhaseMessageCharacters)
|
|
779
|
+
});
|
|
780
|
+
var askReadSourceActivitySchema = import_zod3.z.strictObject({
|
|
781
|
+
kind: import_zod3.z.literal("source"),
|
|
782
|
+
sourceId: contextualAskOpaqueIdSchema,
|
|
783
|
+
relativePath: contextualAskRelativePathSchema
|
|
784
|
+
});
|
|
785
|
+
var askReadFileCountActivitySchema = import_zod3.z.strictObject({
|
|
786
|
+
kind: import_zod3.z.literal("file-count"),
|
|
787
|
+
bucket: import_zod3.z.enum(ASK_FILE_COUNT_BUCKETS)
|
|
788
|
+
});
|
|
789
|
+
var askJobReadActivityEventSchema = import_zod3.z.strictObject({
|
|
790
|
+
...askJobEventBaseShape,
|
|
791
|
+
type: import_zod3.z.literal("read-activity"),
|
|
792
|
+
activity: import_zod3.z.discriminatedUnion("kind", [
|
|
793
|
+
askReadSourceActivitySchema,
|
|
794
|
+
askReadFileCountActivitySchema
|
|
795
|
+
]),
|
|
796
|
+
state: import_zod3.z.enum(ASK_READ_ACTIVITY_STATES)
|
|
797
|
+
});
|
|
798
|
+
var askJobAnswerReadyEventSchema = import_zod3.z.strictObject({
|
|
799
|
+
...askJobEventBaseShape,
|
|
800
|
+
type: import_zod3.z.literal("answer-ready")
|
|
801
|
+
});
|
|
802
|
+
var askJobErrorEventSchema = import_zod3.z.strictObject({
|
|
803
|
+
...askJobEventBaseShape,
|
|
804
|
+
type: import_zod3.z.literal("error"),
|
|
805
|
+
errorCode: import_zod3.z.enum(CONTEXTUAL_ASK_ERROR_CODES)
|
|
806
|
+
});
|
|
807
|
+
var askJobEventSchema = import_zod3.z.discriminatedUnion("type", [
|
|
808
|
+
askJobSnapshotEventSchema,
|
|
809
|
+
askJobPhaseEventSchema,
|
|
810
|
+
askJobReadActivityEventSchema,
|
|
811
|
+
askJobAnswerReadyEventSchema,
|
|
812
|
+
askJobErrorEventSchema
|
|
813
|
+
]).superRefine((event, context) => {
|
|
814
|
+
if (event.type === "snapshot" && (event.snapshot.jobId !== event.jobId || event.snapshot.status !== event.status)) {
|
|
815
|
+
context.addIssue({
|
|
816
|
+
code: "custom",
|
|
817
|
+
message: "Snapshot event identity does not match its envelope.",
|
|
818
|
+
path: ["snapshot"]
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
if (event.type === "read-activity" && event.status !== "running") {
|
|
822
|
+
context.addIssue({
|
|
823
|
+
code: "custom",
|
|
824
|
+
message: "Read activity is only valid while a job is running.",
|
|
825
|
+
path: ["status"]
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
if (event.type === "phase" && ["answered", "cancelled", "failed"].includes(event.status)) {
|
|
829
|
+
context.addIssue({
|
|
830
|
+
code: "custom",
|
|
831
|
+
message: "Phase events cannot report a terminal state.",
|
|
832
|
+
path: ["status"]
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
if (event.type === "answer-ready" && event.status !== "answered") {
|
|
836
|
+
context.addIssue({
|
|
837
|
+
code: "custom",
|
|
838
|
+
message: "Answer-ready must report the answered state.",
|
|
839
|
+
path: ["status"]
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
if (event.type === "error" && !["failed", "cancelled"].includes(event.status)) {
|
|
843
|
+
context.addIssue({
|
|
844
|
+
code: "custom",
|
|
845
|
+
message: "Error events must report a terminal error state.",
|
|
846
|
+
path: ["status"]
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
if (event.type === "error" && (event.status === "cancelled" && event.errorCode !== "ASK_CANCELLED" || event.status === "failed" && event.errorCode === "ASK_CANCELLED")) {
|
|
850
|
+
context.addIssue({
|
|
851
|
+
code: "custom",
|
|
852
|
+
message: "Error event code does not match its status.",
|
|
853
|
+
path: ["errorCode"]
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
// src/protocol/endpoints.ts
|
|
859
|
+
var SPOTPATCH_API_BASE = "/__spotpatch/v1";
|
|
860
|
+
var SPOTPATCH_TOKEN_HEADER = "X-SpotPatch-Token";
|
|
861
|
+
var SPOTPATCH_ENDPOINTS = Object.freeze({
|
|
862
|
+
bootstrap: `${SPOTPATCH_API_BASE}/bootstrap`,
|
|
863
|
+
sourceContext: `${SPOTPATCH_API_BASE}/source-context`,
|
|
864
|
+
openEditor: `${SPOTPATCH_API_BASE}/open-editor`,
|
|
865
|
+
dataFlowComponentReport: `${SPOTPATCH_API_BASE}/data-flow/component-report`,
|
|
866
|
+
dataFlowPageReport: `${SPOTPATCH_API_BASE}/data-flow/page-report`,
|
|
867
|
+
agentCapability: `${SPOTPATCH_API_BASE}/agent/capability`,
|
|
868
|
+
agentWorkspaceHealth: `${SPOTPATCH_API_BASE}/agent/workspace-health`,
|
|
869
|
+
agentJobs: `${SPOTPATCH_API_BASE}/agent/jobs`,
|
|
870
|
+
askCapability: `${SPOTPATCH_API_BASE}/ask/capability`,
|
|
871
|
+
askJobs: `${SPOTPATCH_API_BASE}/ask/jobs`,
|
|
872
|
+
externalHandoffCapability: `${SPOTPATCH_API_BASE}/external-handoff/capability`,
|
|
873
|
+
externalHandoffPublish: `${SPOTPATCH_API_BASE}/external-handoff/publish`,
|
|
874
|
+
externalHandoffStatus: `${SPOTPATCH_API_BASE}/external-handoff/status`,
|
|
875
|
+
externalHandoffResolveDelivery: `${SPOTPATCH_API_BASE}/external-handoff/resolve-delivery`,
|
|
876
|
+
externalAgentControlStatus: `${SPOTPATCH_API_BASE}/external-agent/control/status`,
|
|
877
|
+
externalAgentControlConnect: `${SPOTPATCH_API_BASE}/external-agent/control/connect`,
|
|
878
|
+
externalAgentControlDisconnect: `${SPOTPATCH_API_BASE}/external-agent/control/disconnect`,
|
|
879
|
+
externalAgentControlCancel: `${SPOTPATCH_API_BASE}/external-agent/control/cancel`,
|
|
880
|
+
externalAgentEvents: `${SPOTPATCH_API_BASE}/external-agent/events`,
|
|
881
|
+
externalAgentResult: `${SPOTPATCH_API_BASE}/external-agent/result`
|
|
882
|
+
});
|
|
883
|
+
function getAskJobEndpoint(jobId, action, options = {}) {
|
|
884
|
+
const endpoint = `${SPOTPATCH_ENDPOINTS.askJobs}/${encodeURIComponent(jobId)}/${action}`;
|
|
885
|
+
if (action !== "events" && options.afterSequence !== void 0) {
|
|
886
|
+
throw new RangeError("afterSequence is only valid for the events endpoint.");
|
|
887
|
+
}
|
|
888
|
+
if (options.afterSequence === void 0) return endpoint;
|
|
889
|
+
if (!Number.isSafeInteger(options.afterSequence) || options.afterSequence < 0) {
|
|
890
|
+
throw new RangeError("afterSequence must be a non-negative safe integer.");
|
|
891
|
+
}
|
|
892
|
+
return `${endpoint}?afterSequence=${String(options.afterSequence)}`;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// src/contextual-ask-node.ts
|
|
896
|
+
function adaptChangeEnvelopeToSpotAnnotationV3(envelope) {
|
|
897
|
+
const change = spotChangeTaskEnvelopeSchema.parse(envelope);
|
|
898
|
+
const instructions = new Map(
|
|
899
|
+
change.task.instructions.map((instruction) => [
|
|
900
|
+
instruction.targetId,
|
|
901
|
+
instruction.instruction
|
|
902
|
+
])
|
|
903
|
+
);
|
|
904
|
+
const firstTarget = change.selection.targets[0];
|
|
905
|
+
if (firstTarget === void 0) {
|
|
906
|
+
throw new TypeError("A Change envelope must contain at least one target.");
|
|
907
|
+
}
|
|
908
|
+
const targets = change.selection.targets.map(({ targetId, page, ...target }) => {
|
|
909
|
+
const instruction = instructions.get(targetId);
|
|
910
|
+
if (instruction === void 0) {
|
|
911
|
+
throw new TypeError("A Change target must have an instruction.");
|
|
912
|
+
}
|
|
913
|
+
return { ...target, page, instruction };
|
|
914
|
+
});
|
|
915
|
+
const annotation = spotAnnotationSchema.parse({
|
|
916
|
+
schemaVersion: 3,
|
|
917
|
+
id: change.taskId,
|
|
918
|
+
locale: change.selection.locale,
|
|
919
|
+
page: firstTarget.page,
|
|
920
|
+
targets,
|
|
921
|
+
createdAt: change.createdAt
|
|
922
|
+
});
|
|
923
|
+
return annotation;
|
|
924
|
+
}
|
|
925
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
926
|
+
0 && (module.exports = {
|
|
927
|
+
ASK_ANSWER_WARNING_CODES,
|
|
928
|
+
ASK_EXECUTOR_ANSWER_WARNING_CODES,
|
|
929
|
+
ASK_FILE_COUNT_BUCKETS,
|
|
930
|
+
ASK_JOB_STATUSES,
|
|
931
|
+
ASK_READ_ACTIVITY_STATES,
|
|
932
|
+
ASK_SOURCE_CONFIDENCES,
|
|
933
|
+
CONTEXTUAL_ASK_ERROR_CODES,
|
|
934
|
+
CONTEXTUAL_ASK_EXECUTOR_KINDS,
|
|
935
|
+
CONTEXTUAL_ASK_EXECUTOR_STATES,
|
|
936
|
+
CONTEXTUAL_ASK_LIMITS,
|
|
937
|
+
CONTEXTUAL_ASK_PERMISSION_PROFILE,
|
|
938
|
+
CONTEXTUAL_ASK_SCHEMA_VERSION,
|
|
939
|
+
SPOTPATCH_ENDPOINTS,
|
|
940
|
+
SPOTPATCH_TOKEN_HEADER,
|
|
941
|
+
adaptChangeEnvelopeToSpotAnnotationV3,
|
|
942
|
+
askAnswerBlockSchema,
|
|
943
|
+
askAnswerDraftBlockSchema,
|
|
944
|
+
askAnswerDraftSchema,
|
|
945
|
+
askAnswerResultSchema,
|
|
946
|
+
askAnswerWarningSchema,
|
|
947
|
+
askDraftCitationSchema,
|
|
948
|
+
askDraftOriginSchema,
|
|
949
|
+
askJobActionRequestSchema,
|
|
950
|
+
askJobCreateRequestSchema,
|
|
951
|
+
askJobEventSchema,
|
|
952
|
+
askJobEventsRequestSchema,
|
|
953
|
+
askJobResultResponseSchema,
|
|
954
|
+
askJobSnapshotSchema,
|
|
955
|
+
askSourceReferenceSchema,
|
|
956
|
+
contextualAskCapabilityRequestSchema,
|
|
957
|
+
contextualAskCapabilitySchema,
|
|
958
|
+
contextualAskExecutorCapabilitySchema,
|
|
959
|
+
contextualAskExecutorPreferenceSchema,
|
|
960
|
+
contextualAskOptionsSchema,
|
|
961
|
+
getAskJobEndpoint,
|
|
962
|
+
spotAskTaskEnvelopeSchema,
|
|
963
|
+
spotChangeTaskEnvelopeSchema,
|
|
964
|
+
spotSelectionContextSchema,
|
|
965
|
+
spotSelectionTargetSchema,
|
|
966
|
+
spotTaskEnvelopeSchema
|
|
967
|
+
});
|
|
968
|
+
//# sourceMappingURL=contextual-ask-node.cjs.map
|