@opencode-ai/ai 0.0.0-bootstrap.0 → 0.0.0-next-15618
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 +176 -1
- package/dist/cache-policy.d.ts +2 -0
- package/dist/cache-policy.js +108 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +9 -0
- package/dist/llm.d.ts +223 -0
- package/dist/llm.js +81 -0
- package/dist/protocols/anthropic-messages.d.ts +503 -0
- package/dist/protocols/anthropic-messages.js +745 -0
- package/dist/protocols/bedrock-converse.d.ts +476 -0
- package/dist/protocols/bedrock-converse.js +526 -0
- package/dist/protocols/bedrock-event-stream.d.ts +9 -0
- package/dist/protocols/bedrock-event-stream.js +64 -0
- package/dist/protocols/gemini.d.ts +220 -0
- package/dist/protocols/gemini.js +420 -0
- package/dist/protocols/google-vertex-anthropic.d.ts +494 -0
- package/dist/protocols/google-vertex-anthropic.js +33 -0
- package/dist/protocols/google-vertex-gemini.d.ts +59 -0
- package/dist/protocols/google-vertex-gemini.js +18 -0
- package/dist/protocols/index.d.ts +9 -0
- package/dist/protocols/index.js +9 -0
- package/dist/protocols/openai-chat.d.ts +391 -0
- package/dist/protocols/openai-chat.js +423 -0
- package/dist/protocols/openai-compatible-chat.d.ts +73 -0
- package/dist/protocols/openai-compatible-chat.js +20 -0
- package/dist/protocols/openai-compatible-responses.d.ts +85 -0
- package/dist/protocols/openai-compatible-responses.js +18 -0
- package/dist/protocols/openai-responses.d.ts +613 -0
- package/dist/protocols/openai-responses.js +828 -0
- package/dist/protocols/shared.d.ts +192 -0
- package/dist/protocols/shared.js +236 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +18 -0
- package/dist/protocols/utils/bedrock-auth.js +41 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
- package/dist/protocols/utils/bedrock-cache.js +29 -0
- package/dist/protocols/utils/bedrock-media.d.ts +49 -0
- package/dist/protocols/utils/bedrock-media.js +68 -0
- package/dist/protocols/utils/cache.d.ts +6 -0
- package/dist/protocols/utils/cache.js +8 -0
- package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
- package/dist/protocols/utils/gemini-tool-schema.js +83 -0
- package/dist/protocols/utils/lifecycle.d.ts +19 -0
- package/dist/protocols/utils/lifecycle.js +65 -0
- package/dist/protocols/utils/openai-options.d.ts +22 -0
- package/dist/protocols/utils/openai-options.js +64 -0
- package/dist/protocols/utils/tool-schema.d.ts +7 -0
- package/dist/protocols/utils/tool-schema.js +79 -0
- package/dist/protocols/utils/tool-stream.d.ts +155 -0
- package/dist/protocols/utils/tool-stream.js +136 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +13 -0
- package/dist/provider-error.js +122 -0
- package/dist/provider-package.d.ts +13 -0
- package/dist/provider-package.js +1 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +2 -0
- package/dist/providers/amazon-bedrock.d.ts +150 -0
- package/dist/providers/amazon-bedrock.js +41 -0
- package/dist/providers/anthropic-compatible.d.ts +183 -0
- package/dist/providers/anthropic-compatible.js +44 -0
- package/dist/providers/anthropic.d.ts +181 -0
- package/dist/providers/anthropic.js +39 -0
- package/dist/providers/azure/chat.d.ts +2 -0
- package/dist/providers/azure/chat.js +1 -0
- package/dist/providers/azure/responses.d.ts +2 -0
- package/dist/providers/azure/responses.js +1 -0
- package/dist/providers/azure.d.ts +183 -0
- package/dist/providers/azure.js +89 -0
- package/dist/providers/cloudflare.d.ts +232 -0
- package/dist/providers/cloudflare.js +87 -0
- package/dist/providers/github-copilot.d.ts +167 -0
- package/dist/providers/github-copilot.js +47 -0
- package/dist/providers/google-vertex/anthropic.d.ts +2 -0
- package/dist/providers/google-vertex/anthropic.js +1 -0
- package/dist/providers/google-vertex-anthropic.d.ts +181 -0
- package/dist/providers/google-vertex-anthropic.js +46 -0
- package/dist/providers/google-vertex-shared.d.ts +22 -0
- package/dist/providers/google-vertex-shared.js +61 -0
- package/dist/providers/google-vertex.d.ts +93 -0
- package/dist/providers/google-vertex.js +49 -0
- package/dist/providers/google.d.ts +85 -0
- package/dist/providers/google.js +33 -0
- package/dist/providers/index.d.ts +15 -0
- package/dist/providers/index.js +15 -0
- package/dist/providers/openai/chat.d.ts +2 -0
- package/dist/providers/openai/chat.js +1 -0
- package/dist/providers/openai/responses.d.ts +2 -0
- package/dist/providers/openai/responses.js +1 -0
- package/dist/providers/openai-compatible/responses.d.ts +1 -0
- package/dist/providers/openai-compatible/responses.js +1 -0
- package/dist/providers/openai-compatible-profile.d.ts +43 -0
- package/dist/providers/openai-compatible-profile.js +12 -0
- package/dist/providers/openai-compatible-responses.d.ts +107 -0
- package/dist/providers/openai-compatible-responses.js +33 -0
- package/dist/providers/openai-compatible.d.ts +130 -0
- package/dist/providers/openai-compatible.js +55 -0
- package/dist/providers/openai-options.d.ts +30 -0
- package/dist/providers/openai-options.js +42 -0
- package/dist/providers/openai.d.ts +264 -0
- package/dist/providers/openai.js +62 -0
- package/dist/providers/openrouter.d.ts +321 -0
- package/dist/providers/openrouter.js +65 -0
- package/dist/providers/xai.d.ts +169 -0
- package/dist/providers/xai.js +43 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1 -0
- package/dist/route/auth-options.d.ts +34 -0
- package/dist/route/auth-options.js +14 -0
- package/dist/route/auth.d.ts +49 -0
- package/dist/route/auth.js +89 -0
- package/dist/route/client.d.ts +330 -0
- package/dist/route/client.js +211 -0
- package/dist/route/endpoint.d.ts +28 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor.d.ts +12 -0
- package/dist/route/executor.js +229 -0
- package/dist/route/framing.d.ts +23 -0
- package/dist/route/framing.js +4 -0
- package/dist/route/index.d.ts +16 -0
- package/dist/route/index.js +9 -0
- package/dist/route/protocol.d.ts +76 -0
- package/dist/route/protocol.js +17 -0
- package/dist/route/transport/http.d.ts +33 -0
- package/dist/route/transport/http.js +98 -0
- package/dist/route/transport/index.d.ts +27 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket.d.ts +56 -0
- package/dist/route/transport/websocket.js +181 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +153 -0
- package/dist/schema/errors.js +150 -0
- package/dist/schema/events.d.ts +4292 -0
- package/dist/schema/events.js +482 -0
- package/dist/schema/ids.d.ts +30 -0
- package/dist/schema/ids.js +18 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +385 -0
- package/dist/schema/messages.js +246 -0
- package/dist/schema/options.d.ts +143 -0
- package/dist/schema/options.js +195 -0
- package/dist/tool-runtime.d.ts +15 -0
- package/dist/tool-runtime.js +35 -0
- package/dist/tool.d.ts +134 -0
- package/dist/tool.js +66 -0
- package/dist/utils/record.d.ts +2 -0
- package/dist/utils/record.js +2 -0
- package/package.json +36 -9
- package/index.js +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ModelID, ProviderID, ProviderMetadata, RouteID } from "./ids";
|
|
3
|
+
export const ProviderFailureClassification = Schema.Literal("context-overflow");
|
|
4
|
+
export class HttpRequestDetails extends Schema.Class("LLM.HttpRequestDetails")({
|
|
5
|
+
method: Schema.String,
|
|
6
|
+
url: Schema.String,
|
|
7
|
+
headers: Schema.Record(Schema.String, Schema.String),
|
|
8
|
+
}) {
|
|
9
|
+
}
|
|
10
|
+
export class HttpResponseDetails extends Schema.Class("LLM.HttpResponseDetails")({
|
|
11
|
+
status: Schema.Number,
|
|
12
|
+
headers: Schema.Record(Schema.String, Schema.String),
|
|
13
|
+
}) {
|
|
14
|
+
}
|
|
15
|
+
export class HttpRateLimitDetails extends Schema.Class("LLM.HttpRateLimitDetails")({
|
|
16
|
+
retryAfterMs: Schema.optional(Schema.Number),
|
|
17
|
+
limit: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
18
|
+
remaining: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
19
|
+
reset: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
20
|
+
}) {
|
|
21
|
+
}
|
|
22
|
+
export class HttpContext extends Schema.Class("LLM.HttpContext")({
|
|
23
|
+
request: HttpRequestDetails,
|
|
24
|
+
response: Schema.optional(HttpResponseDetails),
|
|
25
|
+
body: Schema.optional(Schema.String),
|
|
26
|
+
bodyTruncated: Schema.optional(Schema.Boolean),
|
|
27
|
+
requestId: Schema.optional(Schema.String),
|
|
28
|
+
rateLimit: Schema.optional(HttpRateLimitDetails),
|
|
29
|
+
}) {
|
|
30
|
+
}
|
|
31
|
+
export class InvalidRequestReason extends Schema.Class("LLM.Error.InvalidRequest")({
|
|
32
|
+
_tag: Schema.tag("InvalidRequest"),
|
|
33
|
+
message: Schema.String,
|
|
34
|
+
parameter: Schema.optional(Schema.String),
|
|
35
|
+
classification: Schema.optional(ProviderFailureClassification),
|
|
36
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
37
|
+
http: Schema.optional(HttpContext),
|
|
38
|
+
}) {
|
|
39
|
+
}
|
|
40
|
+
export class NoRouteReason extends Schema.Class("LLM.Error.NoRoute")({
|
|
41
|
+
_tag: Schema.tag("NoRoute"),
|
|
42
|
+
route: RouteID,
|
|
43
|
+
provider: ProviderID,
|
|
44
|
+
model: ModelID,
|
|
45
|
+
}) {
|
|
46
|
+
get message() {
|
|
47
|
+
return `No LLM route for ${this.provider}/${this.model} using ${this.route}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class AuthenticationReason extends Schema.Class("LLM.Error.Authentication")({
|
|
51
|
+
_tag: Schema.tag("Authentication"),
|
|
52
|
+
message: Schema.String,
|
|
53
|
+
kind: Schema.Literals(["missing", "invalid", "expired", "insufficient-permissions", "unknown"]),
|
|
54
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
55
|
+
http: Schema.optional(HttpContext),
|
|
56
|
+
}) {
|
|
57
|
+
}
|
|
58
|
+
export class RateLimitReason extends Schema.Class("LLM.Error.RateLimit")({
|
|
59
|
+
_tag: Schema.tag("RateLimit"),
|
|
60
|
+
message: Schema.String,
|
|
61
|
+
retryAfterMs: Schema.optional(Schema.Number),
|
|
62
|
+
rateLimit: Schema.optional(HttpRateLimitDetails),
|
|
63
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
64
|
+
http: Schema.optional(HttpContext),
|
|
65
|
+
}) {
|
|
66
|
+
}
|
|
67
|
+
export class QuotaExceededReason extends Schema.Class("LLM.Error.QuotaExceeded")({
|
|
68
|
+
_tag: Schema.tag("QuotaExceeded"),
|
|
69
|
+
message: Schema.String,
|
|
70
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
71
|
+
http: Schema.optional(HttpContext),
|
|
72
|
+
}) {
|
|
73
|
+
}
|
|
74
|
+
export class ContentPolicyReason extends Schema.Class("LLM.Error.ContentPolicy")({
|
|
75
|
+
_tag: Schema.tag("ContentPolicy"),
|
|
76
|
+
message: Schema.String,
|
|
77
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
78
|
+
http: Schema.optional(HttpContext),
|
|
79
|
+
}) {
|
|
80
|
+
}
|
|
81
|
+
export class ProviderInternalReason extends Schema.Class("LLM.Error.ProviderInternal")({
|
|
82
|
+
_tag: Schema.tag("ProviderInternal"),
|
|
83
|
+
message: Schema.String,
|
|
84
|
+
status: Schema.optional(Schema.Number),
|
|
85
|
+
retryAfterMs: Schema.optional(Schema.Number),
|
|
86
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
87
|
+
http: Schema.optional(HttpContext),
|
|
88
|
+
}) {
|
|
89
|
+
}
|
|
90
|
+
export class TransportReason extends Schema.Class("LLM.Error.Transport")({
|
|
91
|
+
_tag: Schema.tag("Transport"),
|
|
92
|
+
message: Schema.String,
|
|
93
|
+
kind: Schema.optional(Schema.String),
|
|
94
|
+
url: Schema.optional(Schema.String),
|
|
95
|
+
http: Schema.optional(HttpContext),
|
|
96
|
+
}) {
|
|
97
|
+
}
|
|
98
|
+
export class InvalidProviderOutputReason extends Schema.Class("LLM.Error.InvalidProviderOutput")({
|
|
99
|
+
_tag: Schema.tag("InvalidProviderOutput"),
|
|
100
|
+
message: Schema.String,
|
|
101
|
+
route: Schema.optional(Schema.String),
|
|
102
|
+
raw: Schema.optional(Schema.String),
|
|
103
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
104
|
+
}) {
|
|
105
|
+
}
|
|
106
|
+
export class UnknownProviderReason extends Schema.Class("LLM.Error.UnknownProvider")({
|
|
107
|
+
_tag: Schema.tag("UnknownProvider"),
|
|
108
|
+
message: Schema.String,
|
|
109
|
+
status: Schema.optional(Schema.Number),
|
|
110
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
111
|
+
http: Schema.optional(HttpContext),
|
|
112
|
+
}) {
|
|
113
|
+
}
|
|
114
|
+
export const LLMErrorReason = Schema.Union([
|
|
115
|
+
InvalidRequestReason,
|
|
116
|
+
NoRouteReason,
|
|
117
|
+
AuthenticationReason,
|
|
118
|
+
RateLimitReason,
|
|
119
|
+
QuotaExceededReason,
|
|
120
|
+
ContentPolicyReason,
|
|
121
|
+
ProviderInternalReason,
|
|
122
|
+
TransportReason,
|
|
123
|
+
InvalidProviderOutputReason,
|
|
124
|
+
UnknownProviderReason,
|
|
125
|
+
]).pipe(Schema.toTaggedUnion("_tag"));
|
|
126
|
+
export class LLMError extends Schema.TaggedErrorClass()("LLM.Error", {
|
|
127
|
+
module: Schema.String,
|
|
128
|
+
method: Schema.String,
|
|
129
|
+
reason: LLMErrorReason,
|
|
130
|
+
}) {
|
|
131
|
+
cause = this.reason;
|
|
132
|
+
get message() {
|
|
133
|
+
return `${this.module}.${this.method}: ${this.reason.message}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Failure type for tool execute handlers. Handlers must map their internal
|
|
138
|
+
* errors to this shape; the runtime catches `ToolFailure`s and surfaces them
|
|
139
|
+
* as `tool-error` events plus a `tool-result` of `type: "error"` so the model
|
|
140
|
+
* can self-correct.
|
|
141
|
+
*
|
|
142
|
+
* Anything thrown or yielded by a handler that is not a `ToolFailure` is
|
|
143
|
+
* treated as a defect and fails the stream.
|
|
144
|
+
*/
|
|
145
|
+
export class ToolFailure extends Schema.TaggedErrorClass()("LLM.ToolFailure", {
|
|
146
|
+
message: Schema.String,
|
|
147
|
+
error: Schema.optional(Schema.Defect()),
|
|
148
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
149
|
+
}) {
|
|
150
|
+
}
|