@spotpatch/dev-server 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/README.md +31 -0
- package/dist/index.cjs +2447 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +2438 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { applyPreparedAgentChange, executeAgentChange, inspectAgentWorkspace, probeProviderCapability, resolveProviderCredential, revertPreparedAgentChange } from '@spotpatch/agent';
|
|
2
|
+
import { AgentJobEvent, AgentJobSnapshot, AgentJobCreateRequest, AgentCapabilityRequest, AgentCapabilitySnapshot, AgentJobResultResponse, AgentWorkspaceHealthSnapshot, ResolvedAiOptions, SpotPatchEditorPreference, ContextBudget, SpotPatchLocalePreference, AiProviderProtocol, AiProviderAuthentication, AiExecutionOptions, AiOptions, RuntimeAiConfig, SpotPatchRuntimeConfig } from '@spotpatch/shared';
|
|
3
|
+
import { SourceFilterEntry } from '@spotpatch/compiler';
|
|
4
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
|
+
|
|
6
|
+
type AgentJobEventListener = (event: AgentJobEvent) => void;
|
|
7
|
+
interface AgentJobManager {
|
|
8
|
+
apply(jobId: string): Promise<AgentJobSnapshot>;
|
|
9
|
+
cancel(jobId: string): AgentJobSnapshot;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
create(request: AgentJobCreateRequest): AgentJobSnapshot;
|
|
12
|
+
events(jobId: string): readonly AgentJobEvent[];
|
|
13
|
+
probe(request: AgentCapabilityRequest, signal: AbortSignal): Promise<AgentCapabilitySnapshot>;
|
|
14
|
+
result(jobId: string): AgentJobResultResponse;
|
|
15
|
+
revert(jobId: string): Promise<AgentJobSnapshot>;
|
|
16
|
+
subscribe(jobId: string, listener: AgentJobEventListener): () => void;
|
|
17
|
+
workspaceHealth(signal: AbortSignal): Promise<AgentWorkspaceHealthSnapshot>;
|
|
18
|
+
}
|
|
19
|
+
interface AgentJobManagerDependencies {
|
|
20
|
+
readonly applyChange: typeof applyPreparedAgentChange;
|
|
21
|
+
readonly createJobId: () => string;
|
|
22
|
+
readonly executeChange: typeof executeAgentChange;
|
|
23
|
+
readonly inspectWorkspace: typeof inspectAgentWorkspace;
|
|
24
|
+
readonly now: () => string;
|
|
25
|
+
readonly probeCapability: typeof probeProviderCapability;
|
|
26
|
+
readonly resolveCredential: typeof resolveProviderCredential;
|
|
27
|
+
readonly revertChange: typeof revertPreparedAgentChange;
|
|
28
|
+
}
|
|
29
|
+
interface CreateAgentJobManagerOptions {
|
|
30
|
+
readonly ai: ResolvedAiOptions;
|
|
31
|
+
readonly dependencies?: Partial<AgentJobManagerDependencies>;
|
|
32
|
+
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
33
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
34
|
+
readonly root: string;
|
|
35
|
+
}
|
|
36
|
+
declare function createAgentJobManager(options: CreateAgentJobManagerOptions): AgentJobManager;
|
|
37
|
+
|
|
38
|
+
type FilterEntry = SourceFilterEntry;
|
|
39
|
+
interface SimpleAiOptions {
|
|
40
|
+
readonly baseURL: string;
|
|
41
|
+
readonly model: string;
|
|
42
|
+
readonly apiKeyEnv?: string;
|
|
43
|
+
readonly protocol?: AiProviderProtocol;
|
|
44
|
+
readonly authentication?: AiProviderAuthentication;
|
|
45
|
+
readonly providerLabel?: string;
|
|
46
|
+
readonly modelLabel?: string;
|
|
47
|
+
readonly execution?: AiExecutionOptions;
|
|
48
|
+
}
|
|
49
|
+
type SpotPatchAiOptions = false | SimpleAiOptions | AiOptions;
|
|
50
|
+
interface SpotPatchOptions {
|
|
51
|
+
readonly enabled?: boolean;
|
|
52
|
+
readonly include?: readonly FilterEntry[];
|
|
53
|
+
readonly exclude?: readonly FilterEntry[];
|
|
54
|
+
readonly editor?: SpotPatchEditorPreference;
|
|
55
|
+
readonly redact?: boolean;
|
|
56
|
+
readonly budget?: Partial<ContextBudget>;
|
|
57
|
+
readonly shortcut?: string;
|
|
58
|
+
readonly allowLan?: boolean;
|
|
59
|
+
readonly debug?: boolean;
|
|
60
|
+
readonly locale?: SpotPatchLocalePreference;
|
|
61
|
+
readonly maxTargets?: number;
|
|
62
|
+
readonly ai?: SpotPatchAiOptions;
|
|
63
|
+
}
|
|
64
|
+
interface ResolvedSpotPatchOptions {
|
|
65
|
+
readonly enabled: boolean;
|
|
66
|
+
readonly include: readonly FilterEntry[];
|
|
67
|
+
readonly exclude: readonly FilterEntry[];
|
|
68
|
+
readonly editor: SpotPatchEditorPreference;
|
|
69
|
+
readonly redact: boolean;
|
|
70
|
+
readonly budget: Readonly<ContextBudget>;
|
|
71
|
+
readonly shortcut: string;
|
|
72
|
+
readonly allowLan: boolean;
|
|
73
|
+
readonly debug: boolean;
|
|
74
|
+
readonly locale: SpotPatchLocalePreference;
|
|
75
|
+
readonly maxTargets: number;
|
|
76
|
+
readonly ai: false | ResolvedAiOptions;
|
|
77
|
+
}
|
|
78
|
+
declare const DEFAULT_EXCLUDE: readonly RegExp[];
|
|
79
|
+
declare const DEFAULT_OPTIONS: Readonly<{
|
|
80
|
+
enabled: true;
|
|
81
|
+
include: readonly RegExp[];
|
|
82
|
+
exclude: readonly RegExp[];
|
|
83
|
+
editor: "auto";
|
|
84
|
+
redact: true;
|
|
85
|
+
budget: Readonly<{
|
|
86
|
+
totalCharacters: number;
|
|
87
|
+
domCharacters: number;
|
|
88
|
+
cssCharacters: number;
|
|
89
|
+
codeCharacters: number;
|
|
90
|
+
maxCodeLines: number;
|
|
91
|
+
maxComponentDepth: number;
|
|
92
|
+
}>;
|
|
93
|
+
shortcut: string;
|
|
94
|
+
allowLan: false;
|
|
95
|
+
debug: false;
|
|
96
|
+
locale: "auto";
|
|
97
|
+
maxTargets: number;
|
|
98
|
+
ai: false;
|
|
99
|
+
}>;
|
|
100
|
+
declare function createRuntimeAiConfig(options: false | ResolvedAiOptions): RuntimeAiConfig;
|
|
101
|
+
declare function resolveOptions(options?: SpotPatchOptions, environmentAi?: false | SimpleAiOptions): ResolvedSpotPatchOptions;
|
|
102
|
+
|
|
103
|
+
interface EnvironmentAiConfiguration {
|
|
104
|
+
readonly ai: false | SimpleAiOptions;
|
|
105
|
+
}
|
|
106
|
+
declare function resolveCredentialEnvironment(options: ResolvedSpotPatchOptions, environment: Readonly<Record<string, string | undefined>>): Readonly<Record<string, string>>;
|
|
107
|
+
declare function resolveEnvironmentAiConfiguration(environment: Readonly<Record<string, string | undefined>>): EnvironmentAiConfiguration;
|
|
108
|
+
|
|
109
|
+
type SourceIdFactory = () => string;
|
|
110
|
+
|
|
111
|
+
interface SourceRegistry {
|
|
112
|
+
register(absolutePath: string): string;
|
|
113
|
+
resolve(fileId: string): string | undefined;
|
|
114
|
+
clear(): void;
|
|
115
|
+
}
|
|
116
|
+
interface SourceRegistryOptions {
|
|
117
|
+
readonly createId?: SourceIdFactory;
|
|
118
|
+
}
|
|
119
|
+
declare function createSourceRegistry(options?: SourceRegistryOptions): SourceRegistry;
|
|
120
|
+
|
|
121
|
+
interface SpotPatchSession {
|
|
122
|
+
readonly token: string;
|
|
123
|
+
}
|
|
124
|
+
declare function createSession(): SpotPatchSession;
|
|
125
|
+
|
|
126
|
+
type EditorLauncher = (target: string, editor: SpotPatchEditorPreference) => Promise<SpotPatchEditorPreference>;
|
|
127
|
+
|
|
128
|
+
interface RuntimeBootstrapOptions {
|
|
129
|
+
readonly expectedOrigin: string;
|
|
130
|
+
readonly runtimeConfig: SpotPatchRuntimeConfig;
|
|
131
|
+
}
|
|
132
|
+
interface ResolvedRuntimeBootstrapOptions {
|
|
133
|
+
readonly expectedOrigin: string;
|
|
134
|
+
readonly runtimeConfig: SpotPatchRuntimeConfig;
|
|
135
|
+
}
|
|
136
|
+
declare function resolveRuntimeBootstrapOptions(options: RuntimeBootstrapOptions): ResolvedRuntimeBootstrapOptions;
|
|
137
|
+
declare function readRuntimeBootstrap(request: IncomingMessage, options: ResolvedRuntimeBootstrapOptions): Promise<SpotPatchRuntimeConfig>;
|
|
138
|
+
|
|
139
|
+
type SpotPatchNext = (error?: unknown) => void;
|
|
140
|
+
type SpotPatchMiddleware = (request: IncomingMessage, response: ServerResponse, next: SpotPatchNext) => void;
|
|
141
|
+
interface SpotPatchServerLogger {
|
|
142
|
+
warn(message: string): void;
|
|
143
|
+
}
|
|
144
|
+
interface CreateMiddlewareOptions {
|
|
145
|
+
readonly agentManager?: AgentJobManager;
|
|
146
|
+
readonly bootstrap?: RuntimeBootstrapOptions;
|
|
147
|
+
readonly editorLauncher?: EditorLauncher;
|
|
148
|
+
readonly logger?: SpotPatchServerLogger;
|
|
149
|
+
readonly options: ResolvedSpotPatchOptions;
|
|
150
|
+
readonly registry: SourceRegistry;
|
|
151
|
+
readonly root: string;
|
|
152
|
+
readonly session: SpotPatchSession;
|
|
153
|
+
}
|
|
154
|
+
declare function createSpotPatchMiddleware(options: CreateMiddlewareOptions): SpotPatchMiddleware;
|
|
155
|
+
|
|
156
|
+
declare function readJsonRequestBody(request: IncomingMessage, maximumBytes?: number): Promise<unknown>;
|
|
157
|
+
|
|
158
|
+
declare function isLoopbackHostname(hostname: string): boolean;
|
|
159
|
+
|
|
160
|
+
interface SourceRegistrationServiceOptions {
|
|
161
|
+
readonly internalSecret: string;
|
|
162
|
+
readonly options: ResolvedSpotPatchOptions;
|
|
163
|
+
readonly registry: SourceRegistry;
|
|
164
|
+
readonly registryEpoch: string;
|
|
165
|
+
readonly root: string;
|
|
166
|
+
}
|
|
167
|
+
type SourceRegistrationHandler = (request: IncomingMessage, response: ServerResponse) => void;
|
|
168
|
+
interface SourceRegistrationService {
|
|
169
|
+
readonly handler: SourceRegistrationHandler;
|
|
170
|
+
readonly root: string;
|
|
171
|
+
}
|
|
172
|
+
declare function createSourceRegistrationService(input: SourceRegistrationServiceOptions): Promise<SourceRegistrationService>;
|
|
173
|
+
|
|
174
|
+
interface SerializedStringFilter {
|
|
175
|
+
readonly kind: "string";
|
|
176
|
+
readonly value: string;
|
|
177
|
+
}
|
|
178
|
+
interface SerializedRegExpFilter {
|
|
179
|
+
readonly flags: string;
|
|
180
|
+
readonly kind: "regexp";
|
|
181
|
+
readonly source: string;
|
|
182
|
+
}
|
|
183
|
+
type SerializedFilterEntry = SerializedRegExpFilter | SerializedStringFilter;
|
|
184
|
+
interface SerializedSpotPatchOptions {
|
|
185
|
+
readonly ai: false | AiOptions;
|
|
186
|
+
readonly allowLan: boolean;
|
|
187
|
+
readonly budget: Readonly<ContextBudget>;
|
|
188
|
+
readonly debug: boolean;
|
|
189
|
+
readonly editor: SpotPatchEditorPreference;
|
|
190
|
+
readonly enabled: boolean;
|
|
191
|
+
readonly exclude: readonly SerializedFilterEntry[];
|
|
192
|
+
readonly include: readonly SerializedFilterEntry[];
|
|
193
|
+
readonly locale: SpotPatchLocalePreference;
|
|
194
|
+
readonly maxTargets: number;
|
|
195
|
+
readonly redact: boolean;
|
|
196
|
+
readonly shortcut: string;
|
|
197
|
+
}
|
|
198
|
+
declare function serializeResolvedSpotPatchOptions(options: ResolvedSpotPatchOptions): SerializedSpotPatchOptions;
|
|
199
|
+
declare function parseSerializedSpotPatchOptions(value: unknown): ResolvedSpotPatchOptions;
|
|
200
|
+
|
|
201
|
+
export { type AgentJobEventListener, type AgentJobManager, type CreateAgentJobManagerOptions, type CreateMiddlewareOptions, DEFAULT_EXCLUDE, DEFAULT_OPTIONS, type EnvironmentAiConfiguration, type FilterEntry, type ResolvedRuntimeBootstrapOptions, type ResolvedSpotPatchOptions, type RuntimeBootstrapOptions, type SerializedFilterEntry, type SerializedSpotPatchOptions, type SimpleAiOptions, type SourceRegistrationHandler, type SourceRegistrationService, type SourceRegistrationServiceOptions, type SourceRegistry, type SpotPatchAiOptions, type SpotPatchMiddleware, type SpotPatchNext, type SpotPatchOptions, type SpotPatchServerLogger, type SpotPatchSession, createAgentJobManager, createRuntimeAiConfig, createSession, createSourceRegistrationService, createSourceRegistry, createSpotPatchMiddleware, isLoopbackHostname, parseSerializedSpotPatchOptions, readJsonRequestBody, readRuntimeBootstrap, resolveCredentialEnvironment, resolveEnvironmentAiConfiguration, resolveOptions, resolveRuntimeBootstrapOptions, serializeResolvedSpotPatchOptions };
|