@superdurable/connectors-sdk 0.1.1 → 0.2.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/README.md +26 -2
- package/dist/{chunk-2NBM7P4T.js → chunk-32YJXBE4.js} +1 -1
- package/dist/chunk-466BPS3M.js +336 -0
- package/dist/{chunk-2IDXFKMY.js → chunk-BG65RPGH.js} +62 -10
- package/dist/{chunk-SOXYPIMO.js → chunk-BQGYGCOQ.js} +35 -73
- package/dist/chunk-IHG6ADQG.js +44 -0
- package/dist/chunk-NQQJS6OC.js +316 -0
- package/dist/{chunk-KD5DYYSU.js → chunk-QDMBAWXD.js} +1 -1
- package/dist/connectormock/index.d.ts +3 -2
- package/dist/connectormock/index.js +5 -3
- package/dist/credentials-JqG97kJ5.d.ts +102 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +19 -291
- package/dist/oauthtoken/index.d.ts +36 -2
- package/dist/oauthtoken/index.js +326 -5
- package/dist/{operation-Ca8rfacf.d.ts → operation-CASLOg86.d.ts} +2 -1
- package/dist/projectconfig/index.d.ts +2 -1
- package/dist/projectconfig/index.js +5 -3
- package/dist/providerhttp/index.d.ts +20 -3
- package/dist/providerhttp/index.js +3 -1
- package/dist/query-CeUaW9xU.d.ts +42 -0
- package/dist/singledispatch/index.d.ts +2 -1
- package/dist/singledispatch/index.js +2 -1
- package/dist/textgen/index.d.ts +15 -0
- package/dist/textgen/index.js +628 -0
- package/dist/textgen/openaichat/index.d.ts +44 -0
- package/dist/textgen/openaichat/index.js +232 -0
- package/dist/textgen/textgentest/index.d.ts +106 -0
- package/dist/textgen/textgentest/index.js +537 -0
- package/dist/{credentials-vrvW0d4j.d.ts → types-D6De3sry.d.ts} +1 -100
- package/dist/wire_format-stEVruMs.d.ts +190 -0
- package/package.json +14 -2
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { e as BranchDefinition, F as Failure, q as FailureKind } from './types-D6De3sry.js';
|
|
2
|
+
|
|
3
|
+
/** Conversation author accepted by portable text generation. */
|
|
4
|
+
type MessageRole = 'user' | 'assistant';
|
|
5
|
+
/** One text-only conversation turn. */
|
|
6
|
+
interface Message {
|
|
7
|
+
role: MessageRole; /** Nonempty text. */
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
/** One portable JSON object schema, validated before dispatch. */
|
|
11
|
+
interface StructuredOutput {
|
|
12
|
+
name: string; /** Optional model guidance. */
|
|
13
|
+
description?: string; /** Portable JSON Schema object. */
|
|
14
|
+
schema: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/** Portable reasoning effort; model rules determine which values are accepted. */
|
|
17
|
+
type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
18
|
+
/** Provider-neutral generateText input. Zero token limit uses provider default. */
|
|
19
|
+
interface TextGenerationRequest {
|
|
20
|
+
/** Optional model override; whitespace is trimmed. */ model?: string;
|
|
21
|
+
/** System or developer instructions. */ instructions?: string;
|
|
22
|
+
/** Ordered nonempty conversation. */ messages: Message[];
|
|
23
|
+
/** Optional JSON object output contract. */ structuredOutput?: StructuredOutput;
|
|
24
|
+
/** Maximum generated tokens, including reasoning tokens where counted. */ maxOutputTokens?: number;
|
|
25
|
+
/** Sampling temperature; absence preserves the provider default. */ temperature?: number;
|
|
26
|
+
/** Optional model reasoning effort. */ reasoningEffort?: ReasoningEffort;
|
|
27
|
+
}
|
|
28
|
+
/** Provider-neutral terminal finish classification. */
|
|
29
|
+
type FinishReason = 'stop' | 'length' | 'contentPolicy' | 'refusal';
|
|
30
|
+
/** Token counts reported by the provider; absent counts are zero. */
|
|
31
|
+
interface Usage {
|
|
32
|
+
/** Prompt tokens. */ inputTokens: number;
|
|
33
|
+
/** Cached prompt subset. */ cachedInputTokens: number;
|
|
34
|
+
/** Generated tokens. */ outputTokens: number;
|
|
35
|
+
/** Reasoning subset. */ reasoningTokens: number;
|
|
36
|
+
/** Billed total. */ totalTokens: number;
|
|
37
|
+
}
|
|
38
|
+
/** Provider-neutral generateText result; only generated and truncated carry text. */
|
|
39
|
+
interface TextGenerationResponse {
|
|
40
|
+
/** Non-reasoning text. */ text: string;
|
|
41
|
+
/** Validated model sent on the request. */ requestedModel: string;
|
|
42
|
+
/** Provider-reported model, if any. */ servedModel: string;
|
|
43
|
+
/** Provider response identifier, if any. */ responseId: string;
|
|
44
|
+
/** Normalized stop reason, if known. */ finishReason: FinishReason | '';
|
|
45
|
+
/** Safe provider stop token, if known. */ providerFinishReason: string;
|
|
46
|
+
/** Reported usage. */ usage: Usage;
|
|
47
|
+
}
|
|
48
|
+
/** Stable operation identity shared by LLM providers. */
|
|
49
|
+
declare const TextGenerationOperationID = "generateText";
|
|
50
|
+
/** Required normal completion route. */ declare const GeneratedBranchID = "generated";
|
|
51
|
+
/** Partial output at the token limit. */ declare const TruncatedBranchID = "truncated";
|
|
52
|
+
/** Refusal or content policy stop. */ declare const BlockedBranchID = "blocked";
|
|
53
|
+
/** Conclusive provider rejection. */ declare const ProviderRejectedBranchID = "providerRejected";
|
|
54
|
+
/** Malformed or unusable response. */ declare const InvalidResponseBranchID = "invalidResponse";
|
|
55
|
+
/** Invalid local request or connector definition. */ declare const DefectBranchID = "defect";
|
|
56
|
+
/** Return fresh provider-neutral branches in manifest order. */
|
|
57
|
+
declare function textGenerationBranchDefinitions(): BranchDefinition[];
|
|
58
|
+
/** Return a validation failure shared by all providers, without echoing input. */
|
|
59
|
+
declare function validatePortableRequest(request: TextGenerationRequest): Failure | undefined;
|
|
60
|
+
/** Select request model before the configured model, trimming surrounding whitespace. */
|
|
61
|
+
declare function resolveModel(requestModel: string, connectionModel: string): string;
|
|
62
|
+
/** Model placement determines safe model ID syntax. */
|
|
63
|
+
type ModelIDRule = 'body' | 'pathSegment';
|
|
64
|
+
/** Validate and canonicalize a model ID without including it in errors. */
|
|
65
|
+
declare function validateModelID(rule: ModelIDRule, value: string): string;
|
|
66
|
+
|
|
67
|
+
/** Optional portable fields the wire format actually sends. */
|
|
68
|
+
interface RequestFeatures {
|
|
69
|
+
/** Instructions. */ supportsInstructions?: boolean;
|
|
70
|
+
/** Structured output. */ supportsStructuredOutput?: boolean;
|
|
71
|
+
/** Token cap. */ supportsMaxOutputTokens?: boolean;
|
|
72
|
+
/** Temperature. */ supportsTemperature?: boolean;
|
|
73
|
+
/** Reasoning. */ supportsReasoningEffort?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** Credential header and safe public prefix. */
|
|
76
|
+
interface CredentialHeader {
|
|
77
|
+
name: string; /** Public prefix before the secret. */
|
|
78
|
+
prefix: string;
|
|
79
|
+
}
|
|
80
|
+
/** Model sampling policy; accepted is the zero behavior. */
|
|
81
|
+
type TemperaturePolicy = {
|
|
82
|
+
kind: 'accepted';
|
|
83
|
+
} | {
|
|
84
|
+
kind: 'range';
|
|
85
|
+
minimum: number;
|
|
86
|
+
maximum: number;
|
|
87
|
+
} | {
|
|
88
|
+
kind: 'notAccepted';
|
|
89
|
+
};
|
|
90
|
+
/** Accept finite nonnegative temperatures. */ declare function temperatureAccepted(): TemperaturePolicy;
|
|
91
|
+
/** Accept one inclusive temperature range. */ declare function temperatureRange(minimum: number, maximum: number): TemperaturePolicy;
|
|
92
|
+
/** Reject temperature for fixed-sampling models. */ declare function temperatureNotAccepted(): TemperaturePolicy;
|
|
93
|
+
/** How the provider receives structured output. */
|
|
94
|
+
type StructuredOutputMode = 'none' | 'jsonSchema' | 'jsonObjectWithInstruction';
|
|
95
|
+
/** Per-model structured-output transforms; local validation retains original constraints. */
|
|
96
|
+
interface StructuredOutputRules {
|
|
97
|
+
/** Provider request mode. */ mode: StructuredOutputMode;
|
|
98
|
+
/** Constraints moved into descriptions. */ keywordsMovedToDescription?: string[];
|
|
99
|
+
/** Constraints omitted on the wire. */ keywordsRemoved?: string[];
|
|
100
|
+
}
|
|
101
|
+
/** Validate portable schema transform declarations. */
|
|
102
|
+
declare function validateStructuredOutputRules(rules: StructuredOutputRules): void;
|
|
103
|
+
/** Sampling, reasoning, and structured-output rules for one model. */
|
|
104
|
+
interface ModelRequestRules {
|
|
105
|
+
/** Temperature policy. */ temperature: TemperaturePolicy;
|
|
106
|
+
/** Accepted effort to wire value. */ reasoningEfforts: Partial<Record<ReasoningEffort, string>>;
|
|
107
|
+
/** Schema mode and transforms. */ structuredOutput: StructuredOutputRules;
|
|
108
|
+
}
|
|
109
|
+
/** Validated request and selected model rules passed to an encoder. */
|
|
110
|
+
interface EncodeRequestInput {
|
|
111
|
+
request: TextGenerationRequest; /** Selected model rules. */
|
|
112
|
+
rules: ModelRequestRules;
|
|
113
|
+
}
|
|
114
|
+
/** One provider HTTP request without its credential. */
|
|
115
|
+
interface EncodedRequest {
|
|
116
|
+
/** Path including leading slash. */ path: string;
|
|
117
|
+
/** JSON request bytes. */ body: Uint8Array;
|
|
118
|
+
/** Extra safe headers. */ headers?: Record<string, string>;
|
|
119
|
+
/** Whether event-stream is requested. */ isStreaming: boolean;
|
|
120
|
+
}
|
|
121
|
+
/** One decoded text or reasoning segment. */ interface ResponsePart {
|
|
122
|
+
text: string; /** True for hidden reasoning. */
|
|
123
|
+
isReasoning?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/** Provider response decoded to the portable shape. */
|
|
126
|
+
interface DecodedResponse {
|
|
127
|
+
/** Ordered output segments. */ parts: ResponsePart[];
|
|
128
|
+
/** Model echo. */ servedModel?: string;
|
|
129
|
+
/** Response identity. */ responseId?: string;
|
|
130
|
+
/** Provider finish token. */ providerFinishReason?: string;
|
|
131
|
+
/** Model refusal. */ isRefusal?: boolean;
|
|
132
|
+
/** Usage. */ usage?: Partial<Usage>;
|
|
133
|
+
}
|
|
134
|
+
/** A complete server-sent event. */ interface ServerSentEvent {
|
|
135
|
+
data: string; /** Optional event type. */
|
|
136
|
+
event?: string;
|
|
137
|
+
}
|
|
138
|
+
/** Adapter for one provider's request and response dialect. Functions must be concurrency safe. */
|
|
139
|
+
interface WireFormat {
|
|
140
|
+
/** Provider identity in failures and receipts. */ providerName: string;
|
|
141
|
+
/** Model ID validation based on its wire placement. */ modelIDRule: ModelIDRule;
|
|
142
|
+
/** Optional request fields actually transmitted. */ features: RequestFeatures;
|
|
143
|
+
/** Sole credential location. */ credentialHeader: CredentialHeader;
|
|
144
|
+
/** Return per-model rules once after model validation. */ rulesForModel(model: string): ModelRequestRules;
|
|
145
|
+
/** Encode only a validated request. */ encodeRequest(input: EncodeRequestInput): EncodedRequest;
|
|
146
|
+
/** Decode a complete 2xx JSON body. */ decodeResponse?: (body: Uint8Array) => DecodedResponse;
|
|
147
|
+
/** Decode one event and update state. Set hasFinished for a finish token and isDone for a terminal event; throw ProviderReportedError for embedded errors. */
|
|
148
|
+
decodeStreamEvent?: (event: ServerSentEvent, state: StreamDecodeState, writeTextDelta: (delta: string) => void) => void;
|
|
149
|
+
/** Accepted provider token to normalized finish reason. */ finishReasons: Record<string, FinishReason>;
|
|
150
|
+
/** Ordered provider-specific error rules. */ errorRules?: ErrorRule[];
|
|
151
|
+
/** JSON pointers for safe error tokens. */ errorTokenPointers?: string[];
|
|
152
|
+
/** Optional provider-specific retry delay reader in milliseconds; thrown or non-finite values defer to Retry-After. */ readErrorRetryDelay?: (body: Uint8Array) => number;
|
|
153
|
+
/** Response header preference for request ID. */ requestIDHeaders?: string[];
|
|
154
|
+
/** Whitelisted receipt metadata headers. */ rateLimitHeaders?: string[];
|
|
155
|
+
/** No-byte timeout in milliseconds; zero disables it. */ stallTimeoutMs?: number;
|
|
156
|
+
}
|
|
157
|
+
/** Mutable state for a single event stream, owned by the pipeline. */
|
|
158
|
+
interface StreamDecodeState {
|
|
159
|
+
response: DecodedResponse; /** A finish token has arrived. */
|
|
160
|
+
hasFinished: boolean; /** Terminal DONE event arrived. */
|
|
161
|
+
isDone: boolean;
|
|
162
|
+
}
|
|
163
|
+
/** One classified provider error rule. */
|
|
164
|
+
interface ErrorRule {
|
|
165
|
+
statusCode: number; /** Optional exact safe token. */
|
|
166
|
+
errorToken?: string; /** Chosen outcome. */
|
|
167
|
+
outcome: ErrorOutcome;
|
|
168
|
+
}
|
|
169
|
+
/** Terminal or retry disposition and failure kind. */
|
|
170
|
+
interface ErrorOutcome {
|
|
171
|
+
disposition: 'retry' | 'providerRejected' | 'invalidResponse' | 'blocked'; /** Provider-neutral failure category. */
|
|
172
|
+
kind: FailureKind;
|
|
173
|
+
}
|
|
174
|
+
/** Retry a safely repeatable query. */ declare function retryOutcome(kind: FailureKind): ErrorOutcome;
|
|
175
|
+
/** Select conclusive provider rejection. */ declare function providerRejectedOutcome(kind: FailureKind): ErrorOutcome;
|
|
176
|
+
/** Select exhausted spend or credit. */ declare function quotaExhaustedOutcome(): ErrorOutcome;
|
|
177
|
+
/** Select a content policy block. */ declare function blockedOutcome(): ErrorOutcome;
|
|
178
|
+
/** Select a provider contract violation. */ declare function invalidResponseOutcome(): ErrorOutcome;
|
|
179
|
+
/** Provider error embedded in a 2xx response or stream. Tokens alone may reach a failure. */
|
|
180
|
+
declare class ProviderReportedError extends Error {
|
|
181
|
+
/** Bounded machine-readable tokens. */ readonly errorTokens: string[];
|
|
182
|
+
/** Construct without exposing provider message text. */
|
|
183
|
+
constructor(errorTokens: string[]);
|
|
184
|
+
}
|
|
185
|
+
/** Classify non-2xx or embedded errors using first matching rule and Go defaults. */
|
|
186
|
+
declare function classifyError(rules: readonly ErrorRule[], statusCode: number, tokens: readonly string[], isReported?: boolean): ErrorOutcome;
|
|
187
|
+
/** Reject unsafe or incomplete provider declarations before any call. */
|
|
188
|
+
declare function validateWireFormat(format: WireFormat): void;
|
|
189
|
+
|
|
190
|
+
export { temperatureNotAccepted as A, BlockedBranchID as B, type CredentialHeader as C, type DecodedResponse as D, type EncodeRequestInput as E, type FinishReason as F, GeneratedBranchID as G, temperatureRange as H, InvalidResponseBranchID as I, textGenerationBranchDefinitions as J, validateModelID as K, validatePortableRequest as L, type Message as M, validateStructuredOutputRules as N, validateWireFormat as O, ProviderRejectedBranchID as P, type ReasoningEffort as R, type ServerSentEvent as S, type TextGenerationRequest as T, type Usage as U, type WireFormat as W, DefectBranchID as a, type EncodedRequest as b, type ErrorOutcome as c, type ErrorRule as d, type MessageRole as e, type ModelIDRule as f, type ModelRequestRules as g, ProviderReportedError as h, type RequestFeatures as i, type ResponsePart as j, type StreamDecodeState as k, type StructuredOutput as l, type StructuredOutputMode as m, type StructuredOutputRules as n, type TemperaturePolicy as o, TextGenerationOperationID as p, type TextGenerationResponse as q, TruncatedBranchID as r, blockedOutcome as s, classifyError as t, invalidResponseOutcome as u, providerRejectedOutcome as v, quotaExhaustedOutcome as w, resolveModel as x, retryOutcome as y, temperatureAccepted as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connectors-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Provider-neutral TypeScript contracts for Dex connectors",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -41,6 +41,18 @@
|
|
|
41
41
|
"./singledispatch": {
|
|
42
42
|
"types": "./dist/singledispatch/index.d.ts",
|
|
43
43
|
"import": "./dist/singledispatch/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./textgen": {
|
|
46
|
+
"types": "./dist/textgen/index.d.ts",
|
|
47
|
+
"import": "./dist/textgen/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./textgen/openaichat": {
|
|
50
|
+
"types": "./dist/textgen/openaichat/index.d.ts",
|
|
51
|
+
"import": "./dist/textgen/openaichat/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./textgen/textgentest": {
|
|
54
|
+
"types": "./dist/textgen/textgentest/index.d.ts",
|
|
55
|
+
"import": "./dist/textgen/textgentest/index.js"
|
|
44
56
|
}
|
|
45
57
|
},
|
|
46
58
|
"files": [
|
|
@@ -50,7 +62,7 @@
|
|
|
50
62
|
],
|
|
51
63
|
"scripts": {
|
|
52
64
|
"prepack": "npm run build",
|
|
53
|
-
"build": "tsup src/index.ts src/providerhttp/index.ts src/projectconfig/index.ts src/connectormock/index.ts src/oauthtoken/index.ts src/singledispatch/index.ts --format esm --dts --clean",
|
|
65
|
+
"build": "tsup src/index.ts src/providerhttp/index.ts src/projectconfig/index.ts src/connectormock/index.ts src/oauthtoken/index.ts src/singledispatch/index.ts src/textgen/index.ts src/textgen/openaichat/index.ts src/textgen/textgentest/index.ts --format esm --dts --clean",
|
|
54
66
|
"typecheck": "tsc --noEmit",
|
|
55
67
|
"lint": "eslint src test",
|
|
56
68
|
"test": "vitest run",
|