@grafana/sigil-sdk-js-core 0.0.0 → 0.6.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 +2 -200
- package/README.md +34 -1
- package/dist/cache-diagnostics.d.ts +15 -0
- package/dist/cache-diagnostics.d.ts.map +1 -0
- package/dist/cache-diagnostics.js +15 -0
- package/dist/cache-diagnostics.js.map +1 -0
- package/dist/client.d.ts +138 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1855 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +375 -0
- package/dist/config.js.map +1 -0
- package/dist/content_capture.d.ts +34 -0
- package/dist/content_capture.d.ts.map +1 -0
- package/dist/content_capture.js +121 -0
- package/dist/content_capture.js.map +1 -0
- package/dist/context.d.ts +11 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +80 -0
- package/dist/context.js.map +1 -0
- package/dist/core.d.ts +13 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +12 -0
- package/dist/core.js.map +1 -0
- package/dist/exporters/default.d.ts +3 -0
- package/dist/exporters/default.d.ts.map +1 -0
- package/dist/exporters/default.js +77 -0
- package/dist/exporters/default.js.map +1 -0
- package/dist/exporters/grpc.d.ts +14 -0
- package/dist/exporters/grpc.d.ts.map +1 -0
- package/dist/exporters/grpc.js +375 -0
- package/dist/exporters/grpc.js.map +1 -0
- package/dist/exporters/http.d.ts +10 -0
- package/dist/exporters/http.d.ts.map +1 -0
- package/dist/exporters/http.js +280 -0
- package/dist/exporters/http.js.map +1 -0
- package/dist/hooks.d.ts +33 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +464 -0
- package/dist/hooks.js.map +1 -0
- package/dist/redaction.d.ts +16 -0
- package/dist/redaction.d.ts.map +1 -0
- package/dist/redaction.js +155 -0
- package/dist/redaction.js.map +1 -0
- package/dist/types.d.ts +597 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +355 -0
- package/dist/utils.js.map +1 -0
- package/package.json +46 -8
- package/proto/sigil/v1/generation_ingest.proto +187 -0
- package/index.js +0 -1
package/LICENSE
CHANGED
|
@@ -1,201 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
1
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
2
|
|
|
5
|
-
|
|
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
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
3
|
+
See /LICENSE at repository root for full license text.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
1
|
# Grafana Sigil JavaScript Core SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Slim JavaScript package for Sigil generation export and core recording APIs.
|
|
4
|
+
|
|
5
|
+
Use `@grafana/sigil-sdk-js-core` when you want the core `SigilClient` without the provider and framework integration dependencies included by `@grafana/sigil-sdk-js`.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @grafana/sigil-sdk-js-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { SigilClient } from "@grafana/sigil-sdk-js-core";
|
|
13
|
+
|
|
14
|
+
const client = new SigilClient({
|
|
15
|
+
generationExport: {
|
|
16
|
+
protocol: "http",
|
|
17
|
+
endpoint: "https://sigil.example.com",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The default HTTP export path has no provider SDK dependencies. If you configure `generationExport.protocol: "grpc"`, install the optional gRPC peer packages:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @grpc/grpc-js @grpc/proto-loader
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Edge runtime support
|
|
29
|
+
|
|
30
|
+
The default HTTP export path is designed to load and run in edge-like runtimes (for example Cloudflare Workers, Vercel Edge, Deno Deploy) that do not provide Node-only globals (`process`, `Buffer`) or built-in modules (`node:async_hooks`, `node:crypto`). The gRPC exporter is loaded lazily and is only required when `generationExport.protocol: "grpc"` is set.
|
|
31
|
+
|
|
32
|
+
A few caveats:
|
|
33
|
+
|
|
34
|
+
- **Bundler externals for the gRPC code path.** Even though gRPC is dynamically imported, some bundlers (esbuild, webpack, wrangler) statically trace `import('./grpc.js')` and may include `@grpc/grpc-js`, `@grpc/proto-loader`, and `node:*` modules in the output. If you target an edge runtime, mark these as external in your bundler configuration. They are only needed at runtime when you opt in to `protocol: "grpc"`.
|
|
35
|
+
- **Context propagation requires `AsyncLocalStorage`.** The `withConversationId`, `withUserId`, `withAgentName`, and similar helpers rely on `node:async_hooks`. In runtimes without it, the helpers become no-ops and the SDK emits a one-time warning. Pass the identifiers explicitly on each `startGeneration` / `startToolExecution` call when running there.
|
|
36
|
+
- **`generation.effectiveVersion` requires `node:crypto`.** Setting `effectiveVersion` makes the background exporter compute a SHA-256 digest with `node:crypto`. In runtimes without it the next flush of any generation with this field set will throw. Leave the field unset when running in such a runtime.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GenerationRecorder } from './types.js';
|
|
2
|
+
/** Reserved generation metadata keys (Sigil docs/guides/cache-diagnostics.md). */
|
|
3
|
+
export declare const CACHE_DIAGNOSTICS_MISS_REASON_KEY = "sigil.cache_diagnostics.miss_reason";
|
|
4
|
+
export declare const CACHE_DIAGNOSTICS_MISSED_INPUT_TOKENS_KEY = "sigil.cache_diagnostics.missed_input_tokens";
|
|
5
|
+
export declare const CACHE_DIAGNOSTICS_PREVIOUS_MESSAGE_ID_KEY = "sigil.cache_diagnostics.previous_message_id";
|
|
6
|
+
export type CacheDiagnosticsOptions = {
|
|
7
|
+
missedInputTokens?: number;
|
|
8
|
+
previousMessageId?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Stamp `sigil.cache_diagnostics.*` metadata on a generation recorder.
|
|
12
|
+
* Call before `end()`, typically after the provider response is available.
|
|
13
|
+
*/
|
|
14
|
+
export declare function setCacheDiagnostics(rec: GenerationRecorder | null | undefined, missReason: string, opts?: CacheDiagnosticsOptions): void;
|
|
15
|
+
//# sourceMappingURL=cache-diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-diagnostics.d.ts","sourceRoot":"","sources":["../../js/src/cache-diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,kFAAkF;AAClF,eAAO,MAAM,iCAAiC,wCAAwC,CAAC;AACvF,eAAO,MAAM,yCAAyC,gDAAgD,CAAC;AACvG,eAAO,MAAM,yCAAyC,gDAAgD,CAAC;AAEvG,MAAM,MAAM,uBAAuB,GAAG;IACpC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,EAC1C,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,uBAAuB,GAC7B,IAAI,CAKN"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Reserved generation metadata keys (Sigil docs/guides/cache-diagnostics.md). */
|
|
2
|
+
export const CACHE_DIAGNOSTICS_MISS_REASON_KEY = 'sigil.cache_diagnostics.miss_reason';
|
|
3
|
+
export const CACHE_DIAGNOSTICS_MISSED_INPUT_TOKENS_KEY = 'sigil.cache_diagnostics.missed_input_tokens';
|
|
4
|
+
export const CACHE_DIAGNOSTICS_PREVIOUS_MESSAGE_ID_KEY = 'sigil.cache_diagnostics.previous_message_id';
|
|
5
|
+
/**
|
|
6
|
+
* Stamp `sigil.cache_diagnostics.*` metadata on a generation recorder.
|
|
7
|
+
* Call before `end()`, typically after the provider response is available.
|
|
8
|
+
*/
|
|
9
|
+
export function setCacheDiagnostics(rec, missReason, opts) {
|
|
10
|
+
if (rec === null || rec === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
rec.setCacheDiagnostics(missReason, opts);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=cache-diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-diagnostics.js","sourceRoot":"","sources":["../../js/src/cache-diagnostics.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,MAAM,CAAC,MAAM,iCAAiC,GAAG,qCAAqC,CAAC;AACvF,MAAM,CAAC,MAAM,yCAAyC,GAAG,6CAA6C,CAAC;AACvG,MAAM,CAAC,MAAM,yCAAyC,GAAG,6CAA6C,CAAC;AAOvG;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAA0C,EAC1C,UAAkB,EAClB,IAA8B;IAE9B,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO;IACT,CAAC;IACD,GAAG,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type Span } from '@opentelemetry/api';
|
|
2
|
+
import type { ContentCaptureMode, ConversationRatingInput, EmbeddingRecorder, EmbeddingResult, EmbeddingStart, ExecuteToolCallsOptions, Generation, GenerationMode, GenerationRecorder, GenerationStart, HookEvaluateRequest, HookEvaluateResponse, HooksConfig, Message, RecorderCallback, SigilDebugSnapshot, SigilSdkConfigInput, SubmitConversationRatingResponse, ToolExecution, ToolExecutionRecorder, ToolExecutionStart } from './types.js';
|
|
3
|
+
export declare class SigilClient {
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly nowFn;
|
|
6
|
+
private readonly sleepFn;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
private readonly generationExporter;
|
|
9
|
+
private readonly tracer;
|
|
10
|
+
private readonly meter;
|
|
11
|
+
private readonly operationDurationHistogram;
|
|
12
|
+
private readonly tokenUsageHistogram;
|
|
13
|
+
private readonly ttftHistogram;
|
|
14
|
+
private readonly toolCallsHistogram;
|
|
15
|
+
private readonly generations;
|
|
16
|
+
private readonly toolExecutions;
|
|
17
|
+
private readonly pendingGenerations;
|
|
18
|
+
private flushPromise;
|
|
19
|
+
private flushRequested;
|
|
20
|
+
private flushTimer;
|
|
21
|
+
private shutdownPromise;
|
|
22
|
+
private shuttingDown;
|
|
23
|
+
private closed;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a Sigil SDK client.
|
|
26
|
+
*
|
|
27
|
+
* `inputConfig` is merged with defaults.
|
|
28
|
+
*/
|
|
29
|
+
constructor(inputConfig?: SigilSdkConfigInput);
|
|
30
|
+
/**
|
|
31
|
+
* Starts a generation recorder (`SYNC` mode).
|
|
32
|
+
*
|
|
33
|
+
* Overloads:
|
|
34
|
+
* - returns recorder for manual lifecycle
|
|
35
|
+
* - executes callback and auto-ends recorder
|
|
36
|
+
*/
|
|
37
|
+
startGeneration(start: GenerationStart): GenerationRecorder;
|
|
38
|
+
startGeneration<TResult>(start: GenerationStart, callback: RecorderCallback<GenerationRecorder, TResult>): Promise<TResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Starts a streaming generation recorder (`STREAM` mode).
|
|
41
|
+
*
|
|
42
|
+
* Overloads:
|
|
43
|
+
* - returns recorder for manual lifecycle
|
|
44
|
+
* - executes callback and auto-ends recorder
|
|
45
|
+
*/
|
|
46
|
+
startStreamingGeneration(start: GenerationStart): GenerationRecorder;
|
|
47
|
+
startStreamingGeneration<TResult>(start: GenerationStart, callback: RecorderCallback<GenerationRecorder, TResult>): Promise<TResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Starts an embeddings recorder.
|
|
50
|
+
*
|
|
51
|
+
* Overloads:
|
|
52
|
+
* - returns recorder for manual lifecycle
|
|
53
|
+
* - executes callback and auto-ends recorder
|
|
54
|
+
*/
|
|
55
|
+
startEmbedding(start: EmbeddingStart): EmbeddingRecorder;
|
|
56
|
+
startEmbedding<TResult>(start: EmbeddingStart, callback: RecorderCallback<EmbeddingRecorder, TResult>): Promise<TResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Starts a tool execution recorder.
|
|
59
|
+
*
|
|
60
|
+
* Empty tool names return a no-op recorder to keep instrumentation safe.
|
|
61
|
+
*/
|
|
62
|
+
startToolExecution(start: ToolExecutionStart): ToolExecutionRecorder;
|
|
63
|
+
startToolExecution<TResult>(start: ToolExecutionStart, callback: RecorderCallback<ToolExecutionRecorder, TResult>): Promise<TResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Runs each `tool_call` part under `execute_tool` spans and returns tool messages.
|
|
66
|
+
*
|
|
67
|
+
* Walks `messages` (typically `GenerationResult.output`) and invokes `executor`
|
|
68
|
+
* for every tool-call part. Returns `tool` role messages with `tool_result` parts.
|
|
69
|
+
*/
|
|
70
|
+
executeToolCalls(messages: Message[], executor: (toolName: string, args: unknown) => unknown | Promise<unknown>, options?: ExecuteToolCallsOptions): Promise<Message[]>;
|
|
71
|
+
/** Submits a user-facing conversation rating through Sigil HTTP API. */
|
|
72
|
+
submitConversationRating(conversationId: string, input: ConversationRatingInput): Promise<SubmitConversationRatingResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the resolved hook configuration. Framework adapters use this to
|
|
75
|
+
* decide whether to invoke `evaluateHook` and which phases are configured.
|
|
76
|
+
*/
|
|
77
|
+
get hooksConfig(): HooksConfig;
|
|
78
|
+
/**
|
|
79
|
+
* Evaluates synchronous hook rules for the given request.
|
|
80
|
+
*
|
|
81
|
+
* Use this to enforce preflight or postflight guardrails (PII, content
|
|
82
|
+
* policy, etc.) on the LLM call's critical path. The server returns
|
|
83
|
+
* `{ action: 'deny' }` to block; framework adapters typically translate that
|
|
84
|
+
* into a `HookDeniedError`.
|
|
85
|
+
*
|
|
86
|
+
* When `hooks.enabled` is false, this short-circuits to `allow`. When
|
|
87
|
+
* `hooks.failOpen` is true (default), network/timeout failures also resolve
|
|
88
|
+
* to `allow` so the LLM call can proceed.
|
|
89
|
+
*
|
|
90
|
+
* Framework adapters can pass `hooksConfigOverride` to override specific
|
|
91
|
+
* fields of the client's hooks config (e.g., force `enabled: true` when the
|
|
92
|
+
* adapter has its own `enableHooks` option).
|
|
93
|
+
*/
|
|
94
|
+
evaluateHook(request: HookEvaluateRequest, hooksConfigOverride?: Partial<HooksConfig>): Promise<HookEvaluateResponse>;
|
|
95
|
+
/** Forces immediate drain of queued generation exports. */
|
|
96
|
+
flush(): Promise<void>;
|
|
97
|
+
/** Flushes pending generations and shuts down the generation exporter. */
|
|
98
|
+
shutdown(): Promise<void>;
|
|
99
|
+
/** Returns a cloned in-memory snapshot for debugging and tests. */
|
|
100
|
+
debugSnapshot(): SigilDebugSnapshot;
|
|
101
|
+
internalNow(): Date;
|
|
102
|
+
internalAgentName(): string | undefined;
|
|
103
|
+
internalAgentVersion(): string | undefined;
|
|
104
|
+
internalUserId(): string | undefined;
|
|
105
|
+
internalTags(): Record<string, string> | undefined;
|
|
106
|
+
internalRecordGeneration(generation: Generation): void;
|
|
107
|
+
internalRecordToolExecution(toolExecution: ToolExecution): void;
|
|
108
|
+
internalEnqueueGeneration(generation: Generation): void;
|
|
109
|
+
internalLogWarn(message: string, error?: unknown): void;
|
|
110
|
+
internalResolveGenerationContentCaptureMode(seed: GenerationStart): ContentCaptureMode;
|
|
111
|
+
internalResolveEmbeddingContentCaptureMode(seed: EmbeddingStart): ContentCaptureMode;
|
|
112
|
+
internalResolveToolContentCaptureMode(seed: ToolExecutionStart): ContentCaptureMode;
|
|
113
|
+
internalHasGenerationSanitizer(): boolean;
|
|
114
|
+
internalSanitizeGeneration(generation: Generation): Generation;
|
|
115
|
+
internalStartGenerationSpan(seed: GenerationStart, mode: GenerationMode, startedAt: Date, contentCaptureMode: ContentCaptureMode): Span;
|
|
116
|
+
internalStartEmbeddingSpan(seed: EmbeddingStart, startedAt: Date): Span;
|
|
117
|
+
internalStartToolExecutionSpan(seed: ToolExecutionStart, startedAt: Date): Span;
|
|
118
|
+
internalApplyTraceContextFromSpan(span: Span, generation: Generation): void;
|
|
119
|
+
internalSyncGenerationSpan(span: Span, generation: Generation): void;
|
|
120
|
+
internalClearSpanConversationTitle(span: Span): void;
|
|
121
|
+
internalFinalizeGenerationSpan(span: Span, generation: Generation, callError: string | undefined, validationError: Error | undefined, enqueueError: Error | undefined, firstTokenAt: Date | undefined, precomputedCallErrorCategory?: string): void;
|
|
122
|
+
internalFinalizeEmbeddingSpan(span: Span, seed: EmbeddingStart, result: EmbeddingResult, hasResult: boolean, callError: Error | undefined, localError: Error | undefined, startedAt: Date, completedAt: Date, contentCaptureMode?: ContentCaptureMode): void;
|
|
123
|
+
internalFinalizeToolExecutionSpan(span: Span, toolExecution: ToolExecution, localError: Error | undefined, contentCaptureMode?: ContentCaptureMode): Error | undefined;
|
|
124
|
+
private recordGenerationMetrics;
|
|
125
|
+
private recordEmbeddingMetrics;
|
|
126
|
+
private recordTokenUsage;
|
|
127
|
+
private recordToolExecutionMetrics;
|
|
128
|
+
private assertOpen;
|
|
129
|
+
private startGenerationWithMode;
|
|
130
|
+
private triggerAsyncFlush;
|
|
131
|
+
private flushInternal;
|
|
132
|
+
private drainPendingGenerations;
|
|
133
|
+
private exportWithRetry;
|
|
134
|
+
private logRejectedResults;
|
|
135
|
+
private stopFlushTimer;
|
|
136
|
+
private logWarn;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../js/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAA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