@raindrop-ai/openai-managed-agents 0.0.1
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 +21 -0
- package/README.md +137 -0
- package/RELEASING.md +41 -0
- package/dist/index.d.mts +572 -0
- package/dist/index.d.ts +572 -0
- package/dist/index.js +2958 -0
- package/dist/index.mjs +2930 -0
- package/package.json +73 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { AgentSession, AgentSessionItem, AgentSessionInputParam, AgentSessionEvent } from 'openai/resources/beta/agents/agents';
|
|
3
|
+
import { SessionCreateParamsBase } from 'openai/resources/beta/agents/sessions/sessions';
|
|
4
|
+
import { Turn } from 'openai/resources/beta/agents/sessions/turns';
|
|
5
|
+
|
|
6
|
+
type OtlpAnyValue = {
|
|
7
|
+
stringValue?: string;
|
|
8
|
+
intValue?: string;
|
|
9
|
+
doubleValue?: number;
|
|
10
|
+
boolValue?: boolean;
|
|
11
|
+
arrayValue?: {
|
|
12
|
+
values: OtlpAnyValue[];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type OtlpKeyValue = {
|
|
16
|
+
key: string;
|
|
17
|
+
value: OtlpAnyValue;
|
|
18
|
+
};
|
|
19
|
+
declare const SpanStatusCode: {
|
|
20
|
+
readonly UNSET: 0;
|
|
21
|
+
readonly OK: 1;
|
|
22
|
+
readonly ERROR: 2;
|
|
23
|
+
};
|
|
24
|
+
type OtlpSpanStatus = {
|
|
25
|
+
code: (typeof SpanStatusCode)[keyof typeof SpanStatusCode] | number;
|
|
26
|
+
message?: string;
|
|
27
|
+
};
|
|
28
|
+
type OtlpSpan = {
|
|
29
|
+
traceId: string;
|
|
30
|
+
spanId: string;
|
|
31
|
+
parentSpanId?: string;
|
|
32
|
+
name: string;
|
|
33
|
+
startTimeUnixNano: string;
|
|
34
|
+
endTimeUnixNano: string;
|
|
35
|
+
attributes?: OtlpKeyValue[];
|
|
36
|
+
status?: OtlpSpanStatus;
|
|
37
|
+
};
|
|
38
|
+
type SpanIds = {
|
|
39
|
+
traceIdB64: string;
|
|
40
|
+
spanIdB64: string;
|
|
41
|
+
parentSpanIdB64?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Kept structural so public integration declarations do not depend on private schemas. */
|
|
44
|
+
type AppGitOptions = {
|
|
45
|
+
commitSha?: string | null;
|
|
46
|
+
commitDirty?: boolean | null;
|
|
47
|
+
branch?: string | null;
|
|
48
|
+
detectBranch?: boolean;
|
|
49
|
+
sourceDirectory?: string;
|
|
50
|
+
autoDetect?: boolean;
|
|
51
|
+
};
|
|
52
|
+
type AppGitSnapshot = Readonly<Record<string, unknown>>;
|
|
53
|
+
type AppGitEnvironment = Readonly<Record<string, string | undefined>>;
|
|
54
|
+
type AppGitLocalResult = {
|
|
55
|
+
commitSha?: string;
|
|
56
|
+
commitDirty?: boolean;
|
|
57
|
+
branch?: string;
|
|
58
|
+
};
|
|
59
|
+
type AppGitOperationOwner = string;
|
|
60
|
+
type AppGitLocalResolver = (sourceDirectory: string | undefined, detectBranch: boolean, completed: (result: AppGitLocalResult) => void) => () => void;
|
|
61
|
+
/** One client owns its defaults; operation snapshots never wait for discovery. */
|
|
62
|
+
declare class AppGitContextImpl {
|
|
63
|
+
private defaults;
|
|
64
|
+
private explicit;
|
|
65
|
+
private explicitKeys;
|
|
66
|
+
private cancel;
|
|
67
|
+
private disposed;
|
|
68
|
+
private operations;
|
|
69
|
+
private operationOverflow;
|
|
70
|
+
private detectBranch;
|
|
71
|
+
private replayBranch;
|
|
72
|
+
private disabled;
|
|
73
|
+
constructor(options: AppGitOptions | false | undefined, runtime?: {
|
|
74
|
+
allowLocalGit?: boolean;
|
|
75
|
+
resolveLocal?: AppGitLocalResolver;
|
|
76
|
+
env?: AppGitEnvironment;
|
|
77
|
+
captureLegacyReplayBranch?: boolean;
|
|
78
|
+
allowDiscovery?: boolean;
|
|
79
|
+
});
|
|
80
|
+
private accept;
|
|
81
|
+
snapshot(properties?: Readonly<Record<string, unknown>>): AppGitSnapshot;
|
|
82
|
+
/** Safe defaults when no operation/span start was observed; never infer identity. */
|
|
83
|
+
snapshotExplicit(properties?: Readonly<Record<string, unknown>>, eventId?: string): AppGitSnapshot;
|
|
84
|
+
/** Existing replay branch reporting stays separate from opt-in event properties. */
|
|
85
|
+
snapshotForReplay(): AppGitSnapshot;
|
|
86
|
+
/** Merge a frozen span snapshot without losing client-authored provenance. */
|
|
87
|
+
mergeSnapshot(base: AppGitSnapshot, properties?: Readonly<Record<string, unknown>>, explicitKeys?: ReadonlySet<string>): AppGitSnapshot;
|
|
88
|
+
/** Shippers belonging to one client share this bounded operation registry. */
|
|
89
|
+
forOperation(eventId: string | undefined, properties?: Readonly<Record<string, unknown>>, owner?: AppGitOperationOwner): AppGitSnapshot;
|
|
90
|
+
releaseOperation(eventId: string, owner: AppGitOperationOwner): void;
|
|
91
|
+
finishOperation(eventId: string): void;
|
|
92
|
+
dispose(): void;
|
|
93
|
+
}
|
|
94
|
+
/** Structural at package boundaries: public SDK bundles contain independent copies of core. */
|
|
95
|
+
type AppGitContext = Pick<AppGitContextImpl, "snapshot" | "snapshotForReplay" | "forOperation" | "finishOperation" | "dispose"> & {
|
|
96
|
+
snapshotExplicit?: AppGitContextImpl["snapshotExplicit"];
|
|
97
|
+
mergeSnapshot?: AppGitContextImpl["mergeSnapshot"];
|
|
98
|
+
releaseOperation?: (eventId: string, owner: AppGitOperationOwner) => void;
|
|
99
|
+
};
|
|
100
|
+
declare const AppGitContext: typeof AppGitContextImpl;
|
|
101
|
+
type Attachment = {
|
|
102
|
+
type: string;
|
|
103
|
+
role: string;
|
|
104
|
+
name?: string;
|
|
105
|
+
value: string;
|
|
106
|
+
};
|
|
107
|
+
type IdentifyInput = {
|
|
108
|
+
userId: string;
|
|
109
|
+
traits?: Record<string, unknown>;
|
|
110
|
+
};
|
|
111
|
+
type EventUsage = {
|
|
112
|
+
promptTokens?: number;
|
|
113
|
+
completionTokens?: number;
|
|
114
|
+
};
|
|
115
|
+
type Patch = {
|
|
116
|
+
eventName?: string;
|
|
117
|
+
userId?: string;
|
|
118
|
+
convoId?: string;
|
|
119
|
+
input?: string;
|
|
120
|
+
output?: string;
|
|
121
|
+
model?: string;
|
|
122
|
+
usage?: EventUsage;
|
|
123
|
+
error?: unknown;
|
|
124
|
+
properties?: Record<string, unknown>;
|
|
125
|
+
featureFlags?: Record<string, string>;
|
|
126
|
+
attachments?: Attachment[];
|
|
127
|
+
isPending?: boolean;
|
|
128
|
+
timestamp?: string;
|
|
129
|
+
};
|
|
130
|
+
type SignalInput = {
|
|
131
|
+
eventId: string;
|
|
132
|
+
name: string;
|
|
133
|
+
type?: "default" | "feedback" | "edit" | "standard" | "agent" | "agent_internal";
|
|
134
|
+
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
135
|
+
timestamp?: string;
|
|
136
|
+
properties?: Record<string, unknown>;
|
|
137
|
+
attachmentId?: string;
|
|
138
|
+
comment?: string;
|
|
139
|
+
after?: string;
|
|
140
|
+
};
|
|
141
|
+
type EventShipperOptions = {
|
|
142
|
+
appGit?: AppGitOptions | false;
|
|
143
|
+
/** Share with the trace shipper so one operation uses one source snapshot. */
|
|
144
|
+
appGitContext?: AppGitContext;
|
|
145
|
+
writeKey?: string;
|
|
146
|
+
endpoint?: string;
|
|
147
|
+
enabled?: boolean;
|
|
148
|
+
debug: boolean;
|
|
149
|
+
partialFlushMs?: number;
|
|
150
|
+
sdkName?: string;
|
|
151
|
+
libraryName?: string;
|
|
152
|
+
libraryVersion?: string;
|
|
153
|
+
defaultEventName?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Explicit Workshop / local debugger URL. Wins over env vars + auto-detect.
|
|
156
|
+
* Pass `null` to opt out of all mirroring (including auto-detect).
|
|
157
|
+
*/
|
|
158
|
+
localDebuggerUrl?: string | null;
|
|
159
|
+
/**
|
|
160
|
+
* Optional project slug. When set, every outbound cloud request includes an
|
|
161
|
+
* `X-Raindrop-Project-Id: <projectId>` header. Empty / whitespace-only
|
|
162
|
+
* values are ignored. Slug format is validated on construction but never
|
|
163
|
+
* throws — the backend returns 400 on invalid values.
|
|
164
|
+
*/
|
|
165
|
+
projectId?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Per-field character cap applied to event input/output BEFORE buffering
|
|
168
|
+
* or serialization, so oversized payloads cost the cap — not the payload —
|
|
169
|
+
* on the calling code path. Truncated fields end with
|
|
170
|
+
* `...[truncated by raindrop]` and never exceed the cap, marker included.
|
|
171
|
+
* Defaults to 1,000,000 (matching the Python SDK).
|
|
172
|
+
*/
|
|
173
|
+
maxTextFieldChars?: number;
|
|
174
|
+
};
|
|
175
|
+
declare class EventShipper {
|
|
176
|
+
private appGitContext;
|
|
177
|
+
private ownsAppGitContext;
|
|
178
|
+
private readonly appGitOwner;
|
|
179
|
+
private baseUrl;
|
|
180
|
+
private writeKey?;
|
|
181
|
+
private enabled;
|
|
182
|
+
private debug;
|
|
183
|
+
private partialFlushMs;
|
|
184
|
+
private sdkName;
|
|
185
|
+
private prefix;
|
|
186
|
+
private defaultEventName;
|
|
187
|
+
private projectId;
|
|
188
|
+
private context;
|
|
189
|
+
private buffers;
|
|
190
|
+
private sticky;
|
|
191
|
+
private timers;
|
|
192
|
+
private inFlight;
|
|
193
|
+
private maxTextFieldCharsOpt;
|
|
194
|
+
/**
|
|
195
|
+
* Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
|
|
196
|
+
* Checked before every POST issued during the final flush.
|
|
197
|
+
*/
|
|
198
|
+
private shutdownDeadlineAt;
|
|
199
|
+
/**
|
|
200
|
+
* Set once `shutdown()` begins and never cleared. Sends issued after the
|
|
201
|
+
* drain window (stragglers, or flush work the deadline abandoned
|
|
202
|
+
* mid-drain) run as a single short attempt instead of regaining the full
|
|
203
|
+
* retry schedule.
|
|
204
|
+
*/
|
|
205
|
+
private hasShutdown;
|
|
206
|
+
/** URL of the local debugger / Workshop daemon, when one is reachable. */
|
|
207
|
+
private localDebuggerUrl;
|
|
208
|
+
constructor(opts: EventShipperOptions);
|
|
209
|
+
protected ownAppGitContextForShutdown(): void;
|
|
210
|
+
isDebugEnabled(): boolean;
|
|
211
|
+
private authHeaders;
|
|
212
|
+
private requestHeaders;
|
|
213
|
+
/**
|
|
214
|
+
* Build the retry/timeout options for one POST, honoring the shutdown
|
|
215
|
+
* deadline. Returns `null` when the shutdown drain window is exhausted —
|
|
216
|
+
* the caller must drop the payload (with a rate-limited warning) instead
|
|
217
|
+
* of issuing a request that could outlive process exit.
|
|
218
|
+
*
|
|
219
|
+
* Checked fresh on EVERY send, so a shutdown that begins while the flush
|
|
220
|
+
* path is mid-drain takes effect immediately: no further retries, and the
|
|
221
|
+
* per-attempt timeout is clamped to the remaining window. After
|
|
222
|
+
* `shutdown()` returns (deadline cleared, `hasShutdown` still set),
|
|
223
|
+
* sends — late callers, or flush work the deadline abandoned mid-drain —
|
|
224
|
+
* run as a single short attempt rather than regaining the full retry
|
|
225
|
+
* schedule.
|
|
226
|
+
*/
|
|
227
|
+
private requestOpts;
|
|
228
|
+
patch(eventId: string, patch: Patch): Promise<void>;
|
|
229
|
+
finish(eventId: string, patch: Pick<Patch, "output" | "model" | "usage" | "error" | "properties" | "featureFlags" | "userId">): Promise<void>;
|
|
230
|
+
flush(): Promise<void>;
|
|
231
|
+
shutdown(): Promise<void>;
|
|
232
|
+
trackSignal(signal: SignalInput): Promise<void>;
|
|
233
|
+
identify(users: IdentifyInput | IdentifyInput[]): Promise<void>;
|
|
234
|
+
private warnShutdownDrop;
|
|
235
|
+
private flushOne;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Hook fired per OTLP span right before the span is shipped (to the Raindrop
|
|
239
|
+
* API and to a local debugger). Lets callers inspect, rewrite, or drop the
|
|
240
|
+
* entire span — not just individual attributes — which is more flexible than
|
|
241
|
+
* an attribute-level hook (you can rename attributes, add new ones, drop the
|
|
242
|
+
* span outright, etc.).
|
|
243
|
+
*
|
|
244
|
+
* Return values:
|
|
245
|
+
* - `undefined` or the same span: ship the span unchanged.
|
|
246
|
+
* - a new `OtlpSpan`: ship the returned span in place of the original.
|
|
247
|
+
* - `null`: drop the span entirely from every ship path.
|
|
248
|
+
*
|
|
249
|
+
* The hook runs on the hot path — keep it synchronous and side-effect-free.
|
|
250
|
+
* If the hook throws, the span is dropped (fail-closed) so a buggy hook can
|
|
251
|
+
* never accidentally ship raw, un-redacted spans.
|
|
252
|
+
*/
|
|
253
|
+
type TransformSpanHook = (span: OtlpSpan) => OtlpSpan | null | undefined;
|
|
254
|
+
|
|
255
|
+
type InternalSpan = {
|
|
256
|
+
ids: SpanIds;
|
|
257
|
+
name: string;
|
|
258
|
+
startTimeUnixNano: string;
|
|
259
|
+
endTimeUnixNano?: string;
|
|
260
|
+
attributes: Array<OtlpKeyValue | undefined>;
|
|
261
|
+
};
|
|
262
|
+
type TraceShipperOptions = {
|
|
263
|
+
appGit?: AppGitOptions | false;
|
|
264
|
+
appGitContext?: AppGitContext;
|
|
265
|
+
writeKey?: string;
|
|
266
|
+
endpoint?: string;
|
|
267
|
+
enabled?: boolean;
|
|
268
|
+
debug: boolean;
|
|
269
|
+
debugSpans?: boolean;
|
|
270
|
+
flushIntervalMs?: number;
|
|
271
|
+
maxBatchSize?: number;
|
|
272
|
+
maxQueueSize?: number;
|
|
273
|
+
sdkName?: string;
|
|
274
|
+
serviceName?: string;
|
|
275
|
+
serviceVersion?: string;
|
|
276
|
+
/**
|
|
277
|
+
* Explicit Workshop / local debugger URL. Wins over env vars + auto-detect.
|
|
278
|
+
* Pass `null` to opt out of all mirroring (including auto-detect).
|
|
279
|
+
*/
|
|
280
|
+
localDebuggerUrl?: string | null;
|
|
281
|
+
/**
|
|
282
|
+
* Optional project slug. When set, every OTLP trace export includes an
|
|
283
|
+
* `X-Raindrop-Project-Id: <projectId>` header. Empty / whitespace-only
|
|
284
|
+
* values are ignored. Slug format is validated on construction but never
|
|
285
|
+
* throws — the backend returns 400 on invalid values.
|
|
286
|
+
*/
|
|
287
|
+
projectId?: string;
|
|
288
|
+
/**
|
|
289
|
+
* Per-span hook that fires for every OTLP span right before the span is
|
|
290
|
+
* shipped (both to the Raindrop API and to a local debugger). Lets callers
|
|
291
|
+
* inspect, rewrite, or drop entire spans — rename attributes, add new ones,
|
|
292
|
+
* scrub additional secret-shaped values inside `ai.prompt.messages` /
|
|
293
|
+
* `ai.toolCall.args`, etc.
|
|
294
|
+
*
|
|
295
|
+
* Return values:
|
|
296
|
+
* - `undefined` or the same span reference: ship the span unchanged.
|
|
297
|
+
* - a new `OtlpSpan`: ship the returned span in place of the original.
|
|
298
|
+
* - `null`: drop the span entirely from every ship path.
|
|
299
|
+
*
|
|
300
|
+
* The hook runs BEFORE the default redactor (which is the always-on floor
|
|
301
|
+
* for documented BYOK secrets). The default redactor still runs on the
|
|
302
|
+
* post-transform span unless `disableDefaultRedaction` is set, so even if
|
|
303
|
+
* a custom transform overlooks a secret-shaped attribute, the floor catches
|
|
304
|
+
* it.
|
|
305
|
+
*
|
|
306
|
+
* The hook runs on the hot path — keep it synchronous and side-effect-free.
|
|
307
|
+
* If the hook itself throws, the span is dropped (fail-closed) so a buggy
|
|
308
|
+
* hook can never accidentally ship raw, un-redacted spans.
|
|
309
|
+
*/
|
|
310
|
+
transformSpan?: TransformSpanHook;
|
|
311
|
+
/**
|
|
312
|
+
* Disable the built-in default span transformer (which scrubs documented
|
|
313
|
+
* secret-shaped properties — `apiKey`, `secretAccessKey`, `privateKey`,
|
|
314
|
+
* etc. — inside `ai.request.providerOptions` and
|
|
315
|
+
* `ai.response.providerMetadata`).
|
|
316
|
+
*
|
|
317
|
+
* Default: `false` (i.e. default redaction is on). Setting this to `true`
|
|
318
|
+
* disables the floor entirely; provide a custom `transformSpan` if you
|
|
319
|
+
* still want some redaction in that case.
|
|
320
|
+
*/
|
|
321
|
+
disableDefaultRedaction?: boolean;
|
|
322
|
+
/**
|
|
323
|
+
* Per-attribute character cap applied to every span attribute string value
|
|
324
|
+
* right before the span enters a ship path, so a multi-MB prompt/tool
|
|
325
|
+
* payload can never make the batch `JSON.stringify` (which runs on the
|
|
326
|
+
* event loop) cost seconds. Truncated values end with
|
|
327
|
+
* `...[truncated by raindrop]` and never exceed the cap, marker included.
|
|
328
|
+
* Defaults to 1,000,000 (matching the Python SDK).
|
|
329
|
+
*/
|
|
330
|
+
maxTextFieldChars?: number;
|
|
331
|
+
};
|
|
332
|
+
declare class TraceShipper {
|
|
333
|
+
private appGitContext;
|
|
334
|
+
protected ownsAppGitContext: boolean;
|
|
335
|
+
private readonly appGitOwner;
|
|
336
|
+
private appGitEventIds;
|
|
337
|
+
private appGitActiveSpans;
|
|
338
|
+
private appGitCaptured;
|
|
339
|
+
private appGitAdded;
|
|
340
|
+
private baseUrl;
|
|
341
|
+
private writeKey?;
|
|
342
|
+
private enabled;
|
|
343
|
+
private debug;
|
|
344
|
+
private debugSpans;
|
|
345
|
+
private sdkName;
|
|
346
|
+
private prefix;
|
|
347
|
+
private serviceName;
|
|
348
|
+
private serviceVersion;
|
|
349
|
+
private flushIntervalMs;
|
|
350
|
+
private maxBatchSize;
|
|
351
|
+
private maxQueueSize;
|
|
352
|
+
private projectId;
|
|
353
|
+
private queue;
|
|
354
|
+
private timer;
|
|
355
|
+
private inFlight;
|
|
356
|
+
/** URL of the local debugger / Workshop daemon, when one is reachable. */
|
|
357
|
+
private localDebuggerUrl;
|
|
358
|
+
private transformSpanHook;
|
|
359
|
+
private disableDefaultRedaction;
|
|
360
|
+
private maxTextFieldCharsOpt;
|
|
361
|
+
/**
|
|
362
|
+
* Epoch ms deadline while `shutdown()` is draining; undefined otherwise.
|
|
363
|
+
* Checked before every batch POST issued during the final flush.
|
|
364
|
+
*/
|
|
365
|
+
private shutdownDeadlineAt;
|
|
366
|
+
/**
|
|
367
|
+
* Set once `shutdown()` begins and never cleared. Sends issued after the
|
|
368
|
+
* drain window (stragglers, or flush work the deadline abandoned
|
|
369
|
+
* mid-drain) run as a single short attempt instead of regaining the full
|
|
370
|
+
* retry schedule.
|
|
371
|
+
*/
|
|
372
|
+
private hasShutdown;
|
|
373
|
+
constructor(opts: TraceShipperOptions);
|
|
374
|
+
/**
|
|
375
|
+
* Cap every string attribute value on the span. O(#attributes) length
|
|
376
|
+
* checks; only oversized values pay a slice. Runs AFTER the redaction
|
|
377
|
+
* pipeline so the default secret-scrub still sees parseable JSON in
|
|
378
|
+
* `ai.request.providerOptions` / `ai.response.providerMetadata` (capping
|
|
379
|
+
* first could cut a JSON blob mid-way, fail the parse, and ship secrets
|
|
380
|
+
* in the surviving prefix).
|
|
381
|
+
*
|
|
382
|
+
* A stricter `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` env var is honored
|
|
383
|
+
* for span content, matching the Python SDK and the OTel SDK convention.
|
|
384
|
+
*/
|
|
385
|
+
private capSpanAttributes;
|
|
386
|
+
/**
|
|
387
|
+
* Apply the user `transformSpan` hook (if any) followed by the default
|
|
388
|
+
* redactor (unless disabled). Returns either the (possibly new) span to
|
|
389
|
+
* ship, or `null` to drop the span entirely.
|
|
390
|
+
*
|
|
391
|
+
* Ordering: user hook runs first so callers can rewrite the span freely
|
|
392
|
+
* (rename attrs, add new ones, scrub things the default doesn't know
|
|
393
|
+
* about). The default redactor then runs on whatever the user produced,
|
|
394
|
+
* acting as the always-on floor for documented BYOK secrets. If the user
|
|
395
|
+
* sets `disableDefaultRedaction: true`, the floor is skipped.
|
|
396
|
+
*
|
|
397
|
+
* Fail-closed: if the user hook throws, the span is dropped — a buggy
|
|
398
|
+
* hook can never accidentally ship raw, un-redacted spans.
|
|
399
|
+
*/
|
|
400
|
+
private redactSpan;
|
|
401
|
+
isDebugEnabled(): boolean;
|
|
402
|
+
private authHeaders;
|
|
403
|
+
private requestHeaders;
|
|
404
|
+
startSpan(args: {
|
|
405
|
+
name: string;
|
|
406
|
+
parent?: {
|
|
407
|
+
traceIdB64: string;
|
|
408
|
+
spanIdB64: string;
|
|
409
|
+
};
|
|
410
|
+
eventId: string;
|
|
411
|
+
userId?: string;
|
|
412
|
+
convoId?: string;
|
|
413
|
+
eventName?: string;
|
|
414
|
+
operationId?: string;
|
|
415
|
+
attributes?: Array<OtlpKeyValue | undefined>;
|
|
416
|
+
startTimeUnixNano?: string;
|
|
417
|
+
}): InternalSpan;
|
|
418
|
+
private mirrorToLocalDebugger;
|
|
419
|
+
endSpan(span: InternalSpan, extra?: {
|
|
420
|
+
attributes?: InternalSpan["attributes"];
|
|
421
|
+
error?: unknown;
|
|
422
|
+
status?: OtlpSpanStatus;
|
|
423
|
+
endTimeUnixNano?: string;
|
|
424
|
+
}): void;
|
|
425
|
+
createSpan(args: {
|
|
426
|
+
name: string;
|
|
427
|
+
parent?: {
|
|
428
|
+
traceIdB64: string;
|
|
429
|
+
spanIdB64: string;
|
|
430
|
+
};
|
|
431
|
+
eventId: string;
|
|
432
|
+
userId?: string;
|
|
433
|
+
convoId?: string;
|
|
434
|
+
eventName?: string;
|
|
435
|
+
startTimeUnixNano: string;
|
|
436
|
+
endTimeUnixNano: string;
|
|
437
|
+
attributes?: Array<OtlpKeyValue | undefined>;
|
|
438
|
+
status?: OtlpSpanStatus;
|
|
439
|
+
}): void;
|
|
440
|
+
enqueue(span: OtlpSpan): void;
|
|
441
|
+
flush(): Promise<void>;
|
|
442
|
+
/** See EventShipper.requestOpts — same shutdown-budget semantics. */
|
|
443
|
+
private requestOpts;
|
|
444
|
+
shutdown(): Promise<void>;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Run telemetry egress with OpenTelemetry tracing suppressed.
|
|
449
|
+
*
|
|
450
|
+
* Why this exists
|
|
451
|
+
* ---------------
|
|
452
|
+
* Raindrop integrations ship spans/events over HTTP with the global `fetch`
|
|
453
|
+
* (see {@link ../http.ts `postJson`}). When the host app also runs an OTel
|
|
454
|
+
* fetch/undici instrumentation — e.g. `@vercel/otel`'s `registerOTel`, which
|
|
455
|
+
* every Eve agent installs — that instrumentation wraps *our own* telemetry
|
|
456
|
+
* POSTs in a `fetch POST <endpoint>` span. Those spans are then handed to the
|
|
457
|
+
* very exporter that issued the request, so they get shipped right back to
|
|
458
|
+
* Raindrop and Workshop as standalone "runs" (and, because each export issues
|
|
459
|
+
* another fetch, they feed back on themselves). The result is a run list
|
|
460
|
+
* flooded with `fetch POST .../v1/traces`, `.../events/track_partial` and
|
|
461
|
+
* `.../live` entries that drown out the real agent turns — especially with
|
|
462
|
+
* sub-agents, where every sandbox runs its own instrumentation.
|
|
463
|
+
*
|
|
464
|
+
* The OTel-blessed fix is to mark the active context as "tracing suppressed"
|
|
465
|
+
* around the request; instrumentations check `isTracingSuppressed` and return
|
|
466
|
+
* a no-op span instead of recording one. We do this through a hook stashed on
|
|
467
|
+
* `globalThis` by the Node entrypoint ({@link ../index.node.ts}) so that:
|
|
468
|
+
* - `@opentelemetry/api` / `@opentelemetry/core` stay *optional* — core never
|
|
469
|
+
* hard-depends on them, and the hook is simply absent when they (and thus
|
|
470
|
+
* any instrumentation to suppress) are not installed; and
|
|
471
|
+
* - the browser bundle never pulls in `node:module`, mirroring how core
|
|
472
|
+
* injects `AsyncLocalStorage` via `RAINDROP_ASYNC_LOCAL_STORAGE`.
|
|
473
|
+
*
|
|
474
|
+
* When no hook is present the callback runs unchanged, so suppression is a
|
|
475
|
+
* best-effort no-op rather than a hard requirement.
|
|
476
|
+
*/
|
|
477
|
+
/** Hook signature: run `fn` with OTel tracing suppressed, returning its value. */
|
|
478
|
+
type SuppressTracingHook = <T>(fn: () => T) => T;
|
|
479
|
+
declare global {
|
|
480
|
+
var RAINDROP_SUPPRESS_TRACING: SuppressTracingHook | undefined;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
type ParentSpanContext = {
|
|
484
|
+
traceIdB64: string;
|
|
485
|
+
spanIdB64: string;
|
|
486
|
+
eventId: string;
|
|
487
|
+
};
|
|
488
|
+
interface ContextSpan {
|
|
489
|
+
readonly traceIdB64: string;
|
|
490
|
+
readonly spanIdB64: string;
|
|
491
|
+
readonly eventId: string;
|
|
492
|
+
log?(data: Record<string, unknown>): void;
|
|
493
|
+
}
|
|
494
|
+
interface AsyncLocalStorageLike<T> {
|
|
495
|
+
getStore(): T | undefined;
|
|
496
|
+
run<R>(store: T, callback: () => R): R;
|
|
497
|
+
enterWith?(store: T): void;
|
|
498
|
+
}
|
|
499
|
+
declare abstract class ContextManager {
|
|
500
|
+
abstract getParentSpanIds(): ParentSpanContext | undefined;
|
|
501
|
+
abstract runInContext<R>(span: ContextSpan, callback: () => R): R;
|
|
502
|
+
abstract getCurrentSpan(): ContextSpan | undefined;
|
|
503
|
+
abstract isReady(): boolean;
|
|
504
|
+
}
|
|
505
|
+
declare global {
|
|
506
|
+
var RAINDROP_CONTEXT_MANAGER: (new () => ContextManager) | undefined;
|
|
507
|
+
var RAINDROP_ASYNC_LOCAL_STORAGE: (new <T>() => AsyncLocalStorageLike<T>) | undefined;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
type SessionContext = {
|
|
511
|
+
[Key in keyof Pick<Patch, "userId" | "convoId" | "eventName" | "properties">]?: Patch[Key] | undefined;
|
|
512
|
+
};
|
|
513
|
+
type OpenAIManagedAgentsOptions = SessionContext & {
|
|
514
|
+
writeKey?: string | undefined;
|
|
515
|
+
endpoint?: string | undefined;
|
|
516
|
+
projectId?: string | undefined;
|
|
517
|
+
debug?: boolean | undefined;
|
|
518
|
+
appGit?: AppGitOptions | false | undefined;
|
|
519
|
+
localWorkshopUrl?: string | false | undefined;
|
|
520
|
+
maxTextFieldChars?: number | undefined;
|
|
521
|
+
/** Custom event identity for hosts that namespace their telemetry. */
|
|
522
|
+
eventId?: ((turnId: string) => string) | undefined;
|
|
523
|
+
/** Applied to captured text, tool payloads, and errors before shipping. */
|
|
524
|
+
redact?: ((text: string) => string) | undefined;
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
declare class RaindropManagedAgentsHandler {
|
|
528
|
+
private events;
|
|
529
|
+
private traces;
|
|
530
|
+
private opts;
|
|
531
|
+
private sessions;
|
|
532
|
+
private idleSessions;
|
|
533
|
+
private completed;
|
|
534
|
+
constructor(events: EventShipper, traces: TraceShipper, opts: OpenAIManagedAgentsOptions);
|
|
535
|
+
private text;
|
|
536
|
+
private setAttributes;
|
|
537
|
+
private sessionCapture;
|
|
538
|
+
private cacheSession;
|
|
539
|
+
onSession(session: AgentSession, context?: SessionContext): void;
|
|
540
|
+
onInput(sessionId: string, input: SessionCreateParamsBase["input"]): void;
|
|
541
|
+
private capture;
|
|
542
|
+
onTurn(turn: Turn): void;
|
|
543
|
+
onItem(sessionId: string, item: AgentSessionItem): void;
|
|
544
|
+
onInputEvents(sessionId: string, events: AgentSessionInputParam[]): void;
|
|
545
|
+
onEvent(event: AgentSessionEvent): void;
|
|
546
|
+
private complete;
|
|
547
|
+
closeSessionTurns(sessionId: string, error?: Error): void;
|
|
548
|
+
forgetSession(sessionId: string, error?: Error): void;
|
|
549
|
+
shutdown(): void;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
type RaindropOpenAIManagedAgentsClient = {
|
|
553
|
+
handler: RaindropManagedAgentsHandler;
|
|
554
|
+
wrap(client: OpenAI, context?: SessionContext): OpenAI;
|
|
555
|
+
events: {
|
|
556
|
+
patch(eventId: string, patch: Patch): Promise<void>;
|
|
557
|
+
finish(eventId: string, patch: Pick<Patch, "output" | "model" | "properties">): Promise<void>;
|
|
558
|
+
addAttachments(eventId: string, attachments: Attachment[]): Promise<void>;
|
|
559
|
+
setProperties(eventId: string, properties: NonNullable<Patch["properties"]>): Promise<void>;
|
|
560
|
+
};
|
|
561
|
+
users: {
|
|
562
|
+
identify(users: IdentifyInput | IdentifyInput[]): Promise<void>;
|
|
563
|
+
};
|
|
564
|
+
signals: {
|
|
565
|
+
track(signal: SignalInput): Promise<void>;
|
|
566
|
+
};
|
|
567
|
+
flush(): Promise<void>;
|
|
568
|
+
shutdown(): Promise<void>;
|
|
569
|
+
};
|
|
570
|
+
declare function createRaindropOpenAIManagedAgents(opts?: OpenAIManagedAgentsOptions): RaindropOpenAIManagedAgentsClient;
|
|
571
|
+
|
|
572
|
+
export { type OpenAIManagedAgentsOptions, RaindropManagedAgentsHandler, type RaindropOpenAIManagedAgentsClient, type SessionContext, createRaindropOpenAIManagedAgents };
|