@xemahq/llm-client-nest 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 +176 -0
- package/README.md +105 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/dialect.d.ts +15 -0
- package/dist/lib/dialect.d.ts.map +1 -0
- package/dist/lib/dialect.js +63 -0
- package/dist/lib/dialect.js.map +1 -0
- package/dist/lib/errors.d.ts +23 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +47 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/gateway-session-minter.d.ts +20 -0
- package/dist/lib/gateway-session-minter.d.ts.map +1 -0
- package/dist/lib/gateway-session-minter.js +112 -0
- package/dist/lib/gateway-session-minter.js.map +1 -0
- package/dist/lib/gen-ai.d.ts +45 -0
- package/dist/lib/gen-ai.d.ts.map +1 -0
- package/dist/lib/gen-ai.js +126 -0
- package/dist/lib/gen-ai.js.map +1 -0
- package/dist/lib/json-readers.d.ts +6 -0
- package/dist/lib/json-readers.d.ts.map +1 -0
- package/dist/lib/json-readers.js +32 -0
- package/dist/lib/json-readers.js.map +1 -0
- package/dist/lib/llm-client.d.ts +46 -0
- package/dist/lib/llm-client.d.ts.map +1 -0
- package/dist/lib/llm-client.js +341 -0
- package/dist/lib/llm-client.js.map +1 -0
- package/dist/lib/provider-address.d.ts +3 -0
- package/dist/lib/provider-address.d.ts.map +1 -0
- package/dist/lib/provider-address.js +18 -0
- package/dist/lib/provider-address.js.map +1 -0
- package/dist/lib/session-cache.d.ts +21 -0
- package/dist/lib/session-cache.d.ts.map +1 -0
- package/dist/lib/session-cache.js +65 -0
- package/dist/lib/session-cache.js.map +1 -0
- package/dist/lib/stream.d.ts +18 -0
- package/dist/lib/stream.d.ts.map +1 -0
- package/dist/lib/stream.js +185 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/structured.d.ts +22 -0
- package/dist/lib/structured.d.ts.map +1 -0
- package/dist/lib/structured.js +62 -0
- package/dist/lib/structured.js.map +1 -0
- package/dist/lib/wire.d.ts +45 -0
- package/dist/lib/wire.d.ts.map +1 -0
- package/dist/lib/wire.js +7 -0
- package/dist/lib/wire.js.map +1 -0
- package/dist/nest/llm-client.module.d.ts +15 -0
- package/dist/nest/llm-client.module.d.ts.map +1 -0
- package/dist/nest/llm-client.module.js +61 -0
- package/dist/nest/llm-client.module.js.map +1 -0
- package/dist/nest/typed-client-mint-transport.d.ts +15 -0
- package/dist/nest/typed-client-mint-transport.d.ts.map +1 -0
- package/dist/nest/typed-client-mint-transport.js +32 -0
- package/dist/nest/typed-client-mint-transport.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @xemahq/llm-client-nest
|
|
2
|
+
|
|
3
|
+
The one way a Xema service calls a model.
|
|
4
|
+
|
|
5
|
+
`.claude/rules/llm-gateway-egress.md` names the routing pattern in three steps —
|
|
6
|
+
resolve the gateway from the **service registry**, mint a short-lived sealed
|
|
7
|
+
grant through `llm-registry-api`, send with that grant as bearer. Eleven source
|
|
8
|
+
sites across three repositories had written those three steps by hand, and they
|
|
9
|
+
disagreed about the billing tier, the audit envelope, the cache key, the
|
|
10
|
+
concurrency posture, the retry policy, the timeout and the gateway surface. This
|
|
11
|
+
package is that pattern, written once.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
@Module({
|
|
15
|
+
imports: [LlmClientModule.forRootAsync({
|
|
16
|
+
inject: [ConfigService],
|
|
17
|
+
useFactory: (config: ConfigService) => ({ realm: resolveRealm(config) }),
|
|
18
|
+
})],
|
|
19
|
+
})
|
|
20
|
+
export class MyLlmModule {}
|
|
21
|
+
|
|
22
|
+
const answer = await this.llm.chat(
|
|
23
|
+
{
|
|
24
|
+
model, // resolved by YOU — see below
|
|
25
|
+
orgId, projectId,
|
|
26
|
+
userId: 'my-service-purpose',
|
|
27
|
+
groupLabel: 'my-purpose',
|
|
28
|
+
groupCategory: 'DIRECT',
|
|
29
|
+
caller: { kind: LlmCallerKind.DIRECT, id: `my-purpose:${randomUUID()}`, orgId },
|
|
30
|
+
},
|
|
31
|
+
{ messages: [{ role: 'user', content: prompt }], maxTokens: 2000 },
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Two surfaces over one mint
|
|
36
|
+
|
|
37
|
+
The fleet asks **two** questions of the gateway-token broker, and only one of
|
|
38
|
+
them is "call a model":
|
|
39
|
+
|
|
40
|
+
| you want to | take |
|
|
41
|
+
|---|---|
|
|
42
|
+
| call a model **from this process** | `LlmClient` — `chat`, `embed` |
|
|
43
|
+
| provision a grant **into another process** | `GatewaySessionMinter` — `mintUncached` |
|
|
44
|
+
|
|
45
|
+
The second is not hypothetical: the workspace orchestrator mints one grant per
|
|
46
|
+
virtual provider and bakes the sealed tokens into a worker pod's
|
|
47
|
+
`opencode.jsonc`. It never calls the gateway, so a `chat`/`embed` client has
|
|
48
|
+
nothing to offer it. They share the mint and nothing else, so the mint is what
|
|
49
|
+
is shared.
|
|
50
|
+
|
|
51
|
+
## What it deliberately does NOT do
|
|
52
|
+
|
|
53
|
+
**It does not resolve the model.** Which model serves which purpose is the Model
|
|
54
|
+
Resolution Matrix's answer, and callers reach it six different ways — a stage
|
|
55
|
+
key, a `purpose`, a `preferredModelClass`, an above-rules `?modelClass=`
|
|
56
|
+
override, an org embedding *commitment* (deliberately not a Matrix lookup at
|
|
57
|
+
all), and a caller-supplied override. Those are not one question. Resolve the
|
|
58
|
+
model yourself and hand this package a `ResolvedModel`.
|
|
59
|
+
|
|
60
|
+
**It does not let you choose `body.model`.** The gateway forces the grant's
|
|
61
|
+
sealed model slug onto every forwarded request, so a caller-supplied model would
|
|
62
|
+
be ignored. `ChatRequest` has no `model` field: an API that accepted one would
|
|
63
|
+
be an API that lies.
|
|
64
|
+
|
|
65
|
+
**It has no `baseUrl`.** Both gateway surfaces come from the minted grant. There
|
|
66
|
+
is no default provider host to fall back to and no "no gateway configured → call
|
|
67
|
+
the provider" branch. That is the egress rule, not a preference.
|
|
68
|
+
|
|
69
|
+
**It never logs, echoes or returns the grant.** Not in a log line, not in an
|
|
70
|
+
error message, not on a span attribute.
|
|
71
|
+
|
|
72
|
+
## What it centralises, and what each copy cost
|
|
73
|
+
|
|
74
|
+
| | measured across the eleven sites |
|
|
75
|
+
|---|---|
|
|
76
|
+
| **billing tier** | `resolveProviderTier(undefined)` is `BYOK`; two services spell it `providerIsSystem !== false ? MANAGED : BYOK`, which **inverts** it. One absent boolean decides whether the platform or the tenant pays, and both spellings produce a valid grant and a successful call. |
|
|
77
|
+
| **audit envelope** | one mint sends **no `caller` at all**, so that spend reaches the usage ledger with no originating object. |
|
|
78
|
+
| **cache key** | four caches, four keys. Two are keyed on `orgId` **alone** — and a grant seals one model slug, so after a Matrix change they answer the new model's call from the old model's grant, successfully and silently. |
|
|
79
|
+
| **concurrency** | two mint per call, two cache without single-flight. A mint writes a billable audit row, so a concurrent burst writes one per caller. |
|
|
80
|
+
| **timeout** | two issue the inference request with no `AbortSignal` at all. |
|
|
81
|
+
| **gateway surface** | five ways of choosing between the OpenAI-compatible proxy and the native passthrough, including one that compares a **human display name**. Routing Anthropic over the OpenAI surface silently drops reasoning output — the gateway's translator has no `thinking_delta` case. |
|
|
82
|
+
| **telemetry** | **zero** spans and **zero** metrics on any of the eleven. |
|
|
83
|
+
|
|
84
|
+
## Telemetry
|
|
85
|
+
|
|
86
|
+
Every call opens one span named `{gen_ai.operation.name} {gen_ai.request.model}`
|
|
87
|
+
and records `gen_ai.client.operation.duration` and `gen_ai.client.token.usage`,
|
|
88
|
+
per the OpenTelemetry GenAI semantic conventions. Attribute spellings are
|
|
89
|
+
exported so a consumer enriching the same span uses the same ones.
|
|
90
|
+
|
|
91
|
+
Note the convention **moved** out of the main `semantic-conventions` repository
|
|
92
|
+
into `semantic-conventions-genai`; every `gen_ai.*` entry in the old registry is
|
|
93
|
+
marked deprecated-because-moved, so a reader checking the old address will
|
|
94
|
+
conclude these names are retired. They are not. And `gen_ai.system` was renamed
|
|
95
|
+
to `gen_ai.provider.name` — an emitter writing the old spelling looks
|
|
96
|
+
instrumented on a dashboard that groups by the new one and reports nothing.
|
|
97
|
+
|
|
98
|
+
## Failure
|
|
99
|
+
|
|
100
|
+
One error class, `LlmClientError`, carrying a closed `LlmClientFailure` and a
|
|
101
|
+
`transient` flag, so a caller can degrade on a transport blip and refuse on a
|
|
102
|
+
misconfiguration without string-matching. A configuration fault is never
|
|
103
|
+
swallowed: one service's query expansion spent an unbounded period silently off
|
|
104
|
+
because a 400 on every mint was absorbed by a `catch { return null }` written
|
|
105
|
+
for transport blips.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { GatewaySessionMinter, buildMintBody, type GatewayMintTransport, } from './lib/gateway-session-minter';
|
|
2
|
+
export { DEFAULT_CALL_TIMEOUT_MS, LlmClient, type ChatMessage, type ChatRequest, type ChatResult, type EmbedResult, type LlmCallContext, type LlmUsage, } from './lib/llm-client';
|
|
3
|
+
export { GatewayDialect, chatEndpoint, embeddingsEndpoint, selectDialect, } from './lib/dialect';
|
|
4
|
+
export { LlmClientError, LlmClientFailure, MAX_DETAIL_CHARS, } from './lib/errors';
|
|
5
|
+
export { chatStreamEvents, sseDataLines, type ChatStreamEvent, } from './lib/stream';
|
|
6
|
+
export { parseStructuredOutput, structuredOutputBodyFields, structuredOutputJsonSchema, type StructuredOutputSchema, type StructuredOutputSpec, } from './lib/structured';
|
|
7
|
+
export { asArray, asRecord, asRecordOrUndefined, numberOrUndefined, stringOrUndefined, } from './lib/json-readers';
|
|
8
|
+
export { resolveBrokerProviderId } from './lib/provider-address';
|
|
9
|
+
export { GRANT_REFRESH_BUFFER_MS, GrantCache, MAX_CACHED_GRANTS, grantCacheKey, } from './lib/session-cache';
|
|
10
|
+
export { GATEWAY_TOKEN_MINT_PATH, ORG_HEADER, PROJECT_HEADER, type CreateGatewayTokenBody, type GatewaySession, type MintGatewaySessionInput, type ResolvedModel, } from './lib/wire';
|
|
11
|
+
export { ATTR_ERROR_TYPE, ATTR_GEN_AI_EMBEDDINGS_DIMENSION_COUNT, ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_PROVIDER_NAME, ATTR_GEN_AI_REQUEST_MAX_TOKENS, ATTR_GEN_AI_REQUEST_MODEL, ATTR_GEN_AI_REQUEST_STREAM, ATTR_GEN_AI_REQUEST_TEMPERATURE, ATTR_GEN_AI_RESPONSE_FINISH_REASONS, ATTR_GEN_AI_RESPONSE_ID, ATTR_GEN_AI_RESPONSE_MODEL, ATTR_GEN_AI_TOKEN_TYPE, ATTR_GEN_AI_USAGE_INPUT_TOKENS, ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, GenAiOperation, GenAiTokenType, METRIC_GEN_AI_CLIENT_OPERATION_DURATION, METRIC_GEN_AI_CLIENT_TOKEN_USAGE, genAiProviderName, genAiSpanName, } from './lib/gen-ai';
|
|
12
|
+
export { LlmClientModule, type LlmClientModuleAsyncOptions, type LlmClientModuleOptions, } from './nest/llm-client.module';
|
|
13
|
+
export { TypedServiceClientMintTransport, orgScopedClaim, } from './nest/typed-client-mint-transport';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,KAAK,oBAAoB,GAC1B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,QAAQ,GACd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,aAAa,GACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAMtB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,GAC1B,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,OAAO,EACP,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,iBAAiB,EACjB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,uBAAuB,EACvB,UAAU,EACV,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AAKpB,OAAO,EACL,eAAe,EACf,sCAAsC,EACtC,0BAA0B,EAC1B,yBAAyB,EACzB,8BAA8B,EAC9B,yBAAyB,EACzB,0BAA0B,EAC1B,+BAA+B,EAC/B,mCAAmC,EACnC,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,8BAA8B,EAC9B,+BAA+B,EAC/B,cAAc,EACd,cAAc,EACd,uCAAuC,EACvC,gCAAgC,EAChC,iBAAiB,EACjB,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,eAAe,EACf,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,GAC5B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,+BAA+B,EAC/B,cAAc,GACf,MAAM,oCAAoC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlmClientModule = exports.genAiSpanName = exports.genAiProviderName = exports.METRIC_GEN_AI_CLIENT_TOKEN_USAGE = exports.METRIC_GEN_AI_CLIENT_OPERATION_DURATION = exports.GenAiTokenType = exports.GenAiOperation = exports.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS = exports.ATTR_GEN_AI_USAGE_INPUT_TOKENS = exports.ATTR_GEN_AI_TOKEN_TYPE = exports.ATTR_GEN_AI_RESPONSE_MODEL = exports.ATTR_GEN_AI_RESPONSE_ID = exports.ATTR_GEN_AI_RESPONSE_FINISH_REASONS = exports.ATTR_GEN_AI_REQUEST_TEMPERATURE = exports.ATTR_GEN_AI_REQUEST_STREAM = exports.ATTR_GEN_AI_REQUEST_MODEL = exports.ATTR_GEN_AI_REQUEST_MAX_TOKENS = exports.ATTR_GEN_AI_PROVIDER_NAME = exports.ATTR_GEN_AI_OPERATION_NAME = exports.ATTR_GEN_AI_EMBEDDINGS_DIMENSION_COUNT = exports.ATTR_ERROR_TYPE = exports.PROJECT_HEADER = exports.ORG_HEADER = exports.GATEWAY_TOKEN_MINT_PATH = exports.grantCacheKey = exports.MAX_CACHED_GRANTS = exports.GrantCache = exports.GRANT_REFRESH_BUFFER_MS = exports.resolveBrokerProviderId = exports.stringOrUndefined = exports.numberOrUndefined = exports.asRecordOrUndefined = exports.asRecord = exports.asArray = exports.structuredOutputJsonSchema = exports.structuredOutputBodyFields = exports.parseStructuredOutput = exports.sseDataLines = exports.chatStreamEvents = exports.MAX_DETAIL_CHARS = exports.LlmClientFailure = exports.LlmClientError = exports.selectDialect = exports.embeddingsEndpoint = exports.chatEndpoint = exports.GatewayDialect = exports.LlmClient = exports.DEFAULT_CALL_TIMEOUT_MS = exports.buildMintBody = exports.GatewaySessionMinter = void 0;
|
|
4
|
+
exports.orgScopedClaim = exports.TypedServiceClientMintTransport = void 0;
|
|
5
|
+
var gateway_session_minter_1 = require("./lib/gateway-session-minter");
|
|
6
|
+
Object.defineProperty(exports, "GatewaySessionMinter", { enumerable: true, get: function () { return gateway_session_minter_1.GatewaySessionMinter; } });
|
|
7
|
+
Object.defineProperty(exports, "buildMintBody", { enumerable: true, get: function () { return gateway_session_minter_1.buildMintBody; } });
|
|
8
|
+
var llm_client_1 = require("./lib/llm-client");
|
|
9
|
+
Object.defineProperty(exports, "DEFAULT_CALL_TIMEOUT_MS", { enumerable: true, get: function () { return llm_client_1.DEFAULT_CALL_TIMEOUT_MS; } });
|
|
10
|
+
Object.defineProperty(exports, "LlmClient", { enumerable: true, get: function () { return llm_client_1.LlmClient; } });
|
|
11
|
+
var dialect_1 = require("./lib/dialect");
|
|
12
|
+
Object.defineProperty(exports, "GatewayDialect", { enumerable: true, get: function () { return dialect_1.GatewayDialect; } });
|
|
13
|
+
Object.defineProperty(exports, "chatEndpoint", { enumerable: true, get: function () { return dialect_1.chatEndpoint; } });
|
|
14
|
+
Object.defineProperty(exports, "embeddingsEndpoint", { enumerable: true, get: function () { return dialect_1.embeddingsEndpoint; } });
|
|
15
|
+
Object.defineProperty(exports, "selectDialect", { enumerable: true, get: function () { return dialect_1.selectDialect; } });
|
|
16
|
+
var errors_1 = require("./lib/errors");
|
|
17
|
+
Object.defineProperty(exports, "LlmClientError", { enumerable: true, get: function () { return errors_1.LlmClientError; } });
|
|
18
|
+
Object.defineProperty(exports, "LlmClientFailure", { enumerable: true, get: function () { return errors_1.LlmClientFailure; } });
|
|
19
|
+
Object.defineProperty(exports, "MAX_DETAIL_CHARS", { enumerable: true, get: function () { return errors_1.MAX_DETAIL_CHARS; } });
|
|
20
|
+
var stream_1 = require("./lib/stream");
|
|
21
|
+
Object.defineProperty(exports, "chatStreamEvents", { enumerable: true, get: function () { return stream_1.chatStreamEvents; } });
|
|
22
|
+
Object.defineProperty(exports, "sseDataLines", { enumerable: true, get: function () { return stream_1.sseDataLines; } });
|
|
23
|
+
var structured_1 = require("./lib/structured");
|
|
24
|
+
Object.defineProperty(exports, "parseStructuredOutput", { enumerable: true, get: function () { return structured_1.parseStructuredOutput; } });
|
|
25
|
+
Object.defineProperty(exports, "structuredOutputBodyFields", { enumerable: true, get: function () { return structured_1.structuredOutputBodyFields; } });
|
|
26
|
+
Object.defineProperty(exports, "structuredOutputJsonSchema", { enumerable: true, get: function () { return structured_1.structuredOutputJsonSchema; } });
|
|
27
|
+
var json_readers_1 = require("./lib/json-readers");
|
|
28
|
+
Object.defineProperty(exports, "asArray", { enumerable: true, get: function () { return json_readers_1.asArray; } });
|
|
29
|
+
Object.defineProperty(exports, "asRecord", { enumerable: true, get: function () { return json_readers_1.asRecord; } });
|
|
30
|
+
Object.defineProperty(exports, "asRecordOrUndefined", { enumerable: true, get: function () { return json_readers_1.asRecordOrUndefined; } });
|
|
31
|
+
Object.defineProperty(exports, "numberOrUndefined", { enumerable: true, get: function () { return json_readers_1.numberOrUndefined; } });
|
|
32
|
+
Object.defineProperty(exports, "stringOrUndefined", { enumerable: true, get: function () { return json_readers_1.stringOrUndefined; } });
|
|
33
|
+
var provider_address_1 = require("./lib/provider-address");
|
|
34
|
+
Object.defineProperty(exports, "resolveBrokerProviderId", { enumerable: true, get: function () { return provider_address_1.resolveBrokerProviderId; } });
|
|
35
|
+
var session_cache_1 = require("./lib/session-cache");
|
|
36
|
+
Object.defineProperty(exports, "GRANT_REFRESH_BUFFER_MS", { enumerable: true, get: function () { return session_cache_1.GRANT_REFRESH_BUFFER_MS; } });
|
|
37
|
+
Object.defineProperty(exports, "GrantCache", { enumerable: true, get: function () { return session_cache_1.GrantCache; } });
|
|
38
|
+
Object.defineProperty(exports, "MAX_CACHED_GRANTS", { enumerable: true, get: function () { return session_cache_1.MAX_CACHED_GRANTS; } });
|
|
39
|
+
Object.defineProperty(exports, "grantCacheKey", { enumerable: true, get: function () { return session_cache_1.grantCacheKey; } });
|
|
40
|
+
var wire_1 = require("./lib/wire");
|
|
41
|
+
Object.defineProperty(exports, "GATEWAY_TOKEN_MINT_PATH", { enumerable: true, get: function () { return wire_1.GATEWAY_TOKEN_MINT_PATH; } });
|
|
42
|
+
Object.defineProperty(exports, "ORG_HEADER", { enumerable: true, get: function () { return wire_1.ORG_HEADER; } });
|
|
43
|
+
Object.defineProperty(exports, "PROJECT_HEADER", { enumerable: true, get: function () { return wire_1.PROJECT_HEADER; } });
|
|
44
|
+
var gen_ai_1 = require("./lib/gen-ai");
|
|
45
|
+
Object.defineProperty(exports, "ATTR_ERROR_TYPE", { enumerable: true, get: function () { return gen_ai_1.ATTR_ERROR_TYPE; } });
|
|
46
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_EMBEDDINGS_DIMENSION_COUNT", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_EMBEDDINGS_DIMENSION_COUNT; } });
|
|
47
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_OPERATION_NAME", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_OPERATION_NAME; } });
|
|
48
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_PROVIDER_NAME", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_PROVIDER_NAME; } });
|
|
49
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_REQUEST_MAX_TOKENS", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_REQUEST_MAX_TOKENS; } });
|
|
50
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_REQUEST_MODEL", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_REQUEST_MODEL; } });
|
|
51
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_REQUEST_STREAM", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_REQUEST_STREAM; } });
|
|
52
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_REQUEST_TEMPERATURE", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_REQUEST_TEMPERATURE; } });
|
|
53
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_RESPONSE_FINISH_REASONS", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS; } });
|
|
54
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_RESPONSE_ID", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_RESPONSE_ID; } });
|
|
55
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_RESPONSE_MODEL", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_RESPONSE_MODEL; } });
|
|
56
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_TOKEN_TYPE", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_TOKEN_TYPE; } });
|
|
57
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_USAGE_INPUT_TOKENS", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_USAGE_INPUT_TOKENS; } });
|
|
58
|
+
Object.defineProperty(exports, "ATTR_GEN_AI_USAGE_OUTPUT_TOKENS", { enumerable: true, get: function () { return gen_ai_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS; } });
|
|
59
|
+
Object.defineProperty(exports, "GenAiOperation", { enumerable: true, get: function () { return gen_ai_1.GenAiOperation; } });
|
|
60
|
+
Object.defineProperty(exports, "GenAiTokenType", { enumerable: true, get: function () { return gen_ai_1.GenAiTokenType; } });
|
|
61
|
+
Object.defineProperty(exports, "METRIC_GEN_AI_CLIENT_OPERATION_DURATION", { enumerable: true, get: function () { return gen_ai_1.METRIC_GEN_AI_CLIENT_OPERATION_DURATION; } });
|
|
62
|
+
Object.defineProperty(exports, "METRIC_GEN_AI_CLIENT_TOKEN_USAGE", { enumerable: true, get: function () { return gen_ai_1.METRIC_GEN_AI_CLIENT_TOKEN_USAGE; } });
|
|
63
|
+
Object.defineProperty(exports, "genAiProviderName", { enumerable: true, get: function () { return gen_ai_1.genAiProviderName; } });
|
|
64
|
+
Object.defineProperty(exports, "genAiSpanName", { enumerable: true, get: function () { return gen_ai_1.genAiSpanName; } });
|
|
65
|
+
var llm_client_module_1 = require("./nest/llm-client.module");
|
|
66
|
+
Object.defineProperty(exports, "LlmClientModule", { enumerable: true, get: function () { return llm_client_module_1.LlmClientModule; } });
|
|
67
|
+
var typed_client_mint_transport_1 = require("./nest/typed-client-mint-transport");
|
|
68
|
+
Object.defineProperty(exports, "TypedServiceClientMintTransport", { enumerable: true, get: function () { return typed_client_mint_transport_1.TypedServiceClientMintTransport; } });
|
|
69
|
+
Object.defineProperty(exports, "orgScopedClaim", { enumerable: true, get: function () { return typed_client_mint_transport_1.orgScopedClaim; } });
|
|
70
|
+
//# sourceMappingURL=index.js.map
|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AAC1B,yHAAA,+BAA+B,OAAA;AAC/B,6HAAA,mCAAmC,OAAA;AACnC,iHAAA,uBAAuB,OAAA;AACvB,oHAAA,0BAA0B,OAAA;AAC1B,gHAAA,sBAAsB,OAAA;AACtB,wHAAA,8BAA8B,OAAA;AAC9B,yHAAA,+BAA+B,OAAA;AAC/B,wGAAA,cAAc,OAAA;AACd,wGAAA,cAAc,OAAA;AACd,iIAAA,uCAAuC,OAAA;AACvC,0HAAA,gCAAgC,OAAA;AAChC,2GAAA,iBAAiB,OAAA;AACjB,uGAAA,aAAa,OAAA;AAGf,8DAIkC;AAHhC,oHAAA,eAAe,OAAA;AAKjB,kFAG4C;AAF1C,8IAAA,+BAA+B,OAAA;AAC/B,6HAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GatewaySession } from './wire';
|
|
2
|
+
export declare enum GatewayDialect {
|
|
3
|
+
OpenAiCompatible = "openai-compatible",
|
|
4
|
+
AnthropicNative = "anthropic-native"
|
|
5
|
+
}
|
|
6
|
+
export declare function selectDialect(apiType: string | undefined): GatewayDialect;
|
|
7
|
+
export declare function chatEndpoint(dialect: GatewayDialect, session: GatewaySession): {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly headers: Record<string, string>;
|
|
10
|
+
};
|
|
11
|
+
export declare function embeddingsEndpoint(session: GatewaySession): {
|
|
12
|
+
readonly url: string;
|
|
13
|
+
readonly headers: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../../src/lib/dialect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAkB7C,oBAAY,cAAc;IAExB,gBAAgB,sBAAsB;IAEtC,eAAe,qBAAqB;CACrC;AAqBD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAyBzE;AAGD,wBAAgB,YAAY,CAC1B,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,GACtB;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAwBpE;AAUD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG;IAC3D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAQA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GatewayDialect = void 0;
|
|
4
|
+
exports.selectDialect = selectDialect;
|
|
5
|
+
exports.chatEndpoint = chatEndpoint;
|
|
6
|
+
exports.embeddingsEndpoint = embeddingsEndpoint;
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
var GatewayDialect;
|
|
9
|
+
(function (GatewayDialect) {
|
|
10
|
+
GatewayDialect["OpenAiCompatible"] = "openai-compatible";
|
|
11
|
+
GatewayDialect["AnthropicNative"] = "anthropic-native";
|
|
12
|
+
})(GatewayDialect || (exports.GatewayDialect = GatewayDialect = {}));
|
|
13
|
+
const API_TYPE_ANTHROPIC = 'anthropic';
|
|
14
|
+
const API_TYPE_OPENAI_COMPATIBLE = 'openai-compatible';
|
|
15
|
+
const API_TYPE_GOOGLE = 'google';
|
|
16
|
+
function selectDialect(apiType) {
|
|
17
|
+
const family = apiType?.trim().toLowerCase();
|
|
18
|
+
switch (family) {
|
|
19
|
+
case API_TYPE_ANTHROPIC:
|
|
20
|
+
return GatewayDialect.AnthropicNative;
|
|
21
|
+
case API_TYPE_OPENAI_COMPATIBLE:
|
|
22
|
+
case undefined:
|
|
23
|
+
case '':
|
|
24
|
+
return GatewayDialect.OpenAiCompatible;
|
|
25
|
+
case API_TYPE_GOOGLE:
|
|
26
|
+
throw new errors_1.LlmClientError(errors_1.LlmClientFailure.UnsupportedApiType, `Provider apiType "${API_TYPE_GOOGLE}" has no dialect in ` +
|
|
27
|
+
'@xemahq/llm-client-nest. Add one rather than routing it through the ' +
|
|
28
|
+
'OpenAI-compatible surface, which would produce a provider-side 400.');
|
|
29
|
+
default:
|
|
30
|
+
throw new errors_1.LlmClientError(errors_1.LlmClientFailure.UnsupportedApiType, `Unknown provider apiType "${apiType}"; refusing to guess a gateway dialect.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function chatEndpoint(dialect, session) {
|
|
34
|
+
switch (dialect) {
|
|
35
|
+
case GatewayDialect.AnthropicNative:
|
|
36
|
+
return {
|
|
37
|
+
url: `${session.nativeProxyUrl}/anthropic/v1/messages`,
|
|
38
|
+
headers: {
|
|
39
|
+
'content-type': 'application/json',
|
|
40
|
+
'x-api-key': session.token,
|
|
41
|
+
'anthropic-version': '2023-06-01',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
case GatewayDialect.OpenAiCompatible:
|
|
45
|
+
return {
|
|
46
|
+
url: `${session.gatewayUrl}/chat/completions`,
|
|
47
|
+
headers: {
|
|
48
|
+
'content-type': 'application/json',
|
|
49
|
+
authorization: `Bearer ${session.token}`,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function embeddingsEndpoint(session) {
|
|
55
|
+
return {
|
|
56
|
+
url: `${session.gatewayUrl}/embeddings`,
|
|
57
|
+
headers: {
|
|
58
|
+
'content-type': 'application/json',
|
|
59
|
+
authorization: `Bearer ${session.token}`,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","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BAAgB;YAClC,OAAO;gBAIL,GAAG,EAAE,GAAG,OAAO,CAAC,UAAU,mBAAmB;gBAC7C,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE;iBACzC;aACF,CAAC;IACN,CAAC;AACH,CAAC;AAUD,SAAgB,kBAAkB,CAAC,OAAuB;IAIxD,OAAO;QACL,GAAG,EAAE,GAAG,OAAO,CAAC,UAAU,aAAa;QACvC,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE;SACzC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare enum LlmClientFailure {
|
|
2
|
+
ModelUnresolved = "model_unresolved",
|
|
3
|
+
ProviderAddressMissing = "provider_address_missing",
|
|
4
|
+
GatewayMintFailed = "gateway_mint_failed",
|
|
5
|
+
GatewayGrantMalformed = "gateway_grant_malformed",
|
|
6
|
+
GatewayCallFailed = "gateway_call_failed",
|
|
7
|
+
GatewayResponseMalformed = "gateway_response_malformed",
|
|
8
|
+
UnsupportedApiType = "unsupported_api_type",
|
|
9
|
+
StructuredOutputUnrepresentable = "structured_output_unrepresentable",
|
|
10
|
+
StructuredOutputInvalid = "structured_output_invalid"
|
|
11
|
+
}
|
|
12
|
+
export declare class LlmClientError extends Error {
|
|
13
|
+
readonly reason: LlmClientFailure;
|
|
14
|
+
readonly status: number | undefined;
|
|
15
|
+
constructor(reason: LlmClientFailure, message: string, options?: {
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
readonly cause?: unknown;
|
|
18
|
+
});
|
|
19
|
+
get transient(): boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const MAX_DETAIL_CHARS = 500;
|
|
22
|
+
export declare function readDetail(response: Response): Promise<string>;
|
|
23
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AASA,oBAAY,gBAAgB;IAE1B,eAAe,qBAAqB;IAEpC,sBAAsB,6BAA6B;IAEnD,iBAAiB,wBAAwB;IAEzC,qBAAqB,4BAA4B;IAEjD,iBAAiB,wBAAwB;IAEzC,wBAAwB,+BAA+B;IAEvD,kBAAkB,yBAAyB;IAQ3C,+BAA+B,sCAAsC;IAMrE,uBAAuB,8BAA8B;CACtD;AAwBD,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,MAAM,EAAE,gBAAgB,CAAC;IACzC,SAAgB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAGzC,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;IASlE,IAAW,SAAS,IAAI,OAAO,CAE9B;CACF;AAGD,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAGpC,wBAAsB,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CASpE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_DETAIL_CHARS = exports.LlmClientError = exports.LlmClientFailure = void 0;
|
|
4
|
+
exports.readDetail = readDetail;
|
|
5
|
+
var LlmClientFailure;
|
|
6
|
+
(function (LlmClientFailure) {
|
|
7
|
+
LlmClientFailure["ModelUnresolved"] = "model_unresolved";
|
|
8
|
+
LlmClientFailure["ProviderAddressMissing"] = "provider_address_missing";
|
|
9
|
+
LlmClientFailure["GatewayMintFailed"] = "gateway_mint_failed";
|
|
10
|
+
LlmClientFailure["GatewayGrantMalformed"] = "gateway_grant_malformed";
|
|
11
|
+
LlmClientFailure["GatewayCallFailed"] = "gateway_call_failed";
|
|
12
|
+
LlmClientFailure["GatewayResponseMalformed"] = "gateway_response_malformed";
|
|
13
|
+
LlmClientFailure["UnsupportedApiType"] = "unsupported_api_type";
|
|
14
|
+
LlmClientFailure["StructuredOutputUnrepresentable"] = "structured_output_unrepresentable";
|
|
15
|
+
LlmClientFailure["StructuredOutputInvalid"] = "structured_output_invalid";
|
|
16
|
+
})(LlmClientFailure || (exports.LlmClientFailure = LlmClientFailure = {}));
|
|
17
|
+
const TRANSIENT = new Set([
|
|
18
|
+
LlmClientFailure.GatewayMintFailed,
|
|
19
|
+
LlmClientFailure.GatewayCallFailed,
|
|
20
|
+
]);
|
|
21
|
+
class LlmClientError extends Error {
|
|
22
|
+
reason;
|
|
23
|
+
status;
|
|
24
|
+
constructor(reason, message, options) {
|
|
25
|
+
super(message, options?.cause === undefined ? undefined : { cause: options.cause });
|
|
26
|
+
this.name = 'LlmClientError';
|
|
27
|
+
this.reason = reason;
|
|
28
|
+
this.status = options?.status;
|
|
29
|
+
}
|
|
30
|
+
get transient() {
|
|
31
|
+
return TRANSIENT.has(this.reason);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.LlmClientError = LlmClientError;
|
|
35
|
+
exports.MAX_DETAIL_CHARS = 500;
|
|
36
|
+
async function readDetail(response) {
|
|
37
|
+
try {
|
|
38
|
+
const text = await response.text();
|
|
39
|
+
return text.length > exports.MAX_DETAIL_CHARS
|
|
40
|
+
? `${text.slice(0, exports.MAX_DETAIL_CHARS)}…`
|
|
41
|
+
: text;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return '(no body)';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":";;;AAuFA,gCASC;AAvFD,IAAY,gBA6BX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AAI,CAAC;IACX,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,WAAW,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GrantCache } from './session-cache';
|
|
2
|
+
import { type CreateGatewayTokenBody, type GatewaySession, type MintGatewaySessionInput, type ResolvedModel } from './wire';
|
|
3
|
+
export interface GatewayMintTransport {
|
|
4
|
+
post(path: string, body: CreateGatewayTokenBody, context: {
|
|
5
|
+
readonly orgId: string;
|
|
6
|
+
readonly projectId?: string | undefined;
|
|
7
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
8
|
+
}): Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
export declare class GatewaySessionMinter {
|
|
11
|
+
private readonly transport;
|
|
12
|
+
private readonly cache;
|
|
13
|
+
constructor(transport: GatewayMintTransport, cache?: GrantCache);
|
|
14
|
+
acquire(model: ResolvedModel, input: MintGatewaySessionInput): Promise<GatewaySession>;
|
|
15
|
+
mintUncached(model: ResolvedModel, input: MintGatewaySessionInput): Promise<GatewaySession>;
|
|
16
|
+
invalidate(model: ResolvedModel, input: Pick<MintGatewaySessionInput, 'orgId' | 'projectId'>): void;
|
|
17
|
+
private mint;
|
|
18
|
+
}
|
|
19
|
+
export declare function buildMintBody(providerId: string, model: ResolvedModel, input: MintGatewaySessionInput): CreateGatewayTokenBody;
|
|
20
|
+
//# sourceMappingURL=gateway-session-minter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-session-minter.d.ts","sourceRoot":"","sources":["../../src/lib/gateway-session-minter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAIL,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EACnB,MAAM,QAAQ,CAAC;AAoBhB,MAAM,WAAW,oBAAoB;IASnC,IAAI,CACF,I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