opencode-ext-connector 0.3.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/CHANGELOG.md +39 -0
- package/LICENSE +29 -0
- package/README.md +207 -0
- package/THIRD_PARTY_NOTICES.md +201 -0
- package/dist/catalog/parse-ids.d.ts +2 -0
- package/dist/catalog/parse-ids.js +49 -0
- package/dist/core/adapter.d.ts +16 -0
- package/dist/core/adapter.js +20 -0
- package/dist/core/clock.d.ts +7 -0
- package/dist/core/clock.js +1 -0
- package/dist/core/deadline.d.ts +13 -0
- package/dist/core/deadline.js +54 -0
- package/dist/core/errors.d.ts +57 -0
- package/dist/core/errors.js +81 -0
- package/dist/core/health.d.ts +22 -0
- package/dist/core/health.js +30 -0
- package/dist/core/http.d.ts +28 -0
- package/dist/core/http.js +1 -0
- package/dist/core/ids.d.ts +7 -0
- package/dist/core/ids.js +23 -0
- package/dist/core/lifecycle.d.ts +4 -0
- package/dist/core/lifecycle.js +16 -0
- package/dist/core/logger.d.ts +21 -0
- package/dist/core/logger.js +61 -0
- package/dist/core/models.d.ts +41 -0
- package/dist/core/models.js +59 -0
- package/dist/core/options.d.ts +31 -0
- package/dist/core/options.js +62 -0
- package/dist/core/process.d.ts +20 -0
- package/dist/core/process.js +1 -0
- package/dist/http/fetch-transport.d.ts +2 -0
- package/dist/http/fetch-transport.js +75 -0
- package/dist/http/package-version.d.ts +7 -0
- package/dist/http/package-version.js +46 -0
- package/dist/http/read-body.d.ts +9 -0
- package/dist/http/read-body.js +22 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/logging/logger.d.ts +4 -0
- package/dist/logging/logger.js +11 -0
- package/dist/opencode/auth-store.d.ts +19 -0
- package/dist/opencode/auth-store.js +107 -0
- package/dist/opencode/beta-api.d.ts +3 -0
- package/dist/opencode/beta-api.js +1 -0
- package/dist/opencode/catalog-bridge.d.ts +3 -0
- package/dist/opencode/catalog-bridge.js +85 -0
- package/dist/opencode/health-refresh.d.ts +16 -0
- package/dist/opencode/health-refresh.js +49 -0
- package/dist/opencode/host-options.d.ts +2 -0
- package/dist/opencode/host-options.js +49 -0
- package/dist/opencode/language-factory.d.ts +13 -0
- package/dist/opencode/language-factory.js +37 -0
- package/dist/opencode/ollama-probe.d.ts +2 -0
- package/dist/opencode/ollama-probe.js +15 -0
- package/dist/opencode/ollama-production.d.ts +4 -0
- package/dist/opencode/ollama-production.js +10 -0
- package/dist/opencode/plugin.d.ts +33 -0
- package/dist/opencode/plugin.js +40 -0
- package/dist/opencode/process-exit.d.ts +4 -0
- package/dist/opencode/process-exit.js +22 -0
- package/dist/opencode/provider-entry.d.ts +25 -0
- package/dist/opencode/provider-entry.js +1 -0
- package/dist/opencode/providers.d.ts +16 -0
- package/dist/opencode/providers.js +140 -0
- package/dist/opencode/register-integrations.d.ts +3 -0
- package/dist/opencode/register-integrations.js +8 -0
- package/dist/opencode/reload.d.ts +9 -0
- package/dist/opencode/reload.js +30 -0
- package/dist/opencode/v1-anthropic-auth.d.ts +9 -0
- package/dist/opencode/v1-anthropic-auth.js +55 -0
- package/dist/opencode/v1-catalog.d.ts +13 -0
- package/dist/opencode/v1-catalog.js +80 -0
- package/dist/opencode/v1-language.d.ts +3 -0
- package/dist/opencode/v1-language.js +64 -0
- package/dist/opencode/v1-module.d.ts +23 -0
- package/dist/opencode/v1-module.js +74 -0
- package/dist/opencode/v1-session-auth.d.ts +5 -0
- package/dist/opencode/v1-session-auth.js +98 -0
- package/dist/providers/claude/adapter.d.ts +7 -0
- package/dist/providers/claude/adapter.js +37 -0
- package/dist/providers/claude/atomic-private-file.d.ts +13 -0
- package/dist/providers/claude/atomic-private-file.js +94 -0
- package/dist/providers/claude/auth-json.d.ts +2 -0
- package/dist/providers/claude/auth-json.js +14 -0
- package/dist/providers/claude/auth.d.ts +24 -0
- package/dist/providers/claude/auth.js +200 -0
- package/dist/providers/claude/cli-version.d.ts +10 -0
- package/dist/providers/claude/cli-version.js +36 -0
- package/dist/providers/claude/compat-betas.d.ts +5 -0
- package/dist/providers/claude/compat-betas.js +54 -0
- package/dist/providers/claude/compat-config.d.ts +8 -0
- package/dist/providers/claude/compat-config.js +31 -0
- package/dist/providers/claude/compat-request.d.ts +12 -0
- package/dist/providers/claude/compat-request.js +151 -0
- package/dist/providers/claude/compat-response.d.ts +1 -0
- package/dist/providers/claude/compat-response.js +54 -0
- package/dist/providers/claude/compat-signing.d.ts +9 -0
- package/dist/providers/claude/compat-signing.js +24 -0
- package/dist/providers/claude/compat-transform.d.ts +3 -0
- package/dist/providers/claude/compat-transform.js +224 -0
- package/dist/providers/claude/credentials.d.ts +7 -0
- package/dist/providers/claude/credentials.js +37 -0
- package/dist/providers/claude/emit-stream.d.ts +2 -0
- package/dist/providers/claude/emit-stream.js +62 -0
- package/dist/providers/claude/keychain-account.d.ts +1 -0
- package/dist/providers/claude/keychain-account.js +14 -0
- package/dist/providers/claude/language-model.d.ts +8 -0
- package/dist/providers/claude/language-model.js +109 -0
- package/dist/providers/claude/models.d.ts +9 -0
- package/dist/providers/claude/models.js +24 -0
- package/dist/providers/claude/prompt.d.ts +42 -0
- package/dist/providers/claude/prompt.js +134 -0
- package/dist/providers/claude/refresh.d.ts +19 -0
- package/dist/providers/claude/refresh.js +85 -0
- package/dist/providers/claude/sse-convert.d.ts +6 -0
- package/dist/providers/claude/sse-convert.js +74 -0
- package/dist/providers/claude/sse.d.ts +71 -0
- package/dist/providers/claude/sse.js +123 -0
- package/dist/providers/claude/transform.d.ts +32 -0
- package/dist/providers/claude/transform.js +52 -0
- package/dist/providers/claude/writeback.d.ts +18 -0
- package/dist/providers/claude/writeback.js +140 -0
- package/dist/providers/command-code/adapter.d.ts +7 -0
- package/dist/providers/command-code/adapter.js +37 -0
- package/dist/providers/command-code/auth.d.ts +5 -0
- package/dist/providers/command-code/auth.js +88 -0
- package/dist/providers/command-code/cli-version.d.ts +10 -0
- package/dist/providers/command-code/cli-version.js +36 -0
- package/dist/providers/command-code/emit-stream.d.ts +2 -0
- package/dist/providers/command-code/emit-stream.js +226 -0
- package/dist/providers/command-code/errors.d.ts +33 -0
- package/dist/providers/command-code/errors.js +105 -0
- package/dist/providers/command-code/language-model.d.ts +15 -0
- package/dist/providers/command-code/language-model.js +203 -0
- package/dist/providers/command-code/models.d.ts +3 -0
- package/dist/providers/command-code/models.js +18 -0
- package/dist/providers/command-code/record-stream.d.ts +1 -0
- package/dist/providers/command-code/record-stream.js +61 -0
- package/dist/providers/command-code/request-lifecycle.d.ts +8 -0
- package/dist/providers/command-code/request-lifecycle.js +33 -0
- package/dist/providers/command-code/request.d.ts +14 -0
- package/dist/providers/command-code/request.js +167 -0
- package/dist/providers/command-code/session.d.ts +5 -0
- package/dist/providers/command-code/session.js +9 -0
- package/dist/providers/cursor/adapter.d.ts +7 -0
- package/dist/providers/cursor/adapter.js +37 -0
- package/dist/providers/cursor/auth.d.ts +6 -0
- package/dist/providers/cursor/auth.js +56 -0
- package/dist/providers/cursor/blob-store.d.ts +26 -0
- package/dist/providers/cursor/blob-store.js +119 -0
- package/dist/providers/cursor/bridge-client.d.ts +33 -0
- package/dist/providers/cursor/bridge-client.js +200 -0
- package/dist/providers/cursor/bridge-event-sanitize.d.ts +3 -0
- package/dist/providers/cursor/bridge-event-sanitize.js +49 -0
- package/dist/providers/cursor/bridge-limits.d.ts +3 -0
- package/dist/providers/cursor/bridge-limits.js +10 -0
- package/dist/providers/cursor/bridge-process.d.ts +45 -0
- package/dist/providers/cursor/bridge-process.js +211 -0
- package/dist/providers/cursor/bridge-protocol.d.ts +68 -0
- package/dist/providers/cursor/bridge-protocol.js +49 -0
- package/dist/providers/cursor/bridge-serialize.d.ts +3 -0
- package/dist/providers/cursor/bridge-serialize.js +53 -0
- package/dist/providers/cursor/bridge-wire.d.ts +3 -0
- package/dist/providers/cursor/bridge-wire.js +163 -0
- package/dist/providers/cursor/checkpoint-store.d.ts +28 -0
- package/dist/providers/cursor/checkpoint-store.js +94 -0
- package/dist/providers/cursor/connect-frame-stream.d.ts +19 -0
- package/dist/providers/cursor/connect-frame-stream.js +160 -0
- package/dist/providers/cursor/connect-frame.d.ts +31 -0
- package/dist/providers/cursor/connect-frame.js +121 -0
- package/dist/providers/cursor/credentials.d.ts +5 -0
- package/dist/providers/cursor/credentials.js +22 -0
- package/dist/providers/cursor/direct-run-types.d.ts +33 -0
- package/dist/providers/cursor/direct-run-types.js +1 -0
- package/dist/providers/cursor/direct-run.d.ts +5 -0
- package/dist/providers/cursor/direct-run.js +213 -0
- package/dist/providers/cursor/direct-runtime.d.ts +23 -0
- package/dist/providers/cursor/direct-runtime.js +111 -0
- package/dist/providers/cursor/direct-stream.d.ts +28 -0
- package/dist/providers/cursor/direct-stream.js +190 -0
- package/dist/providers/cursor/exec-reply.d.ts +13 -0
- package/dist/providers/cursor/exec-reply.js +102 -0
- package/dist/providers/cursor/h2-bridge-response.d.ts +9 -0
- package/dist/providers/cursor/h2-bridge-response.js +51 -0
- package/dist/providers/cursor/h2-bridge-session.d.ts +24 -0
- package/dist/providers/cursor/h2-bridge-session.js +197 -0
- package/dist/providers/cursor/h2-bridge.d.ts +2 -0
- package/dist/providers/cursor/h2-bridge.js +12865 -0
- package/dist/providers/cursor/http2.d.ts +18 -0
- package/dist/providers/cursor/http2.js +144 -0
- package/dist/providers/cursor/interaction-reply.d.ts +6 -0
- package/dist/providers/cursor/interaction-reply.js +52 -0
- package/dist/providers/cursor/language-generate.d.ts +2 -0
- package/dist/providers/cursor/language-generate.js +35 -0
- package/dist/providers/cursor/language-model.d.ts +13 -0
- package/dist/providers/cursor/language-model.js +77 -0
- package/dist/providers/cursor/legacy-stream.d.ts +11 -0
- package/dist/providers/cursor/legacy-stream.js +115 -0
- package/dist/providers/cursor/mcp-tools.d.ts +7 -0
- package/dist/providers/cursor/mcp-tools.js +15 -0
- package/dist/providers/cursor/models.d.ts +14 -0
- package/dist/providers/cursor/models.js +116 -0
- package/dist/providers/cursor/ndjson.d.ts +3 -0
- package/dist/providers/cursor/ndjson.js +100 -0
- package/dist/providers/cursor/prompt.d.ts +4 -0
- package/dist/providers/cursor/prompt.js +142 -0
- package/dist/providers/cursor/proto/checkpoint.d.ts +35 -0
- package/dist/providers/cursor/proto/checkpoint.js +114 -0
- package/dist/providers/cursor/proto/context.d.ts +64 -0
- package/dist/providers/cursor/proto/context.js +178 -0
- package/dist/providers/cursor/proto/errors.d.ts +16 -0
- package/dist/providers/cursor/proto/errors.js +26 -0
- package/dist/providers/cursor/proto/exec-control.d.ts +20 -0
- package/dist/providers/cursor/proto/exec-control.js +54 -0
- package/dist/providers/cursor/proto/exec.d.ts +47 -0
- package/dist/providers/cursor/proto/exec.js +154 -0
- package/dist/providers/cursor/proto/fields.d.ts +22 -0
- package/dist/providers/cursor/proto/fields.js +97 -0
- package/dist/providers/cursor/proto/interaction-query.d.ts +15 -0
- package/dist/providers/cursor/proto/interaction-query.js +79 -0
- package/dist/providers/cursor/proto/interaction-tool-update.d.ts +10 -0
- package/dist/providers/cursor/proto/interaction-tool-update.js +58 -0
- package/dist/providers/cursor/proto/interaction-turn-ended.d.ts +6 -0
- package/dist/providers/cursor/proto/interaction-turn-ended.js +18 -0
- package/dist/providers/cursor/proto/interaction.d.ts +65 -0
- package/dist/providers/cursor/proto/interaction.js +185 -0
- package/dist/providers/cursor/proto/kv.d.ts +25 -0
- package/dist/providers/cursor/proto/kv.js +109 -0
- package/dist/providers/cursor/proto/mcp-result.d.ts +40 -0
- package/dist/providers/cursor/proto/mcp-result.js +150 -0
- package/dist/providers/cursor/proto/mcp.d.ts +19 -0
- package/dist/providers/cursor/proto/mcp.js +78 -0
- package/dist/providers/cursor/proto/model.d.ts +11 -0
- package/dist/providers/cursor/proto/model.js +36 -0
- package/dist/providers/cursor/proto/output-location.d.ts +7 -0
- package/dist/providers/cursor/proto/output-location.js +53 -0
- package/dist/providers/cursor/proto/prewarm.d.ts +16 -0
- package/dist/providers/cursor/proto/prewarm.js +68 -0
- package/dist/providers/cursor/proto/request-context.d.ts +16 -0
- package/dist/providers/cursor/proto/request-context.js +58 -0
- package/dist/providers/cursor/proto/request.d.ts +44 -0
- package/dist/providers/cursor/proto/request.js +111 -0
- package/dist/providers/cursor/proto/run-request.d.ts +19 -0
- package/dist/providers/cursor/proto/run-request.js +68 -0
- package/dist/providers/cursor/proto/server.d.ts +35 -0
- package/dist/providers/cursor/proto/server.js +93 -0
- package/dist/providers/cursor/proto/unknown-field.d.ts +1 -0
- package/dist/providers/cursor/proto/unknown-field.js +22 -0
- package/dist/providers/cursor/proto-value.d.ts +3 -0
- package/dist/providers/cursor/proto-value.js +170 -0
- package/dist/providers/cursor/proto-wire.d.ts +22 -0
- package/dist/providers/cursor/proto-wire.js +224 -0
- package/dist/providers/cursor/protocol-failure.d.ts +18 -0
- package/dist/providers/cursor/protocol-failure.js +45 -0
- package/dist/providers/cursor/recovery.d.ts +48 -0
- package/dist/providers/cursor/recovery.js +102 -0
- package/dist/providers/cursor/request-blob-ownership.d.ts +15 -0
- package/dist/providers/cursor/request-blob-ownership.js +39 -0
- package/dist/providers/cursor/request-build.d.ts +18 -0
- package/dist/providers/cursor/request-build.js +123 -0
- package/dist/providers/cursor/request-history.d.ts +32 -0
- package/dist/providers/cursor/request-history.js +163 -0
- package/dist/providers/cursor/request-input.d.ts +75 -0
- package/dist/providers/cursor/request-input.js +123 -0
- package/dist/providers/cursor/run-events.d.ts +15 -0
- package/dist/providers/cursor/run-events.js +43 -0
- package/dist/providers/cursor/run-session-expiry.d.ts +15 -0
- package/dist/providers/cursor/run-session-expiry.js +21 -0
- package/dist/providers/cursor/run-session.d.ts +50 -0
- package/dist/providers/cursor/run-session.js +205 -0
- package/dist/providers/cursor/run.d.ts +9 -0
- package/dist/providers/cursor/run.js +151 -0
- package/dist/providers/cursor/runner.d.ts +1 -0
- package/dist/providers/cursor/runner.js +55 -0
- package/dist/providers/cursor/server-dispatch-types.d.ts +83 -0
- package/dist/providers/cursor/server-dispatch-types.js +1 -0
- package/dist/providers/cursor/server-dispatch.d.ts +3 -0
- package/dist/providers/cursor/server-dispatch.js +178 -0
- package/dist/providers/cursor/session-state.d.ts +21 -0
- package/dist/providers/cursor/session-state.js +118 -0
- package/dist/providers/cursor/session.d.ts +1 -0
- package/dist/providers/cursor/session.js +26 -0
- package/dist/providers/cursor/settle-cleanup.d.ts +1 -0
- package/dist/providers/cursor/settle-cleanup.js +11 -0
- package/dist/providers/cursor/stream-adapter.d.ts +17 -0
- package/dist/providers/cursor/stream-adapter.js +99 -0
- package/dist/providers/cursor/tool-continuation.d.ts +14 -0
- package/dist/providers/cursor/tool-continuation.js +134 -0
- package/dist/providers/cursor/tool-stream.d.ts +2 -0
- package/dist/providers/cursor/tool-stream.js +220 -0
- package/dist/providers/cursor/usage.d.ts +3 -0
- package/dist/providers/cursor/usage.js +35 -0
- package/dist/providers/ollama/adapter.d.ts +8 -0
- package/dist/providers/ollama/adapter.js +65 -0
- package/dist/providers/ollama/catalog-state.d.ts +17 -0
- package/dist/providers/ollama/catalog-state.js +40 -0
- package/dist/providers/ollama/cloud-catalog.d.ts +3 -0
- package/dist/providers/ollama/cloud-catalog.js +82 -0
- package/dist/providers/ollama/errors.d.ts +14 -0
- package/dist/providers/ollama/errors.js +19 -0
- package/dist/providers/ollama/generate.d.ts +2 -0
- package/dist/providers/ollama/generate.js +49 -0
- package/dist/providers/ollama/html-links.d.ts +1 -0
- package/dist/providers/ollama/html-links.js +30 -0
- package/dist/providers/ollama/http.d.ts +12 -0
- package/dist/providers/ollama/http.js +67 -0
- package/dist/providers/ollama/index.d.ts +8 -0
- package/dist/providers/ollama/index.js +8 -0
- package/dist/providers/ollama/language-model.d.ts +11 -0
- package/dist/providers/ollama/language-model.js +62 -0
- package/dist/providers/ollama/local-catalog.d.ts +3 -0
- package/dist/providers/ollama/local-catalog.js +38 -0
- package/dist/providers/ollama/ndjson.d.ts +3 -0
- package/dist/providers/ollama/ndjson.js +51 -0
- package/dist/providers/ollama/prompt.d.ts +8 -0
- package/dist/providers/ollama/prompt.js +141 -0
- package/dist/providers/ollama/protocol.d.ts +56 -0
- package/dist/providers/ollama/protocol.js +26 -0
- package/dist/providers/ollama/runtime.d.ts +11 -0
- package/dist/providers/ollama/runtime.js +128 -0
- package/dist/providers/ollama/stream.d.ts +8 -0
- package/dist/providers/ollama/stream.js +110 -0
- package/dist/sdk/command-code.d.ts +5 -0
- package/dist/sdk/command-code.js +6 -0
- package/dist/sdk/cursor.d.ts +5 -0
- package/dist/sdk/cursor.js +6 -0
- package/dist/sdk/ollama.d.ts +5 -0
- package/dist/sdk/ollama.js +6 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +94 -0
- package/docs/README.ko.md +189 -0
- package/package.json +75 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ProviderId } from "./ids";
|
|
2
|
+
export type ConnectorErrorCode = "invalid-argument" | "operation-cancelled" | "deadline-exceeded" | "resource-disposed" | "adapter-error" | "http-transport-error" | "process-supervisor-error";
|
|
3
|
+
type ConnectorErrorOptions = {
|
|
4
|
+
readonly code: ConnectorErrorCode;
|
|
5
|
+
readonly retryable: boolean;
|
|
6
|
+
readonly cause: unknown | null;
|
|
7
|
+
};
|
|
8
|
+
export declare abstract class ConnectorError extends Error {
|
|
9
|
+
readonly code: ConnectorErrorCode;
|
|
10
|
+
readonly retryable: boolean;
|
|
11
|
+
readonly cause: unknown | null;
|
|
12
|
+
protected constructor(message: string, options: ConnectorErrorOptions);
|
|
13
|
+
}
|
|
14
|
+
export declare class InvalidArgumentError extends ConnectorError {
|
|
15
|
+
readonly argument: string;
|
|
16
|
+
readonly name = "InvalidArgumentError";
|
|
17
|
+
constructor(argument: string, cause?: unknown | null);
|
|
18
|
+
}
|
|
19
|
+
export declare class OperationCancelledError extends ConnectorError {
|
|
20
|
+
readonly operation: string;
|
|
21
|
+
readonly name = "OperationCancelledError";
|
|
22
|
+
constructor(operation: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class DeadlineExceededError extends ConnectorError {
|
|
25
|
+
readonly timeoutMs: number;
|
|
26
|
+
readonly name = "DeadlineExceededError";
|
|
27
|
+
constructor(timeoutMs: number);
|
|
28
|
+
}
|
|
29
|
+
export declare class ResourceDisposedError extends ConnectorError {
|
|
30
|
+
readonly resource: string;
|
|
31
|
+
readonly name = "ResourceDisposedError";
|
|
32
|
+
constructor(resource: string);
|
|
33
|
+
}
|
|
34
|
+
type InfrastructureErrorOptions = {
|
|
35
|
+
readonly operation: string;
|
|
36
|
+
readonly retryable: boolean;
|
|
37
|
+
readonly cause: unknown | null;
|
|
38
|
+
};
|
|
39
|
+
export declare class AdapterError extends ConnectorError {
|
|
40
|
+
readonly name = "AdapterError";
|
|
41
|
+
readonly operation: string;
|
|
42
|
+
readonly providerId: ProviderId | null;
|
|
43
|
+
constructor(options: InfrastructureErrorOptions & {
|
|
44
|
+
readonly providerId: ProviderId | null;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export declare class HttpTransportError extends ConnectorError {
|
|
48
|
+
readonly name = "HttpTransportError";
|
|
49
|
+
readonly operation: string;
|
|
50
|
+
constructor(options: InfrastructureErrorOptions);
|
|
51
|
+
}
|
|
52
|
+
export declare class ProcessSupervisorError extends ConnectorError {
|
|
53
|
+
readonly name = "ProcessSupervisorError";
|
|
54
|
+
readonly operation: string;
|
|
55
|
+
constructor(options: InfrastructureErrorOptions);
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export class ConnectorError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
retryable;
|
|
4
|
+
cause;
|
|
5
|
+
constructor(message, options) {
|
|
6
|
+
super(message, { cause: options.cause });
|
|
7
|
+
this.code = options.code;
|
|
8
|
+
this.retryable = options.retryable;
|
|
9
|
+
this.cause = options.cause;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class InvalidArgumentError extends ConnectorError {
|
|
13
|
+
argument;
|
|
14
|
+
name = "InvalidArgumentError";
|
|
15
|
+
constructor(argument, cause = null) {
|
|
16
|
+
super("invalid connector argument", { code: "invalid-argument", retryable: false, cause });
|
|
17
|
+
this.argument = argument;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class OperationCancelledError extends ConnectorError {
|
|
21
|
+
operation;
|
|
22
|
+
name = "OperationCancelledError";
|
|
23
|
+
constructor(operation) {
|
|
24
|
+
super("connector operation cancelled", {
|
|
25
|
+
code: "operation-cancelled",
|
|
26
|
+
retryable: false,
|
|
27
|
+
cause: null,
|
|
28
|
+
});
|
|
29
|
+
this.operation = operation;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class DeadlineExceededError extends ConnectorError {
|
|
33
|
+
timeoutMs;
|
|
34
|
+
name = "DeadlineExceededError";
|
|
35
|
+
constructor(timeoutMs) {
|
|
36
|
+
super("connector deadline exceeded", {
|
|
37
|
+
code: "deadline-exceeded",
|
|
38
|
+
retryable: true,
|
|
39
|
+
cause: null,
|
|
40
|
+
});
|
|
41
|
+
this.timeoutMs = timeoutMs;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class ResourceDisposedError extends ConnectorError {
|
|
45
|
+
resource;
|
|
46
|
+
name = "ResourceDisposedError";
|
|
47
|
+
constructor(resource) {
|
|
48
|
+
super("connector resource disposed", {
|
|
49
|
+
code: "resource-disposed",
|
|
50
|
+
retryable: false,
|
|
51
|
+
cause: null,
|
|
52
|
+
});
|
|
53
|
+
this.resource = resource;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class AdapterError extends ConnectorError {
|
|
57
|
+
name = "AdapterError";
|
|
58
|
+
operation;
|
|
59
|
+
providerId;
|
|
60
|
+
constructor(options) {
|
|
61
|
+
super("provider adapter failed", { code: "adapter-error", ...options });
|
|
62
|
+
this.operation = options.operation;
|
|
63
|
+
this.providerId = options.providerId;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class HttpTransportError extends ConnectorError {
|
|
67
|
+
name = "HttpTransportError";
|
|
68
|
+
operation;
|
|
69
|
+
constructor(options) {
|
|
70
|
+
super("HTTP transport failed", { code: "http-transport-error", ...options });
|
|
71
|
+
this.operation = options.operation;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export class ProcessSupervisorError extends ConnectorError {
|
|
75
|
+
name = "ProcessSupervisorError";
|
|
76
|
+
operation;
|
|
77
|
+
constructor(options) {
|
|
78
|
+
super("process supervisor failed", { code: "process-supervisor-error", ...options });
|
|
79
|
+
this.operation = options.operation;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type HealthPolicy = {
|
|
2
|
+
readonly initialBackoffMs: number;
|
|
3
|
+
readonly maximumBackoffMs: number;
|
|
4
|
+
};
|
|
5
|
+
export type HealthState = {
|
|
6
|
+
readonly status: "unknown" | "ready" | "stale" | "unavailable";
|
|
7
|
+
readonly consecutiveFailures: number;
|
|
8
|
+
readonly retryAtMs: number | null;
|
|
9
|
+
};
|
|
10
|
+
export type HealthEvent = {
|
|
11
|
+
readonly status: "ready";
|
|
12
|
+
readonly atMs: number;
|
|
13
|
+
} | {
|
|
14
|
+
readonly status: "stale";
|
|
15
|
+
readonly atMs: number;
|
|
16
|
+
} | {
|
|
17
|
+
readonly status: "unavailable";
|
|
18
|
+
readonly atMs: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function createInitialHealthState(): HealthState;
|
|
21
|
+
export declare function calculateBackoffMs(failures: number, policy: HealthPolicy): number;
|
|
22
|
+
export declare function reduceHealth(state: HealthState, event: HealthEvent, policy: HealthPolicy): HealthState;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function createInitialHealthState() {
|
|
2
|
+
return { status: "unknown", consecutiveFailures: 0, retryAtMs: null };
|
|
3
|
+
}
|
|
4
|
+
export function calculateBackoffMs(failures, policy) {
|
|
5
|
+
if (failures <= 0) {
|
|
6
|
+
return 0;
|
|
7
|
+
}
|
|
8
|
+
let delay = Math.min(policy.initialBackoffMs, policy.maximumBackoffMs);
|
|
9
|
+
let remainingFailures = failures - 1;
|
|
10
|
+
while (remainingFailures > 0 && delay < policy.maximumBackoffMs) {
|
|
11
|
+
delay = Math.min(delay * 2, policy.maximumBackoffMs);
|
|
12
|
+
remainingFailures -= 1;
|
|
13
|
+
}
|
|
14
|
+
return delay;
|
|
15
|
+
}
|
|
16
|
+
export function reduceHealth(state, event, policy) {
|
|
17
|
+
switch (event.status) {
|
|
18
|
+
case "ready":
|
|
19
|
+
return { status: "ready", consecutiveFailures: 0, retryAtMs: null };
|
|
20
|
+
case "stale":
|
|
21
|
+
case "unavailable": {
|
|
22
|
+
const consecutiveFailures = state.consecutiveFailures + 1;
|
|
23
|
+
return {
|
|
24
|
+
status: event.status,
|
|
25
|
+
consecutiveFailures,
|
|
26
|
+
retryAtMs: event.atMs + calculateBackoffMs(consecutiveFailures, policy),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
+
export type HttpHeaders = {
|
|
3
|
+
readonly [name: string]: string;
|
|
4
|
+
};
|
|
5
|
+
export type HttpRequest = {
|
|
6
|
+
readonly method: HttpMethod;
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly headers: HttpHeaders;
|
|
9
|
+
readonly body: Uint8Array | null;
|
|
10
|
+
};
|
|
11
|
+
export type HttpResponse = {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly statusText?: string;
|
|
14
|
+
readonly headers: HttpHeaders;
|
|
15
|
+
readonly body: Uint8Array;
|
|
16
|
+
readonly bodyPresent?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type HttpStreamResponse = {
|
|
19
|
+
readonly status: number;
|
|
20
|
+
readonly statusText?: string;
|
|
21
|
+
readonly headers: HttpHeaders;
|
|
22
|
+
readonly body: AsyncIterable<Uint8Array>;
|
|
23
|
+
readonly bodyPresent?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export interface HttpTransport {
|
|
26
|
+
request(request: HttpRequest, signal: AbortSignal): Promise<HttpResponse>;
|
|
27
|
+
stream?(request: HttpRequest, signal: AbortSignal): Promise<HttpStreamResponse>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ProviderIdSchema: z.core.$ZodBranded<z.ZodString, "ProviderId">;
|
|
3
|
+
export type ProviderId = z.output<typeof ProviderIdSchema>;
|
|
4
|
+
export declare const ModelIdSchema: z.core.$ZodBranded<z.ZodString, "ModelId">;
|
|
5
|
+
export type ModelId = z.output<typeof ModelIdSchema>;
|
|
6
|
+
export declare function parseProviderId(input: unknown): ProviderId;
|
|
7
|
+
export declare function parseModelId(input: unknown): ModelId;
|
package/dist/core/ids.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const ProviderIdSchema = z
|
|
3
|
+
.string()
|
|
4
|
+
.min(1)
|
|
5
|
+
.max(64)
|
|
6
|
+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
|
|
7
|
+
.brand();
|
|
8
|
+
export const ModelIdSchema = z
|
|
9
|
+
.string()
|
|
10
|
+
.min(1)
|
|
11
|
+
.max(256)
|
|
12
|
+
.refine((value) => [...value].every((character) => {
|
|
13
|
+
const codePoint = character.codePointAt(0);
|
|
14
|
+
return codePoint !== undefined && codePoint >= 32 && codePoint !== 127;
|
|
15
|
+
}))
|
|
16
|
+
.refine((value) => value.trim() === value)
|
|
17
|
+
.brand();
|
|
18
|
+
export function parseProviderId(input) {
|
|
19
|
+
return ProviderIdSchema.parse(input);
|
|
20
|
+
}
|
|
21
|
+
export function parseModelId(input) {
|
|
22
|
+
return ModelIdSchema.parse(input);
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function createAsyncDisposable(cleanup) {
|
|
2
|
+
let disposal;
|
|
3
|
+
const dispose = () => {
|
|
4
|
+
if (disposal !== undefined) {
|
|
5
|
+
return disposal;
|
|
6
|
+
}
|
|
7
|
+
const deferred = Promise.withResolvers();
|
|
8
|
+
disposal = deferred.promise;
|
|
9
|
+
Promise.resolve().then(cleanup).then(deferred.resolve, deferred.reject);
|
|
10
|
+
return disposal;
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
dispose,
|
|
14
|
+
[Symbol.asyncDispose]: dispose,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Clock } from "./clock";
|
|
2
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
3
|
+
export type LogValue = null | boolean | number | string | readonly LogValue[] | {
|
|
4
|
+
readonly [key: string]: LogValue;
|
|
5
|
+
};
|
|
6
|
+
export type LogFields = {
|
|
7
|
+
readonly [key: string]: LogValue;
|
|
8
|
+
};
|
|
9
|
+
export type LogRecord = {
|
|
10
|
+
readonly timestampMs: number;
|
|
11
|
+
readonly level: LogLevel;
|
|
12
|
+
readonly event: string;
|
|
13
|
+
readonly fields: LogFields;
|
|
14
|
+
};
|
|
15
|
+
export interface LogSink {
|
|
16
|
+
write(record: LogRecord): void;
|
|
17
|
+
}
|
|
18
|
+
export interface ConnectorLogger {
|
|
19
|
+
log(level: LogLevel, event: string, fields: LogFields): void;
|
|
20
|
+
}
|
|
21
|
+
export declare function createConnectorLogger(clock: Clock, sink: LogSink): ConnectorLogger;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const REDACTED = "[REDACTED]";
|
|
2
|
+
const SENSITIVE_KEYS = new Set([
|
|
3
|
+
"authorization",
|
|
4
|
+
"cookie",
|
|
5
|
+
"setcookie",
|
|
6
|
+
"token",
|
|
7
|
+
"accesstoken",
|
|
8
|
+
"refreshtoken",
|
|
9
|
+
"access",
|
|
10
|
+
"refresh",
|
|
11
|
+
"expires",
|
|
12
|
+
"apikey",
|
|
13
|
+
"password",
|
|
14
|
+
"secret",
|
|
15
|
+
]);
|
|
16
|
+
function isLogArray(value) {
|
|
17
|
+
return Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
function sanitizeUrl(value) {
|
|
20
|
+
if (!URL.canParse(value)) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
const url = new URL(value);
|
|
24
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
if (url.username.length > 0)
|
|
28
|
+
url.username = REDACTED;
|
|
29
|
+
if (url.password.length > 0)
|
|
30
|
+
url.password = REDACTED;
|
|
31
|
+
const queryNames = [...url.searchParams.keys()];
|
|
32
|
+
if (queryNames.length > 0) {
|
|
33
|
+
url.search = "";
|
|
34
|
+
for (const name of queryNames)
|
|
35
|
+
url.searchParams.append(name, REDACTED);
|
|
36
|
+
}
|
|
37
|
+
return url.toString();
|
|
38
|
+
}
|
|
39
|
+
function sanitizeValue(value) {
|
|
40
|
+
if (typeof value === "string") {
|
|
41
|
+
return sanitizeUrl(value);
|
|
42
|
+
}
|
|
43
|
+
if (value === null || typeof value !== "object") {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
if (isLogArray(value)) {
|
|
47
|
+
return value.map(sanitizeValue);
|
|
48
|
+
}
|
|
49
|
+
return sanitizeFields(value);
|
|
50
|
+
}
|
|
51
|
+
function sanitizeFields(fields) {
|
|
52
|
+
return Object.fromEntries(Object.entries(fields).map(([key, value]) => {
|
|
53
|
+
const normalizedKey = key.toLowerCase().replaceAll("-", "").replaceAll("_", "");
|
|
54
|
+
return [key, SENSITIVE_KEYS.has(normalizedKey) ? REDACTED : sanitizeValue(value)];
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
export function createConnectorLogger(clock, sink) {
|
|
58
|
+
return {
|
|
59
|
+
log: (level, event, fields) => sink.write({ timestampMs: clock.nowMs(), level, event, fields: sanitizeFields(fields) }),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ModelId, ProviderId } from "./ids";
|
|
3
|
+
export type AdapterModelInput = {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
};
|
|
6
|
+
export type AdapterModel = {
|
|
7
|
+
readonly id: ModelId;
|
|
8
|
+
};
|
|
9
|
+
export type ProviderFailureReason = "adapter-error" | "transport-error" | "process-error" | "invalid-data";
|
|
10
|
+
export type ProviderSnapshotInput = {
|
|
11
|
+
readonly status: "ready";
|
|
12
|
+
readonly providerId: string;
|
|
13
|
+
readonly models: readonly AdapterModelInput[];
|
|
14
|
+
} | {
|
|
15
|
+
readonly status: "stale";
|
|
16
|
+
readonly providerId: string;
|
|
17
|
+
readonly models: readonly AdapterModelInput[];
|
|
18
|
+
readonly reason: ProviderFailureReason;
|
|
19
|
+
} | {
|
|
20
|
+
readonly status: "unavailable";
|
|
21
|
+
readonly providerId: string;
|
|
22
|
+
readonly reason: ProviderFailureReason;
|
|
23
|
+
};
|
|
24
|
+
export type ProviderSnapshot = {
|
|
25
|
+
readonly status: "ready";
|
|
26
|
+
readonly providerId: ProviderId;
|
|
27
|
+
readonly models: readonly AdapterModel[];
|
|
28
|
+
} | {
|
|
29
|
+
readonly status: "stale";
|
|
30
|
+
readonly providerId: ProviderId;
|
|
31
|
+
readonly models: readonly AdapterModel[];
|
|
32
|
+
readonly reason: ProviderFailureReason;
|
|
33
|
+
} | {
|
|
34
|
+
readonly status: "unavailable";
|
|
35
|
+
readonly providerId: ProviderId;
|
|
36
|
+
readonly reason: ProviderFailureReason;
|
|
37
|
+
};
|
|
38
|
+
export declare const AdapterModelSchema: z.ZodType<AdapterModel, AdapterModelInput>;
|
|
39
|
+
export declare const ProviderSnapshotSchema: z.ZodType<ProviderSnapshot, ProviderSnapshotInput>;
|
|
40
|
+
export declare function parseAdapterModel(input: unknown): AdapterModel;
|
|
41
|
+
export declare function parseProviderSnapshot(input: unknown): ProviderSnapshot;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ModelIdSchema, ProviderIdSchema } from "./ids";
|
|
3
|
+
export const AdapterModelSchema = z
|
|
4
|
+
.object({ id: ModelIdSchema })
|
|
5
|
+
.strict()
|
|
6
|
+
.readonly();
|
|
7
|
+
const ProviderFailureReasonSchema = z.union([
|
|
8
|
+
z.literal("adapter-error"),
|
|
9
|
+
z.literal("transport-error"),
|
|
10
|
+
z.literal("process-error"),
|
|
11
|
+
z.literal("invalid-data"),
|
|
12
|
+
]);
|
|
13
|
+
const AdapterModelsSchema = z
|
|
14
|
+
.array(AdapterModelSchema)
|
|
15
|
+
.superRefine((models, context) => {
|
|
16
|
+
const ids = new Set();
|
|
17
|
+
for (const model of models) {
|
|
18
|
+
if (ids.has(model.id)) {
|
|
19
|
+
context.addIssue({ code: "custom", message: "duplicate model ID" });
|
|
20
|
+
}
|
|
21
|
+
ids.add(model.id);
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.readonly();
|
|
25
|
+
export const ProviderSnapshotSchema = z
|
|
26
|
+
.discriminatedUnion("status", [
|
|
27
|
+
z
|
|
28
|
+
.object({
|
|
29
|
+
status: z.literal("ready"),
|
|
30
|
+
providerId: ProviderIdSchema,
|
|
31
|
+
models: AdapterModelsSchema,
|
|
32
|
+
})
|
|
33
|
+
.strict()
|
|
34
|
+
.readonly(),
|
|
35
|
+
z
|
|
36
|
+
.object({
|
|
37
|
+
status: z.literal("stale"),
|
|
38
|
+
providerId: ProviderIdSchema,
|
|
39
|
+
models: AdapterModelsSchema,
|
|
40
|
+
reason: ProviderFailureReasonSchema,
|
|
41
|
+
})
|
|
42
|
+
.strict()
|
|
43
|
+
.readonly(),
|
|
44
|
+
z
|
|
45
|
+
.object({
|
|
46
|
+
status: z.literal("unavailable"),
|
|
47
|
+
providerId: ProviderIdSchema,
|
|
48
|
+
reason: ProviderFailureReasonSchema,
|
|
49
|
+
})
|
|
50
|
+
.strict()
|
|
51
|
+
.readonly(),
|
|
52
|
+
])
|
|
53
|
+
.readonly();
|
|
54
|
+
export function parseAdapterModel(input) {
|
|
55
|
+
return AdapterModelSchema.parse(input);
|
|
56
|
+
}
|
|
57
|
+
export function parseProviderSnapshot(input) {
|
|
58
|
+
return ProviderSnapshotSchema.parse(input);
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { HealthPolicy } from "./health";
|
|
3
|
+
export type CredentialRefreshMode = "auto" | "never";
|
|
4
|
+
export type CredentialRefreshPolicy = {
|
|
5
|
+
readonly mode: CredentialRefreshMode;
|
|
6
|
+
readonly leadMs: number;
|
|
7
|
+
};
|
|
8
|
+
export type ConnectorOptionsInput = {
|
|
9
|
+
readonly providers?: readonly ("claude" | "cursor" | "command-code" | "ollama")[] | undefined;
|
|
10
|
+
readonly snapshotTimeoutMs?: number | undefined;
|
|
11
|
+
readonly writeBackCredentials?: boolean | undefined;
|
|
12
|
+
readonly credentialRefresh?: {
|
|
13
|
+
readonly mode?: CredentialRefreshMode | undefined;
|
|
14
|
+
readonly leadMs?: number | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
readonly catalogReloadMs?: number | undefined;
|
|
17
|
+
readonly health?: {
|
|
18
|
+
readonly initialBackoffMs?: number | undefined;
|
|
19
|
+
readonly maximumBackoffMs?: number | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
};
|
|
22
|
+
export type ConnectorOptions = {
|
|
23
|
+
readonly providers: readonly ("claude" | "cursor" | "command-code" | "ollama")[];
|
|
24
|
+
readonly snapshotTimeoutMs: number;
|
|
25
|
+
readonly writeBackCredentials: boolean;
|
|
26
|
+
readonly credentialRefresh: CredentialRefreshPolicy;
|
|
27
|
+
readonly catalogReloadMs: number;
|
|
28
|
+
readonly health: HealthPolicy;
|
|
29
|
+
};
|
|
30
|
+
export declare const ConnectorOptionsSchema: z.ZodType<ConnectorOptions, ConnectorOptionsInput>;
|
|
31
|
+
export declare function parseConnectorOptions(input: unknown): ConnectorOptions;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const MaximumTimerMs = 2_147_483_647;
|
|
3
|
+
const PositiveSafeIntegerSchema = z.number().int().positive().max(MaximumTimerMs);
|
|
4
|
+
const NonNegativeSafeIntegerSchema = z.number().int().nonnegative().max(MaximumTimerMs);
|
|
5
|
+
const ProviderSchema = z.enum(["claude", "cursor", "command-code", "ollama"]);
|
|
6
|
+
const CredentialRefreshModeSchema = z.enum(["auto", "never"]);
|
|
7
|
+
const DefaultProviders = [
|
|
8
|
+
"claude",
|
|
9
|
+
"cursor",
|
|
10
|
+
"command-code",
|
|
11
|
+
"ollama",
|
|
12
|
+
];
|
|
13
|
+
const ConnectorOptionsInputSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
providers: z.array(ProviderSchema).optional(),
|
|
16
|
+
snapshotTimeoutMs: PositiveSafeIntegerSchema.optional(),
|
|
17
|
+
writeBackCredentials: z.boolean().optional(),
|
|
18
|
+
credentialRefresh: z
|
|
19
|
+
.object({
|
|
20
|
+
mode: CredentialRefreshModeSchema.optional(),
|
|
21
|
+
leadMs: NonNegativeSafeIntegerSchema.optional(),
|
|
22
|
+
})
|
|
23
|
+
.strict()
|
|
24
|
+
.optional(),
|
|
25
|
+
catalogReloadMs: NonNegativeSafeIntegerSchema.optional(),
|
|
26
|
+
health: z
|
|
27
|
+
.object({
|
|
28
|
+
initialBackoffMs: PositiveSafeIntegerSchema.optional(),
|
|
29
|
+
maximumBackoffMs: PositiveSafeIntegerSchema.optional(),
|
|
30
|
+
})
|
|
31
|
+
.strict()
|
|
32
|
+
.optional(),
|
|
33
|
+
})
|
|
34
|
+
.strict()
|
|
35
|
+
.superRefine((input, context) => {
|
|
36
|
+
const initialBackoffMs = input.health?.initialBackoffMs ?? 1_000;
|
|
37
|
+
const maximumBackoffMs = input.health?.maximumBackoffMs ?? 60_000;
|
|
38
|
+
if (initialBackoffMs > maximumBackoffMs) {
|
|
39
|
+
context.addIssue({ code: "custom", message: "initial backoff exceeds maximum" });
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
export const ConnectorOptionsSchema = ConnectorOptionsInputSchema.transform((input) => {
|
|
43
|
+
const health = Object.freeze({
|
|
44
|
+
initialBackoffMs: input.health?.initialBackoffMs ?? 1_000,
|
|
45
|
+
maximumBackoffMs: input.health?.maximumBackoffMs ?? 60_000,
|
|
46
|
+
});
|
|
47
|
+
const credentialRefresh = Object.freeze({
|
|
48
|
+
mode: input.credentialRefresh?.mode ?? "auto",
|
|
49
|
+
leadMs: input.credentialRefresh?.leadMs ?? 60_000,
|
|
50
|
+
});
|
|
51
|
+
return Object.freeze({
|
|
52
|
+
providers: Object.freeze(input.providers ?? DefaultProviders),
|
|
53
|
+
snapshotTimeoutMs: input.snapshotTimeoutMs ?? 30_000,
|
|
54
|
+
writeBackCredentials: input.writeBackCredentials ?? false,
|
|
55
|
+
credentialRefresh,
|
|
56
|
+
catalogReloadMs: input.catalogReloadMs ?? 300_000,
|
|
57
|
+
health,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
export function parseConnectorOptions(input) {
|
|
61
|
+
return ConnectorOptionsSchema.parse(input);
|
|
62
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AsyncDisposableHandle } from "./lifecycle";
|
|
2
|
+
export type ProcessCommand = {
|
|
3
|
+
readonly executable: string;
|
|
4
|
+
readonly arguments: readonly string[];
|
|
5
|
+
readonly cwd: string | null;
|
|
6
|
+
};
|
|
7
|
+
export type ProcessExit = {
|
|
8
|
+
readonly kind: "code";
|
|
9
|
+
readonly code: number;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "signal";
|
|
12
|
+
readonly signal: string;
|
|
13
|
+
};
|
|
14
|
+
export interface SupervisedProcess extends AsyncDisposableHandle {
|
|
15
|
+
wait(signal: AbortSignal): Promise<ProcessExit>;
|
|
16
|
+
terminate(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface ProcessSupervisor extends AsyncDisposableHandle {
|
|
19
|
+
start(command: ProcessCommand, signal: AbortSignal): Promise<SupervisedProcess>;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export function createFetchHttpTransport() {
|
|
2
|
+
return {
|
|
3
|
+
request: async (request, signal) => {
|
|
4
|
+
const response = await fetch(request.url, {
|
|
5
|
+
method: request.method,
|
|
6
|
+
headers: request.headers,
|
|
7
|
+
body: request.body,
|
|
8
|
+
signal,
|
|
9
|
+
});
|
|
10
|
+
const headers = {};
|
|
11
|
+
response.headers.forEach((value, name) => {
|
|
12
|
+
headers[name] = value;
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
status: response.status,
|
|
16
|
+
statusText: response.statusText,
|
|
17
|
+
headers,
|
|
18
|
+
body: new Uint8Array(await response.arrayBuffer()),
|
|
19
|
+
bodyPresent: response.body !== null,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
stream: async (request, signal) => {
|
|
23
|
+
const response = await fetch(request.url, {
|
|
24
|
+
method: request.method,
|
|
25
|
+
headers: request.headers,
|
|
26
|
+
body: request.body,
|
|
27
|
+
signal,
|
|
28
|
+
});
|
|
29
|
+
const headers = {};
|
|
30
|
+
response.headers.forEach((value, name) => {
|
|
31
|
+
headers[name] = value;
|
|
32
|
+
});
|
|
33
|
+
const body = response.body;
|
|
34
|
+
if (body === null) {
|
|
35
|
+
return {
|
|
36
|
+
status: response.status,
|
|
37
|
+
statusText: response.statusText,
|
|
38
|
+
headers,
|
|
39
|
+
body: (async function* () { })(),
|
|
40
|
+
bodyPresent: false,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const reader = body.getReader();
|
|
44
|
+
const streamBody = (async function* () {
|
|
45
|
+
let completed = false;
|
|
46
|
+
try {
|
|
47
|
+
while (true) {
|
|
48
|
+
if (signal.aborted) {
|
|
49
|
+
throw new DOMException("Aborted", "AbortError");
|
|
50
|
+
}
|
|
51
|
+
const { done, value } = await reader.read();
|
|
52
|
+
if (done) {
|
|
53
|
+
completed = true;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
yield value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
if (!completed) {
|
|
61
|
+
await reader.cancel();
|
|
62
|
+
}
|
|
63
|
+
reader.releaseLock();
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
return {
|
|
67
|
+
status: response.status,
|
|
68
|
+
statusText: response.statusText,
|
|
69
|
+
headers,
|
|
70
|
+
body: streamBody,
|
|
71
|
+
bodyPresent: true,
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HttpTransport } from "../core/http";
|
|
2
|
+
export type PackageVersionResolver = (signal: AbortSignal) => Promise<string | null>;
|
|
3
|
+
export type PackageVersionResolverOptions = {
|
|
4
|
+
readonly transport: HttpTransport;
|
|
5
|
+
readonly packageName: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function createPackageVersionResolver(options: PackageVersionResolverOptions): PackageVersionResolver;
|