@granular-software/sdk 0.4.37 → 0.4.39
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/dist/agent-evals.d.mts +17 -3
- package/dist/agent-evals.d.ts +17 -3
- package/dist/agent-evals.js +1067 -153
- package/dist/agent-evals.js.map +1 -1
- package/dist/agent-evals.mjs +1066 -154
- package/dist/agent-evals.mjs.map +1 -1
- package/dist/agent-harness.d.mts +9 -2
- package/dist/agent-harness.d.ts +9 -2
- package/dist/agent-harness.js +273 -5
- package/dist/agent-harness.js.map +1 -1
- package/dist/agent-harness.mjs +271 -6
- package/dist/agent-harness.mjs.map +1 -1
- package/dist/cli/index.js +293 -34
- package/dist/client-BZ8NuQ_e.d.ts +1080 -0
- package/dist/client-CBQFvuKf.d.mts +1080 -0
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +668 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +659 -40
- package/dist/index.mjs.map +1 -1
- package/dist/spend-tAz2a16I.d.mts +1593 -0
- package/dist/spend-tAz2a16I.d.ts +1593 -0
- package/dist/spend.d.mts +2 -0
- package/dist/spend.d.ts +2 -0
- package/dist/spend.js +111 -0
- package/dist/spend.js.map +1 -0
- package/dist/spend.mjs +107 -0
- package/dist/spend.mjs.map +1 -0
- package/package.json +7 -1
- package/dist/client-eE9nTfvp.d.mts +0 -2483
- package/dist/client-eE9nTfvp.d.ts +0 -2483
|
@@ -0,0 +1,1593 @@
|
|
|
1
|
+
import { PermissionProfileFile } from '@granular-software/policy-engine';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @module @granular-software/sdk/types
|
|
5
|
+
* Type definitions for the Granular SDK
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for the Granular client
|
|
10
|
+
*/
|
|
11
|
+
type AccessTokenProvider = () => Promise<string | null | undefined> | string | null | undefined;
|
|
12
|
+
type EndpointMode = "auto" | "local" | "production";
|
|
13
|
+
interface GranularOptions {
|
|
14
|
+
/** Your Granular API key (for service/CLI auth; use with GRANULAR_API_KEY) */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** Application/session JWT (for user-context auth; use from simulator or getAccessToken) */
|
|
17
|
+
token?: string;
|
|
18
|
+
/** Optional provider used to refresh JWT before WebSocket (re)connect attempts */
|
|
19
|
+
tokenProvider?: AccessTokenProvider;
|
|
20
|
+
/** Optional API URL (for on-prem or testing) */
|
|
21
|
+
apiUrl?: string;
|
|
22
|
+
/** Optional live effect-host WebSocket/base URL override (for local/on-prem routing) */
|
|
23
|
+
effectHostUrl?: string;
|
|
24
|
+
/** Optional endpoint mode when apiUrl is not explicitly provided */
|
|
25
|
+
endpointMode?: EndpointMode;
|
|
26
|
+
/** Optional WebSocket constructor (for Node.js environments) */
|
|
27
|
+
WebSocketCtor?: any;
|
|
28
|
+
/**
|
|
29
|
+
* Optional callback invoked when a connected WebSocket closes unexpectedly.
|
|
30
|
+
* Useful for forwarding close diagnostics to monitoring (e.g., Sentry).
|
|
31
|
+
*/
|
|
32
|
+
onUnexpectedClose?: (info: WSDisconnectInfo) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Optional callback invoked when automatic reconnect fails.
|
|
35
|
+
* Useful to capture auth or gateway rejection causes.
|
|
36
|
+
*/
|
|
37
|
+
onReconnectError?: (info: WSReconnectErrorInfo) => void;
|
|
38
|
+
}
|
|
39
|
+
/** Resolved auth credential: either apiKey or token must be provided */
|
|
40
|
+
type GranularAuth = string;
|
|
41
|
+
/**
|
|
42
|
+
* A user/subject object returned from recordUser()
|
|
43
|
+
*/
|
|
44
|
+
interface User {
|
|
45
|
+
/** Internal Granular user identifier */
|
|
46
|
+
granularId: string;
|
|
47
|
+
/** External user identifier from your app */
|
|
48
|
+
userId: string;
|
|
49
|
+
/** @deprecated Use `granularId` instead */
|
|
50
|
+
subjectId: string;
|
|
51
|
+
/** @deprecated Use `userId` instead */
|
|
52
|
+
identityId: string;
|
|
53
|
+
/** User's display name */
|
|
54
|
+
name?: string;
|
|
55
|
+
/** User's email */
|
|
56
|
+
email?: string;
|
|
57
|
+
/** Permission profile IDs to be assigned when connecting */
|
|
58
|
+
permissions: string[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Options for recording a user
|
|
62
|
+
*/
|
|
63
|
+
interface RecordUserOptions {
|
|
64
|
+
/** External user/identity ID (e.g. your Auth0 or database user ID) */
|
|
65
|
+
userId: string;
|
|
66
|
+
/** User's display name */
|
|
67
|
+
name?: string;
|
|
68
|
+
/** User's email */
|
|
69
|
+
email?: string;
|
|
70
|
+
/** Permission profile IDs to assign when connecting to sandboxes */
|
|
71
|
+
permissions?: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Subject as returned from the API
|
|
75
|
+
*/
|
|
76
|
+
interface Subject {
|
|
77
|
+
/** Internal Granular user identifier */
|
|
78
|
+
granularId: string;
|
|
79
|
+
/** External user identifier from your app */
|
|
80
|
+
userId: string;
|
|
81
|
+
subjectId: string;
|
|
82
|
+
tenantId: string;
|
|
83
|
+
identityId: string;
|
|
84
|
+
email?: string | null;
|
|
85
|
+
name?: string | null;
|
|
86
|
+
metadata?: Record<string, unknown>;
|
|
87
|
+
createdAt: number;
|
|
88
|
+
updatedAt: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for opening an ontology environment for one delegated subject.
|
|
92
|
+
*
|
|
93
|
+
* This does not open a live runtime session. Use
|
|
94
|
+
* `environment.sessions.create()` or `granular.createSession({ environmentId })`
|
|
95
|
+
* when you need a conversation/session with jobs, prompts, heap, and effects.
|
|
96
|
+
*/
|
|
97
|
+
interface OpenEnvironmentOptions {
|
|
98
|
+
/** The ontology name or ID to open. */
|
|
99
|
+
ontology: string;
|
|
100
|
+
/** Version channel to follow, typically `dev` or `prod`. */
|
|
101
|
+
tag?: string;
|
|
102
|
+
/**
|
|
103
|
+
* External user identifier from your app.
|
|
104
|
+
*
|
|
105
|
+
* Exactly one of `userId`, `granularId`, or `user` should be provided.
|
|
106
|
+
*/
|
|
107
|
+
userId?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Internal Granular user identifier.
|
|
110
|
+
*
|
|
111
|
+
* Exactly one of `userId`, `granularId`, or `user` should be provided.
|
|
112
|
+
*/
|
|
113
|
+
granularId?: string;
|
|
114
|
+
/** Optional display name used when upserting the user. */
|
|
115
|
+
name?: string;
|
|
116
|
+
/** Optional email used when upserting the user. */
|
|
117
|
+
email?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Permission profile names or IDs to ensure before opening the environment.
|
|
120
|
+
* This should be provided even for existing users so the SDK can guarantee
|
|
121
|
+
* assignments for first-time environment creation.
|
|
122
|
+
*/
|
|
123
|
+
permissions: string[];
|
|
124
|
+
/**
|
|
125
|
+
* When true, if the latest environment for this ontology/user/tag is marked
|
|
126
|
+
* outdated relative to the current tag target, create a fresh environment on
|
|
127
|
+
* the newest tag target instead of reusing the outdated one.
|
|
128
|
+
*/
|
|
129
|
+
createFreshIfOutdated?: boolean;
|
|
130
|
+
/** Backwards-compatible user object returned from `recordUser()`. */
|
|
131
|
+
user?: User;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Deprecated compatibility alias for the legacy `connect()` entry point.
|
|
135
|
+
*
|
|
136
|
+
* `connect()` now resolves an environment handle and no longer opens a runtime
|
|
137
|
+
* session automatically. Prefer `openEnvironment()` for new code.
|
|
138
|
+
*/
|
|
139
|
+
interface ConnectOptions extends OpenEnvironmentOptions {
|
|
140
|
+
/** @deprecated Legacy explicit environment slot name. Prefer `tag`. */
|
|
141
|
+
environment?: string;
|
|
142
|
+
/** @deprecated Legacy tag field. Prefer `tag`. */
|
|
143
|
+
tagName?: string;
|
|
144
|
+
/** @deprecated Ignored by `connect()` now that it no longer opens sessions. */
|
|
145
|
+
clientId?: string;
|
|
146
|
+
/**
|
|
147
|
+
* @deprecated Ignored by `connect()` now that it no longer opens sessions.
|
|
148
|
+
* Uses application record identity: class name plus the record id from the
|
|
149
|
+
* customer's own system. Granular resolves the internal graph path.
|
|
150
|
+
*/
|
|
151
|
+
initialHeap?: Array<{
|
|
152
|
+
className: string;
|
|
153
|
+
id: string;
|
|
154
|
+
}>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Options for creating a live runtime session from an opened environment.
|
|
158
|
+
*/
|
|
159
|
+
interface CreateSessionOptions {
|
|
160
|
+
/** Optional stable client ID. Defaults to `client_${Date.now()}`. */
|
|
161
|
+
clientId?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Optional session heap seed. Each item uses application record identity:
|
|
164
|
+
* class name plus the record id from the customer's own system. Granular
|
|
165
|
+
* resolves and hydrates the corresponding internal graph record on connect.
|
|
166
|
+
*/
|
|
167
|
+
initialHeap?: Array<{
|
|
168
|
+
className: string;
|
|
169
|
+
id: string;
|
|
170
|
+
}>;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Control-plane session row: one real-time conversation thread with the agent for an environment.
|
|
174
|
+
*/
|
|
175
|
+
interface ConversationSessionInfo {
|
|
176
|
+
sessionId: string;
|
|
177
|
+
tenantId?: string;
|
|
178
|
+
environmentId: string;
|
|
179
|
+
versionId?: string | null;
|
|
180
|
+
docId: string;
|
|
181
|
+
status: "active" | "closed" | "expired";
|
|
182
|
+
createdAt: string;
|
|
183
|
+
lastSeenAt: string;
|
|
184
|
+
summary?: string | null;
|
|
185
|
+
summaryUpdatedAt?: string | null;
|
|
186
|
+
subjectId?: string | null;
|
|
187
|
+
jobCount?: number;
|
|
188
|
+
toolCallCount?: number;
|
|
189
|
+
}
|
|
190
|
+
type SpendLineItemType = "llm_tokens" | "granular_session_time" | string;
|
|
191
|
+
type QuotaScopeType = "tenant" | "sandbox" | "permission_profile" | "subject";
|
|
192
|
+
type QuotaPeriod = "hour" | "day" | "week" | "month";
|
|
193
|
+
type QuotaStatus = "active" | "paused" | "archived";
|
|
194
|
+
interface SpendSummary {
|
|
195
|
+
amountMicros: number;
|
|
196
|
+
inputTokens: number;
|
|
197
|
+
outputTokens: number;
|
|
198
|
+
cachedInputTokens: number;
|
|
199
|
+
reasoningTokens: number;
|
|
200
|
+
quantity: number;
|
|
201
|
+
eventCount: number;
|
|
202
|
+
}
|
|
203
|
+
interface QuotaLineItemFilter {
|
|
204
|
+
lineItemTypes?: string[];
|
|
205
|
+
sources?: string[];
|
|
206
|
+
providers?: string[];
|
|
207
|
+
models?: string[];
|
|
208
|
+
}
|
|
209
|
+
interface GranularQuotaPolicy {
|
|
210
|
+
quotaId: string;
|
|
211
|
+
tenantId: string;
|
|
212
|
+
scopeType: QuotaScopeType;
|
|
213
|
+
sandboxId: string | null;
|
|
214
|
+
permissionProfileId: string | null;
|
|
215
|
+
subjectId: string | null;
|
|
216
|
+
period: QuotaPeriod;
|
|
217
|
+
limitAmountMicros: number;
|
|
218
|
+
currency: string;
|
|
219
|
+
lineItemFilter: QuotaLineItemFilter | null;
|
|
220
|
+
status: QuotaStatus;
|
|
221
|
+
description: string | null;
|
|
222
|
+
createdBy: string | null;
|
|
223
|
+
startsAt: number | null;
|
|
224
|
+
endsAt: number | null;
|
|
225
|
+
createdAt: number;
|
|
226
|
+
updatedAt: number;
|
|
227
|
+
}
|
|
228
|
+
interface GranularQuotaProgress {
|
|
229
|
+
unlimited: boolean;
|
|
230
|
+
allowed: boolean;
|
|
231
|
+
blocked: boolean;
|
|
232
|
+
policy: GranularQuotaPolicy | null;
|
|
233
|
+
period: QuotaPeriod | null;
|
|
234
|
+
periodStart: number | null;
|
|
235
|
+
periodEnd: number | null;
|
|
236
|
+
usedAmountMicros: number;
|
|
237
|
+
limitAmountMicros: number | null;
|
|
238
|
+
remainingAmountMicros: number | null;
|
|
239
|
+
percentUsed: number | null;
|
|
240
|
+
currency: string;
|
|
241
|
+
summary: SpendSummary;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* A sandbox container
|
|
245
|
+
*/
|
|
246
|
+
interface Sandbox {
|
|
247
|
+
sandboxId: string;
|
|
248
|
+
tenantId: string;
|
|
249
|
+
name: string;
|
|
250
|
+
description?: string | null;
|
|
251
|
+
createdAt: number;
|
|
252
|
+
updatedAt: number;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Data for creating a new sandbox
|
|
256
|
+
*/
|
|
257
|
+
interface CreateSandboxData {
|
|
258
|
+
name: string;
|
|
259
|
+
description?: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* List response for sandboxes
|
|
263
|
+
*/
|
|
264
|
+
interface SandboxListResponse {
|
|
265
|
+
items: Sandbox[];
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Rules defining what effects and resources are allowed or denied.
|
|
269
|
+
*/
|
|
270
|
+
interface PermissionRules {
|
|
271
|
+
/** Effect access rules */
|
|
272
|
+
effects?: {
|
|
273
|
+
/** Patterns for allowed effects (e.g. ["*"] for all, ["read_*"] for prefix match) */
|
|
274
|
+
allow?: string[];
|
|
275
|
+
/** Patterns for denied effects */
|
|
276
|
+
deny?: string[];
|
|
277
|
+
};
|
|
278
|
+
/** Legacy alias accepted by the backend while migrating to `effects`. */
|
|
279
|
+
tools?: {
|
|
280
|
+
/** Patterns for allowed effects (e.g. ["*"] for all, ["read_*"] for prefix match) */
|
|
281
|
+
allow?: string[];
|
|
282
|
+
/** Patterns for denied effects */
|
|
283
|
+
deny?: string[];
|
|
284
|
+
};
|
|
285
|
+
/** Resource access rules */
|
|
286
|
+
resources?: {
|
|
287
|
+
/** Patterns for allowed resources */
|
|
288
|
+
allow?: string[];
|
|
289
|
+
/** Patterns for denied resources */
|
|
290
|
+
deny?: string[];
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* A permission profile defines access controls for an environment
|
|
295
|
+
*/
|
|
296
|
+
interface PermissionProfile {
|
|
297
|
+
permissionProfileId: string;
|
|
298
|
+
sandboxId: string;
|
|
299
|
+
name: string;
|
|
300
|
+
description?: string;
|
|
301
|
+
rules?: PermissionProfileFile;
|
|
302
|
+
profile?: PermissionProfileFile;
|
|
303
|
+
createdAt: number;
|
|
304
|
+
updatedAt: number;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Data for creating a new permission profile
|
|
308
|
+
*/
|
|
309
|
+
interface CreatePermissionProfileData {
|
|
310
|
+
name: string;
|
|
311
|
+
rules: PermissionProfileFile;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* List response for permission profiles
|
|
315
|
+
*/
|
|
316
|
+
interface PermissionProfileListResponse {
|
|
317
|
+
items: PermissionProfile[];
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* An assignment links a subject to a sandbox with a permission profile
|
|
321
|
+
*/
|
|
322
|
+
interface Assignment {
|
|
323
|
+
assignmentId: string;
|
|
324
|
+
tenantId: string;
|
|
325
|
+
subjectId: string;
|
|
326
|
+
sandboxId: string;
|
|
327
|
+
permissionProfileId: string;
|
|
328
|
+
createdAt: number;
|
|
329
|
+
createdBy?: string | null;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* List response for assignments
|
|
333
|
+
*/
|
|
334
|
+
interface AssignmentListResponse {
|
|
335
|
+
items: Assignment[];
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Version tracking policy for environments.
|
|
339
|
+
*
|
|
340
|
+
* Environments either follow a version tag such as `dev` or `prod`, or they
|
|
341
|
+
* pin themselves to one immutable ontology version.
|
|
342
|
+
*/
|
|
343
|
+
interface BuildPolicy {
|
|
344
|
+
mode: "tag" | "current" | "pinned";
|
|
345
|
+
buildId?: string;
|
|
346
|
+
versionId?: string;
|
|
347
|
+
tagId?: string;
|
|
348
|
+
tagName?: string;
|
|
349
|
+
}
|
|
350
|
+
type VersionTracking = BuildPolicy;
|
|
351
|
+
interface VersionTag {
|
|
352
|
+
tagId: string;
|
|
353
|
+
sandboxId: string;
|
|
354
|
+
name: string;
|
|
355
|
+
kind: "channel" | "release" | "system";
|
|
356
|
+
targetBuildId?: string | null;
|
|
357
|
+
targetVersionId?: string | null;
|
|
358
|
+
description?: string | null;
|
|
359
|
+
protected?: boolean;
|
|
360
|
+
createdAt: number;
|
|
361
|
+
updatedAt: number;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* An environment links a user (subject) to a sandbox with specific permissions
|
|
365
|
+
*/
|
|
366
|
+
interface EnvironmentData {
|
|
367
|
+
environmentId: string;
|
|
368
|
+
sandboxId: string;
|
|
369
|
+
ontologyId?: string;
|
|
370
|
+
buildId: string;
|
|
371
|
+
versionNumber?: number | null;
|
|
372
|
+
versionId: string;
|
|
373
|
+
subjectId: string;
|
|
374
|
+
envName: string;
|
|
375
|
+
environment?: string;
|
|
376
|
+
permissionProfileId: string;
|
|
377
|
+
tagId?: string | null;
|
|
378
|
+
tag?: VersionTag | null;
|
|
379
|
+
tracking?: BuildPolicy;
|
|
380
|
+
buildPolicy: BuildPolicy;
|
|
381
|
+
setup?: EnvironmentSetupSummary | null;
|
|
382
|
+
updateState?: "up_to_date" | "update_available" | "upgrading" | "failed";
|
|
383
|
+
createdAt: number;
|
|
384
|
+
updatedAt: number;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Data for creating a new environment
|
|
388
|
+
*/
|
|
389
|
+
interface CreateEnvironmentData {
|
|
390
|
+
/** The user/subject ID to create the environment for */
|
|
391
|
+
subjectId: string;
|
|
392
|
+
/** Named environment slot such as dev or prod */
|
|
393
|
+
environment?: string;
|
|
394
|
+
/** @deprecated Use `environment` instead. */
|
|
395
|
+
envName?: string;
|
|
396
|
+
/** The permission profile to apply (optional - uses assignment if not specified) */
|
|
397
|
+
permissionProfileId?: string | null;
|
|
398
|
+
/** Follow a tag directly */
|
|
399
|
+
tagId?: string;
|
|
400
|
+
/** Follow a tag by name, typically dev or prod */
|
|
401
|
+
tagName?: string;
|
|
402
|
+
/** Pin the environment to a specific version */
|
|
403
|
+
versionId?: string;
|
|
404
|
+
/** Legacy/compat environment tracking input */
|
|
405
|
+
buildPolicy?: BuildPolicy;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* List response for environments
|
|
409
|
+
*/
|
|
410
|
+
interface EnvironmentListResponse {
|
|
411
|
+
items: EnvironmentData[];
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* A manifest describes the structure and behavior of a sandbox
|
|
415
|
+
*/
|
|
416
|
+
interface Manifest {
|
|
417
|
+
manifestId: string;
|
|
418
|
+
sandboxId: string;
|
|
419
|
+
version: string;
|
|
420
|
+
digest: string;
|
|
421
|
+
content?: Record<string, unknown>;
|
|
422
|
+
createdAt: number;
|
|
423
|
+
locked?: boolean;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* List response for manifests
|
|
427
|
+
*/
|
|
428
|
+
interface ManifestListResponse {
|
|
429
|
+
items: Manifest[];
|
|
430
|
+
}
|
|
431
|
+
type BuildStatus = "queued" | "building" | "completed" | "failed" | "canceled";
|
|
432
|
+
/**
|
|
433
|
+
* An immutable ontology version derived from a specific manifest revision.
|
|
434
|
+
*
|
|
435
|
+
* The same version may have multiple build runs over time when the manifest
|
|
436
|
+
* content is unchanged but the compilation process is re-executed.
|
|
437
|
+
*/
|
|
438
|
+
interface Build {
|
|
439
|
+
buildId: string;
|
|
440
|
+
sandboxId: string;
|
|
441
|
+
manifestId: string;
|
|
442
|
+
manifestDigest?: string;
|
|
443
|
+
versionNumber?: number;
|
|
444
|
+
status: BuildStatus;
|
|
445
|
+
graphBinaryId?: string | null;
|
|
446
|
+
logsUri?: string | null;
|
|
447
|
+
latestBuildRunId?: string | null;
|
|
448
|
+
buildRunId?: string;
|
|
449
|
+
createdNewVersion?: boolean;
|
|
450
|
+
environmentCount?: number;
|
|
451
|
+
laggingEnvironmentCount?: number;
|
|
452
|
+
sessionCount?: number;
|
|
453
|
+
createdAt: number;
|
|
454
|
+
updatedAt: number;
|
|
455
|
+
isCurrent?: boolean;
|
|
456
|
+
}
|
|
457
|
+
type Version = Build;
|
|
458
|
+
/**
|
|
459
|
+
* List response for versions
|
|
460
|
+
*/
|
|
461
|
+
interface BuildListResponse {
|
|
462
|
+
items: Build[];
|
|
463
|
+
}
|
|
464
|
+
interface SemanticVersionDiffEntry {
|
|
465
|
+
operationId: string;
|
|
466
|
+
kind: "create" | "update" | "relationship" | "effect" | "eventStream" | "unknown";
|
|
467
|
+
changeType: "added" | "removed" | "changed";
|
|
468
|
+
label: string;
|
|
469
|
+
additive: boolean;
|
|
470
|
+
breaking: boolean;
|
|
471
|
+
before?: Record<string, unknown>;
|
|
472
|
+
after?: Record<string, unknown>;
|
|
473
|
+
}
|
|
474
|
+
interface SemanticVersionDiff {
|
|
475
|
+
summary: {
|
|
476
|
+
added: number;
|
|
477
|
+
removed: number;
|
|
478
|
+
changed: number;
|
|
479
|
+
additive: number;
|
|
480
|
+
breaking: number;
|
|
481
|
+
onlyAdditiveChanges: boolean;
|
|
482
|
+
};
|
|
483
|
+
entries: SemanticVersionDiffEntry[];
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Effect handler for static/global effects: receives (input, context)
|
|
487
|
+
*/
|
|
488
|
+
interface EffectHandlerContext {
|
|
489
|
+
effectClientId: string;
|
|
490
|
+
sandboxId: string;
|
|
491
|
+
environmentId: string;
|
|
492
|
+
buildId?: string;
|
|
493
|
+
buildVersionNumber?: number;
|
|
494
|
+
sessionId: string;
|
|
495
|
+
tenantId?: string;
|
|
496
|
+
principalId?: string;
|
|
497
|
+
permissionProfileId?: string;
|
|
498
|
+
user: {
|
|
499
|
+
granularId?: string;
|
|
500
|
+
userId?: string;
|
|
501
|
+
subjectId: string;
|
|
502
|
+
identityId?: string;
|
|
503
|
+
principalId?: string;
|
|
504
|
+
};
|
|
505
|
+
behaviors?: ResolvedEffectBehaviors;
|
|
506
|
+
invocation?: EffectInvocationMetadata;
|
|
507
|
+
}
|
|
508
|
+
interface ResolvedEffectPostCondition {
|
|
509
|
+
condition: string;
|
|
510
|
+
description?: string;
|
|
511
|
+
}
|
|
512
|
+
interface ResolvedEffectDryRun {
|
|
513
|
+
enabled: boolean;
|
|
514
|
+
description?: string;
|
|
515
|
+
}
|
|
516
|
+
interface ResolvedEffectReverse {
|
|
517
|
+
handler?: string;
|
|
518
|
+
description?: string;
|
|
519
|
+
}
|
|
520
|
+
interface ResolvedEffectApprovalRequired {
|
|
521
|
+
required: boolean;
|
|
522
|
+
reason?: string;
|
|
523
|
+
mode?: string;
|
|
524
|
+
}
|
|
525
|
+
interface ResolvedEffectBehaviors {
|
|
526
|
+
postCondition?: ResolvedEffectPostCondition;
|
|
527
|
+
dryRun?: ResolvedEffectDryRun;
|
|
528
|
+
reverse?: ResolvedEffectReverse;
|
|
529
|
+
approvalRequired?: ResolvedEffectApprovalRequired;
|
|
530
|
+
}
|
|
531
|
+
type EffectInvocationMode = "execute" | "dryRun" | "reverse";
|
|
532
|
+
interface EffectInvocationMetadata {
|
|
533
|
+
mode?: EffectInvocationMode;
|
|
534
|
+
reverseHandler?: string;
|
|
535
|
+
sourceEffectKey?: string;
|
|
536
|
+
sourceEffectName?: string;
|
|
537
|
+
}
|
|
538
|
+
type ToolHandler = (input: any, context: EffectHandlerContext) => Promise<unknown>;
|
|
539
|
+
/**
|
|
540
|
+
* Effect handler for instance methods: receives (objectId, input, context)
|
|
541
|
+
*/
|
|
542
|
+
type InstanceToolHandler = (id: string, input: any, context: EffectHandlerContext) => Promise<unknown>;
|
|
543
|
+
/**
|
|
544
|
+
* Effect schema for declaring or registering an effect.
|
|
545
|
+
*
|
|
546
|
+
* Effects come in three flavours:
|
|
547
|
+
*
|
|
548
|
+
* 1. **Instance methods** — set `className`, omit `static`.
|
|
549
|
+
* In the sandbox: `tolkien.get_bio({ detailed: true })`
|
|
550
|
+
* Handler signature: `(objectId: string, params: any) => any`
|
|
551
|
+
*
|
|
552
|
+
* 2. **Static methods** — set `className` + `static: true`.
|
|
553
|
+
* In the sandbox: `Author.search({ query: 'tolkien' })`
|
|
554
|
+
* Handler signature: `(params: any) => any`
|
|
555
|
+
*
|
|
556
|
+
* 3. **Global effects** — omit `className`.
|
|
557
|
+
* In the sandbox: `global_search({ query: 'rings' })`
|
|
558
|
+
* Handler signature: `(params: any) => any`
|
|
559
|
+
*
|
|
560
|
+
* Both `inputSchema` and `outputSchema` accept JSON Schema objects.
|
|
561
|
+
* The `outputSchema` drives the return type in the auto-generated
|
|
562
|
+
* TypeScript declarations that sandbox code imports from `./sandbox-tools`.
|
|
563
|
+
*/
|
|
564
|
+
interface ToolSchema {
|
|
565
|
+
effectKey?: string;
|
|
566
|
+
name: string;
|
|
567
|
+
description: string;
|
|
568
|
+
/** JSON Schema for the effect input parameters */
|
|
569
|
+
inputSchema: Record<string, unknown>;
|
|
570
|
+
/**
|
|
571
|
+
* JSON Schema for the tool's return value.
|
|
572
|
+
* Used to generate typed return types in the sandbox TypeScript declarations.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* outputSchema: {
|
|
577
|
+
* type: 'object',
|
|
578
|
+
* properties: {
|
|
579
|
+
* bio: { type: 'string', description: 'The biography text' },
|
|
580
|
+
* source: { type: 'string', description: 'Source of the bio' },
|
|
581
|
+
* },
|
|
582
|
+
* required: ['bio'],
|
|
583
|
+
* }
|
|
584
|
+
* // Generates: Promise<{ bio: string; source?: string }>
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
outputSchema?: Record<string, unknown>;
|
|
588
|
+
stability?: "stable" | "experimental" | "deprecated";
|
|
589
|
+
provenance?: {
|
|
590
|
+
source: "mcp" | "custom";
|
|
591
|
+
};
|
|
592
|
+
tags?: string[];
|
|
593
|
+
/**
|
|
594
|
+
* The class this effect belongs to (e.g., `'author'`, `'book'`).
|
|
595
|
+
* When set, the effect becomes a method on the auto-generated class.
|
|
596
|
+
* Omit for global effects (standalone exported functions).
|
|
597
|
+
*/
|
|
598
|
+
className?: string;
|
|
599
|
+
/**
|
|
600
|
+
* If `true`, this is a static/class-level method (no object ID required).
|
|
601
|
+
* If `false` or omitted and `className` is set, this is an instance method
|
|
602
|
+
* that operates on a specific object (the object's real-world ID is
|
|
603
|
+
* passed as the first argument to the handler).
|
|
604
|
+
*/
|
|
605
|
+
static?: boolean;
|
|
606
|
+
/**
|
|
607
|
+
* Optional build-version selector for this live effect binding.
|
|
608
|
+
*
|
|
609
|
+
* When omitted, the binding applies to all build versions for the sandbox.
|
|
610
|
+
*/
|
|
611
|
+
versionSelector?: EffectVersionSelector;
|
|
612
|
+
/** Declarative runtime behaviors attached to the effect. */
|
|
613
|
+
metamodels?: ManifestEffectMetamodelSpec;
|
|
614
|
+
}
|
|
615
|
+
type EffectSchema = ToolSchema;
|
|
616
|
+
/**
|
|
617
|
+
* Effect with handler — what users provide to `registerEffect()`.
|
|
618
|
+
*
|
|
619
|
+
* - **Instance methods** (`className` set, `static` omitted):
|
|
620
|
+
* handler receives `(objectId: string, params: any)`
|
|
621
|
+
* - **Static methods** (`className` set, `static: true`):
|
|
622
|
+
* handler receives `(params: any)`
|
|
623
|
+
* - **Global tools** (no `className`):
|
|
624
|
+
* handler receives `(params: any)`
|
|
625
|
+
*/
|
|
626
|
+
interface ToolWithHandler extends ToolSchema {
|
|
627
|
+
handler: ToolHandler | InstanceToolHandler;
|
|
628
|
+
dryRunHandler?: ToolHandler | InstanceToolHandler;
|
|
629
|
+
reverseHandler?: ToolHandler | InstanceToolHandler;
|
|
630
|
+
}
|
|
631
|
+
type EffectWithHandler = ToolWithHandler;
|
|
632
|
+
/**
|
|
633
|
+
* Result from publishing or synchronizing effects
|
|
634
|
+
*/
|
|
635
|
+
interface PublishToolsResult {
|
|
636
|
+
accepted: boolean;
|
|
637
|
+
domainRevision: string;
|
|
638
|
+
rejected?: Array<{
|
|
639
|
+
name: string;
|
|
640
|
+
reason: string;
|
|
641
|
+
}>;
|
|
642
|
+
}
|
|
643
|
+
type PublishEffectsResult = PublishToolsResult;
|
|
644
|
+
type EffectVersionSelector = {
|
|
645
|
+
mode: "all";
|
|
646
|
+
} | {
|
|
647
|
+
mode: "exact";
|
|
648
|
+
versionNumber: number;
|
|
649
|
+
} | {
|
|
650
|
+
mode: "before";
|
|
651
|
+
versionNumber: number;
|
|
652
|
+
} | {
|
|
653
|
+
mode: "after";
|
|
654
|
+
versionNumber: number;
|
|
655
|
+
};
|
|
656
|
+
/**
|
|
657
|
+
* Domain state response
|
|
658
|
+
*/
|
|
659
|
+
interface DomainState {
|
|
660
|
+
activeDomainRevision?: string;
|
|
661
|
+
tools?: Array<{
|
|
662
|
+
name: string;
|
|
663
|
+
description?: string;
|
|
664
|
+
inputSchema?: Record<string, unknown>;
|
|
665
|
+
outputSchema?: Record<string, unknown>;
|
|
666
|
+
metamodels?: ManifestEffectMetamodelSpec;
|
|
667
|
+
}>;
|
|
668
|
+
[key: string]: unknown;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Information about a live or declared effect
|
|
672
|
+
*/
|
|
673
|
+
interface ToolInfo {
|
|
674
|
+
effectKey?: string;
|
|
675
|
+
/** Unique name of the effect */
|
|
676
|
+
name: string;
|
|
677
|
+
/** Description of what the effect does */
|
|
678
|
+
description?: string;
|
|
679
|
+
/** JSON Schema for effect input */
|
|
680
|
+
inputSchema?: Record<string, unknown>;
|
|
681
|
+
/** JSON Schema for effect output */
|
|
682
|
+
outputSchema?: Record<string, unknown>;
|
|
683
|
+
/** Client ID that published this effect (absent for domain-only entries) */
|
|
684
|
+
clientId?: string;
|
|
685
|
+
/** Whether the effect is ready for use (has a registered handler) */
|
|
686
|
+
ready: boolean;
|
|
687
|
+
/** Timestamp when the effect was published */
|
|
688
|
+
publishedAt?: number;
|
|
689
|
+
/** Class this effect belongs to (instance/static method) */
|
|
690
|
+
className?: string;
|
|
691
|
+
/** Whether this is a static method */
|
|
692
|
+
static?: boolean;
|
|
693
|
+
/** Optional build-version selector associated with the live binding. */
|
|
694
|
+
versionSelector?: EffectVersionSelector;
|
|
695
|
+
/** Declarative runtime behaviors attached to the effect. */
|
|
696
|
+
metamodels?: ManifestEffectMetamodelSpec;
|
|
697
|
+
}
|
|
698
|
+
interface EffectInfo extends ToolInfo {
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Event data when the list of available effects changes
|
|
702
|
+
*/
|
|
703
|
+
interface ToolsChangedEvent {
|
|
704
|
+
/** The current list of all available effects */
|
|
705
|
+
tools: ToolInfo[];
|
|
706
|
+
/** Names of effects that were added or updated */
|
|
707
|
+
added: string[];
|
|
708
|
+
/** Names of effects that were removed */
|
|
709
|
+
removed: string[];
|
|
710
|
+
}
|
|
711
|
+
interface EffectsChangedEvent extends ToolsChangedEvent {
|
|
712
|
+
/** The current list of all available effects */
|
|
713
|
+
effects: EffectInfo[];
|
|
714
|
+
}
|
|
715
|
+
type EffectHandler = ToolHandler;
|
|
716
|
+
type InstanceEffectHandler = InstanceToolHandler;
|
|
717
|
+
type JobStatus = "queued" | "running" | "awaitingTool" | "awaitingHuman" | "succeeded" | "failed" | "timeout" | "canceled";
|
|
718
|
+
type JobFeedbackSentiment = "good" | "bad";
|
|
719
|
+
interface JobFeedbackToolCall {
|
|
720
|
+
callId?: string;
|
|
721
|
+
toolName?: string;
|
|
722
|
+
input?: unknown;
|
|
723
|
+
output?: unknown;
|
|
724
|
+
error?: string;
|
|
725
|
+
startedAt?: number;
|
|
726
|
+
completedAt?: number;
|
|
727
|
+
durationMs?: number | null;
|
|
728
|
+
}
|
|
729
|
+
interface JobFeedbackMetadata {
|
|
730
|
+
source: "sdk";
|
|
731
|
+
status: JobStatus;
|
|
732
|
+
code: string;
|
|
733
|
+
domainRevision?: string;
|
|
734
|
+
createdAt: number;
|
|
735
|
+
startedAt?: number;
|
|
736
|
+
completedAt?: number;
|
|
737
|
+
durationMs?: number | null;
|
|
738
|
+
result?: unknown;
|
|
739
|
+
error?: string;
|
|
740
|
+
stdout: string[];
|
|
741
|
+
stderr: string[];
|
|
742
|
+
toolCalls: JobFeedbackToolCall[];
|
|
743
|
+
}
|
|
744
|
+
interface JobFeedbackInput {
|
|
745
|
+
sentiment: JobFeedbackSentiment;
|
|
746
|
+
comment?: string | null;
|
|
747
|
+
}
|
|
748
|
+
interface JobFeedbackRecord {
|
|
749
|
+
feedbackId: string;
|
|
750
|
+
tenantId?: string;
|
|
751
|
+
sessionId: string;
|
|
752
|
+
environmentId: string;
|
|
753
|
+
sandboxId?: string;
|
|
754
|
+
buildId?: string;
|
|
755
|
+
subjectId?: string;
|
|
756
|
+
jobId: string;
|
|
757
|
+
sentiment: JobFeedbackSentiment;
|
|
758
|
+
comment?: string | null;
|
|
759
|
+
metadata: JobFeedbackMetadata & Record<string, unknown>;
|
|
760
|
+
createdAt: number;
|
|
761
|
+
updatedAt: number;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Persisted feedback row listed at the environment level.
|
|
765
|
+
*/
|
|
766
|
+
interface EnvironmentFeedbackRecord {
|
|
767
|
+
feedbackId: string;
|
|
768
|
+
sessionId: string;
|
|
769
|
+
jobId: string;
|
|
770
|
+
sentiment: JobFeedbackSentiment;
|
|
771
|
+
comment?: string | null;
|
|
772
|
+
metadata?: Record<string, unknown> | null;
|
|
773
|
+
createdAt: string | null;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Result from submitting a job
|
|
777
|
+
*/
|
|
778
|
+
interface JobSubmitResult {
|
|
779
|
+
jobId: string;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Represents a job executed in the sandbox
|
|
783
|
+
*/
|
|
784
|
+
interface Job {
|
|
785
|
+
/** Unique Job ID */
|
|
786
|
+
id: string;
|
|
787
|
+
/** Current status of the job */
|
|
788
|
+
status: JobStatus;
|
|
789
|
+
/** Promise that resolves with the job result */
|
|
790
|
+
result: Promise<unknown>;
|
|
791
|
+
/** Attach user feedback to this job and persist it with job/session metadata */
|
|
792
|
+
leaveFeedback(input: JobFeedbackInput): Promise<JobFeedbackRecord>;
|
|
793
|
+
/** Subscribe to job events */
|
|
794
|
+
on(event: string, handler: (data: unknown) => void): () => void;
|
|
795
|
+
}
|
|
796
|
+
interface Prompt {
|
|
797
|
+
id: string;
|
|
798
|
+
type: "confirm" | "choice" | "input";
|
|
799
|
+
title: string;
|
|
800
|
+
message: string;
|
|
801
|
+
options?: Array<string | {
|
|
802
|
+
value: string;
|
|
803
|
+
label: string;
|
|
804
|
+
description?: string;
|
|
805
|
+
}>;
|
|
806
|
+
defaultValue?: unknown;
|
|
807
|
+
placeholder?: string;
|
|
808
|
+
allowEmpty?: boolean;
|
|
809
|
+
metadata?: Record<string, unknown>;
|
|
810
|
+
}
|
|
811
|
+
interface ConversationMessageShowRefs {
|
|
812
|
+
entryPaths?: string[];
|
|
813
|
+
listNames?: string[];
|
|
814
|
+
variableNames?: string[];
|
|
815
|
+
fileIds?: string[];
|
|
816
|
+
}
|
|
817
|
+
interface ConversationMessageInput {
|
|
818
|
+
role: "user" | "assistant";
|
|
819
|
+
content?: string;
|
|
820
|
+
show?: ConversationMessageShowRefs;
|
|
821
|
+
jobId?: string;
|
|
822
|
+
promptId?: string;
|
|
823
|
+
timestamp?: number;
|
|
824
|
+
}
|
|
825
|
+
interface ConversationAppendResult {
|
|
826
|
+
ok: boolean;
|
|
827
|
+
messageId: string;
|
|
828
|
+
timestamp: number;
|
|
829
|
+
jobId?: string;
|
|
830
|
+
promptId?: string;
|
|
831
|
+
}
|
|
832
|
+
interface SessionConversationMessage {
|
|
833
|
+
id: string;
|
|
834
|
+
role: "user" | "assistant";
|
|
835
|
+
content?: string;
|
|
836
|
+
show?: ConversationMessageShowRefs;
|
|
837
|
+
jobId?: string;
|
|
838
|
+
promptId?: string;
|
|
839
|
+
ts: number;
|
|
840
|
+
[key: string]: unknown;
|
|
841
|
+
}
|
|
842
|
+
interface SessionTimelineEvent {
|
|
843
|
+
id?: string;
|
|
844
|
+
eventId?: string;
|
|
845
|
+
kind?: string;
|
|
846
|
+
type?: string;
|
|
847
|
+
status?: string | null;
|
|
848
|
+
message?: string;
|
|
849
|
+
summary?: string;
|
|
850
|
+
title?: string;
|
|
851
|
+
ts?: number;
|
|
852
|
+
timestamp?: number;
|
|
853
|
+
at?: number;
|
|
854
|
+
createdAt?: number;
|
|
855
|
+
[key: string]: unknown;
|
|
856
|
+
}
|
|
857
|
+
type SessionFileSource = "dock" | "sdk" | "agent" | "runtime" | "processor" | "library" | "imported";
|
|
858
|
+
type SessionFileKind = "csv" | "spreadsheet" | "pdf" | "image" | "text" | "document" | "binary";
|
|
859
|
+
type SessionFileStatus = "queued" | "ready" | "processing" | "processed" | "failed" | "deleted";
|
|
860
|
+
interface SessionFileRecord {
|
|
861
|
+
fileId: string;
|
|
862
|
+
sessionId: string;
|
|
863
|
+
tenantId: string | null;
|
|
864
|
+
subjectId: string | null;
|
|
865
|
+
sandboxId: string | null;
|
|
866
|
+
environmentId: string | null;
|
|
867
|
+
filename: string;
|
|
868
|
+
safeFilename: string;
|
|
869
|
+
contentType: string;
|
|
870
|
+
byteLength: number;
|
|
871
|
+
sha256: string;
|
|
872
|
+
r2Key: string;
|
|
873
|
+
kind: SessionFileKind;
|
|
874
|
+
source: SessionFileSource;
|
|
875
|
+
status: SessionFileStatus;
|
|
876
|
+
createdAt: number;
|
|
877
|
+
updatedAt: number;
|
|
878
|
+
jobId?: string;
|
|
879
|
+
parentFileIds?: string[];
|
|
880
|
+
outputPath?: string;
|
|
881
|
+
metadata?: Record<string, unknown>;
|
|
882
|
+
}
|
|
883
|
+
interface SessionFileUploadOptions {
|
|
884
|
+
filename?: string;
|
|
885
|
+
contentType?: string;
|
|
886
|
+
source?: "dock" | "sdk" | "imported";
|
|
887
|
+
parentFileIds?: string[];
|
|
888
|
+
metadata?: Record<string, unknown>;
|
|
889
|
+
}
|
|
890
|
+
interface SessionJobRecord {
|
|
891
|
+
jobId: string;
|
|
892
|
+
status: string;
|
|
893
|
+
code?: string;
|
|
894
|
+
createdAt?: number;
|
|
895
|
+
startedAt?: number;
|
|
896
|
+
completedAt?: number;
|
|
897
|
+
durationMs?: number | null;
|
|
898
|
+
progressPercent?: number | null;
|
|
899
|
+
progressMessage?: string | null;
|
|
900
|
+
stdout?: string[];
|
|
901
|
+
stderr?: string[];
|
|
902
|
+
result?: unknown;
|
|
903
|
+
error?: string | null;
|
|
904
|
+
toolCalls?: JobFeedbackToolCall[];
|
|
905
|
+
prompts?: Record<string, unknown>;
|
|
906
|
+
actionSummary?: string[];
|
|
907
|
+
actionTrace?: Array<Record<string, unknown>>;
|
|
908
|
+
agentMessages?: Array<Record<string, unknown>>;
|
|
909
|
+
[key: string]: unknown;
|
|
910
|
+
}
|
|
911
|
+
interface SessionTranscriptEntry {
|
|
912
|
+
id: string;
|
|
913
|
+
role: "user" | "assistant";
|
|
914
|
+
content: string;
|
|
915
|
+
timestamp: number;
|
|
916
|
+
jobId?: string;
|
|
917
|
+
promptId?: string;
|
|
918
|
+
code?: string;
|
|
919
|
+
jobStatus?: string;
|
|
920
|
+
jobResultPreview?: string;
|
|
921
|
+
error?: string;
|
|
922
|
+
show?: ConversationMessageShowRefs;
|
|
923
|
+
historyContent?: string;
|
|
924
|
+
source: "conversation" | "job_code" | "job_result" | "job_prompt" | "job_agent_message";
|
|
925
|
+
}
|
|
926
|
+
type SessionHeapFieldType = "string" | "number" | "boolean" | "null" | "unknown";
|
|
927
|
+
interface SessionHeapFieldValue {
|
|
928
|
+
name: string;
|
|
929
|
+
type: SessionHeapFieldType;
|
|
930
|
+
value: string | number | boolean | null;
|
|
931
|
+
}
|
|
932
|
+
interface SessionHeapEntry {
|
|
933
|
+
path: string;
|
|
934
|
+
className: string;
|
|
935
|
+
id: string;
|
|
936
|
+
label?: string | null;
|
|
937
|
+
description?: string | null;
|
|
938
|
+
prototypes: string[];
|
|
939
|
+
fields: SessionHeapFieldValue[];
|
|
940
|
+
relatedJobIds: string[];
|
|
941
|
+
source: string;
|
|
942
|
+
createdAt: number;
|
|
943
|
+
updatedAt: number;
|
|
944
|
+
}
|
|
945
|
+
interface SessionHeapList {
|
|
946
|
+
name: string;
|
|
947
|
+
className: string;
|
|
948
|
+
paths: string[];
|
|
949
|
+
relatedJobIds: string[];
|
|
950
|
+
updatedAt: number;
|
|
951
|
+
}
|
|
952
|
+
interface SessionHeapVariable {
|
|
953
|
+
name: string;
|
|
954
|
+
kind: "entry" | "list" | "scalar";
|
|
955
|
+
entryPath?: string;
|
|
956
|
+
listName?: string;
|
|
957
|
+
value?: string | number | boolean | null;
|
|
958
|
+
className?: string;
|
|
959
|
+
updatedAt: number;
|
|
960
|
+
}
|
|
961
|
+
interface SessionHeapSnapshot {
|
|
962
|
+
entriesByPath: Record<string, SessionHeapEntry>;
|
|
963
|
+
listsByName: Record<string, SessionHeapList>;
|
|
964
|
+
variablesByName: Record<string, SessionHeapVariable>;
|
|
965
|
+
updatedAt: number;
|
|
966
|
+
}
|
|
967
|
+
interface RecordSearchResult {
|
|
968
|
+
path: string;
|
|
969
|
+
className: string;
|
|
970
|
+
id: string;
|
|
971
|
+
label: string;
|
|
972
|
+
description?: string | null;
|
|
973
|
+
fields: SessionHeapFieldValue[];
|
|
974
|
+
}
|
|
975
|
+
interface RecordSearchOptions {
|
|
976
|
+
limit?: number;
|
|
977
|
+
offset?: number;
|
|
978
|
+
classNames?: string[];
|
|
979
|
+
}
|
|
980
|
+
interface RecordMentionInput {
|
|
981
|
+
className: string;
|
|
982
|
+
id?: string;
|
|
983
|
+
path?: string;
|
|
984
|
+
}
|
|
985
|
+
interface SessionDocumentResult {
|
|
986
|
+
sessionState: Record<string, unknown> | null;
|
|
987
|
+
document: Record<string, unknown> | null;
|
|
988
|
+
savedAt: number;
|
|
989
|
+
}
|
|
990
|
+
interface SessionCollectionListOptions {
|
|
991
|
+
limit?: number;
|
|
992
|
+
cursor?: string | null;
|
|
993
|
+
}
|
|
994
|
+
interface SessionJobListOptions extends SessionCollectionListOptions {
|
|
995
|
+
status?: string | null;
|
|
996
|
+
}
|
|
997
|
+
interface SessionCollectionListResult<T = unknown> {
|
|
998
|
+
items: T[];
|
|
999
|
+
nextCursor: string | null;
|
|
1000
|
+
totalCount: number;
|
|
1001
|
+
}
|
|
1002
|
+
interface WSDisconnectInfo {
|
|
1003
|
+
code?: number;
|
|
1004
|
+
reason?: string;
|
|
1005
|
+
wasClean?: boolean;
|
|
1006
|
+
unexpected: boolean;
|
|
1007
|
+
timestamp: number;
|
|
1008
|
+
reconnectScheduled: boolean;
|
|
1009
|
+
reconnectDelayMs?: number;
|
|
1010
|
+
}
|
|
1011
|
+
interface WSReconnectErrorInfo {
|
|
1012
|
+
sessionId: string;
|
|
1013
|
+
error: string;
|
|
1014
|
+
timestamp: number;
|
|
1015
|
+
}
|
|
1016
|
+
interface WSClientOptions {
|
|
1017
|
+
url: string;
|
|
1018
|
+
sessionId: string;
|
|
1019
|
+
token: string;
|
|
1020
|
+
tokenProvider?: AccessTokenProvider;
|
|
1021
|
+
WebSocketCtor?: any;
|
|
1022
|
+
onUnexpectedClose?: (info: WSDisconnectInfo) => void;
|
|
1023
|
+
onReconnectError?: (info: WSReconnectErrorInfo) => void;
|
|
1024
|
+
}
|
|
1025
|
+
interface RPCRequest {
|
|
1026
|
+
type: "rpc";
|
|
1027
|
+
method: string;
|
|
1028
|
+
params: unknown;
|
|
1029
|
+
id: string;
|
|
1030
|
+
}
|
|
1031
|
+
interface RPCResponse {
|
|
1032
|
+
type: "rpc_result" | "rpc_error";
|
|
1033
|
+
id: string;
|
|
1034
|
+
result?: unknown;
|
|
1035
|
+
error?: {
|
|
1036
|
+
code: number;
|
|
1037
|
+
message: string;
|
|
1038
|
+
data?: unknown;
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
interface SyncMessage {
|
|
1042
|
+
type: "sync";
|
|
1043
|
+
message?: string | number[] | Uint8Array;
|
|
1044
|
+
data?: number[];
|
|
1045
|
+
}
|
|
1046
|
+
interface RPCRequestFromServer {
|
|
1047
|
+
type: "rpc";
|
|
1048
|
+
method: string;
|
|
1049
|
+
params: unknown;
|
|
1050
|
+
id: string;
|
|
1051
|
+
}
|
|
1052
|
+
interface ToolInvokeParams {
|
|
1053
|
+
callId: string;
|
|
1054
|
+
toolName: string;
|
|
1055
|
+
input: unknown;
|
|
1056
|
+
}
|
|
1057
|
+
interface ToolResultParams {
|
|
1058
|
+
callId: string;
|
|
1059
|
+
result?: unknown;
|
|
1060
|
+
error?: string | {
|
|
1061
|
+
code: string;
|
|
1062
|
+
message: string;
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* A model reference as returned from relationship queries
|
|
1067
|
+
*/
|
|
1068
|
+
interface ModelRef {
|
|
1069
|
+
path: string;
|
|
1070
|
+
label?: string;
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* Relationship info as returned from the GraphQL API.
|
|
1074
|
+
* Represents a typed, bidirectional relationship between two model types,
|
|
1075
|
+
* seen from one model's perspective.
|
|
1076
|
+
*/
|
|
1077
|
+
interface RelationshipInfo {
|
|
1078
|
+
/** Unique name of this relationship definition */
|
|
1079
|
+
name: string;
|
|
1080
|
+
/** The submodel on this model that holds the relationship */
|
|
1081
|
+
local_submodel: ModelRef;
|
|
1082
|
+
/** Whether this side is a "many" collection */
|
|
1083
|
+
local_is_many: boolean;
|
|
1084
|
+
/** The submodel on the foreign model */
|
|
1085
|
+
foreign_submodel: ModelRef;
|
|
1086
|
+
/** Whether the foreign side is a "many" collection */
|
|
1087
|
+
foreign_is_many: boolean;
|
|
1088
|
+
/** The foreign model type */
|
|
1089
|
+
foreign_model: ModelRef;
|
|
1090
|
+
/** Computed relationship kind: "one_to_one" | "one_to_many" | "many_to_one" | "many_to_many" */
|
|
1091
|
+
relationship_kind: "one_to_one" | "one_to_many" | "many_to_one" | "many_to_many";
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Options for defining a relationship between two model types
|
|
1095
|
+
*/
|
|
1096
|
+
interface DefineRelationshipOptions {
|
|
1097
|
+
/** The model to define the relationship on (the "left" / "local" type) */
|
|
1098
|
+
model: string;
|
|
1099
|
+
/** The submodel name on the local model (e.g., "books") */
|
|
1100
|
+
localSubmodel: string;
|
|
1101
|
+
/** Whether the local side is "many" */
|
|
1102
|
+
localIsMany: boolean;
|
|
1103
|
+
/** The foreign model type (e.g., "book") */
|
|
1104
|
+
foreignModel: string;
|
|
1105
|
+
/** The submodel name on the foreign model (e.g., "author") */
|
|
1106
|
+
foreignSubmodel: string;
|
|
1107
|
+
/** Whether the foreign side is "many" */
|
|
1108
|
+
foreignIsMany: boolean;
|
|
1109
|
+
/** Optional relationship name (auto-generated if omitted) */
|
|
1110
|
+
name?: string;
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Options for creating or updating a class instance in the graph.
|
|
1114
|
+
*
|
|
1115
|
+
* `recordObject` uses the graph's `instantiate` (find-or-create) semantics:
|
|
1116
|
+
* if an instance with the given `id` already exists under the class, its
|
|
1117
|
+
* fields are updated in place; otherwise a new instance is created.
|
|
1118
|
+
*/
|
|
1119
|
+
interface RecordObjectOptions {
|
|
1120
|
+
/** The class to instantiate (e.g., "author") */
|
|
1121
|
+
className: string;
|
|
1122
|
+
/**
|
|
1123
|
+
* Real-world object ID. Unique within its class, but two objects of
|
|
1124
|
+
* different classes may share the same ID. Internally the SDK derives
|
|
1125
|
+
* a unique graph path as `{className}__{id}`.
|
|
1126
|
+
*/
|
|
1127
|
+
id: string;
|
|
1128
|
+
/** Optional display label (defaults to `id`) */
|
|
1129
|
+
label?: string;
|
|
1130
|
+
/** Scalar field values to set on the instance */
|
|
1131
|
+
fields?: Record<string, string | number | boolean | null>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Relationship attachments.
|
|
1134
|
+
* Keys are relationship submodel names. Values are real-world IDs
|
|
1135
|
+
* (not graph paths) — the SDK resolves them using the foreign class
|
|
1136
|
+
* derived from the relationship definition.
|
|
1137
|
+
* - For a "one" side: pass a single target ID (string)
|
|
1138
|
+
* - For a "many" side: pass an array of target IDs
|
|
1139
|
+
*/
|
|
1140
|
+
relationships?: Record<string, string | string[]>;
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Return value from `recordObject()`
|
|
1144
|
+
*/
|
|
1145
|
+
interface RecordObjectResult {
|
|
1146
|
+
/** The internal graph path (e.g., "author__tolkien") */
|
|
1147
|
+
path: string;
|
|
1148
|
+
/** The real-world object ID as provided by the caller (e.g., "tolkien") */
|
|
1149
|
+
id: string;
|
|
1150
|
+
/** Whether the instance was newly created (false = updated) */
|
|
1151
|
+
created: boolean;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Metadata for one completed HTTP chunk in `recordObjects()`.
|
|
1155
|
+
* Chunk indices follow input order; when concurrency is greater than 1, completion order may differ.
|
|
1156
|
+
*/
|
|
1157
|
+
interface RecordObjectsChunkInfo {
|
|
1158
|
+
/** Zero-based chunk index */
|
|
1159
|
+
chunkIndex: number;
|
|
1160
|
+
totalChunks: number;
|
|
1161
|
+
/** Zero-based offset into the original `records` array */
|
|
1162
|
+
offset: number;
|
|
1163
|
+
/** Number of records in this chunk */
|
|
1164
|
+
recordCount: number;
|
|
1165
|
+
/** Wall time for this chunk’s POST (including retries) */
|
|
1166
|
+
durationMs: number;
|
|
1167
|
+
/** Acknowledgements for this chunk, in the same order as the slice sent */
|
|
1168
|
+
results: RecordObjectResult[];
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Optional tuning for `recordObjects()` — batching, parallelism, and progress hooks.
|
|
1172
|
+
*/
|
|
1173
|
+
interface RecordObjectsOptions {
|
|
1174
|
+
/**
|
|
1175
|
+
* Max records per HTTP POST to the control-plane batch endpoint. Default 100.
|
|
1176
|
+
* Smaller values: more round trips and finer `onChunkComplete` updates.
|
|
1177
|
+
* Larger values: fewer requests (watch request size/timeouts).
|
|
1178
|
+
*/
|
|
1179
|
+
batchSize?: number;
|
|
1180
|
+
/**
|
|
1181
|
+
* How many chunk POSTs may run concurrently. Default 1 (strictly sequential).
|
|
1182
|
+
* Values above 1 can reduce wall time when the server can overlap work; capped at 16.
|
|
1183
|
+
*/
|
|
1184
|
+
concurrency?: number;
|
|
1185
|
+
/**
|
|
1186
|
+
* Called after each chunk succeeds (after retries). Useful for UI progress bars.
|
|
1187
|
+
*/
|
|
1188
|
+
onChunkComplete?: (info: RecordObjectsChunkInfo) => void | Promise<void>;
|
|
1189
|
+
}
|
|
1190
|
+
type RecordImportWriteMode = "adaptive" | "batched" | "per_record" | "parallel_5";
|
|
1191
|
+
interface RecordImportOptions {
|
|
1192
|
+
batchSize?: number;
|
|
1193
|
+
setupRunId?: string;
|
|
1194
|
+
writeMode?: RecordImportWriteMode;
|
|
1195
|
+
}
|
|
1196
|
+
type RecordImportStatus = "queued" | "processing" | "completed" | "failed" | "canceled";
|
|
1197
|
+
type RecordImportItemStatus = "queued" | "processing" | "completed" | "failed" | "canceled";
|
|
1198
|
+
interface RecordImportStats {
|
|
1199
|
+
totalRecords: number;
|
|
1200
|
+
queuedRecords: number;
|
|
1201
|
+
processingRecords: number;
|
|
1202
|
+
completedRecords: number;
|
|
1203
|
+
failedRecords: number;
|
|
1204
|
+
canceledRecords: number;
|
|
1205
|
+
awaitingRecords: number;
|
|
1206
|
+
}
|
|
1207
|
+
interface RecordImportItem {
|
|
1208
|
+
itemId: string;
|
|
1209
|
+
importId: string;
|
|
1210
|
+
tenantId: string;
|
|
1211
|
+
environmentId: string;
|
|
1212
|
+
className: string;
|
|
1213
|
+
id: string;
|
|
1214
|
+
label: string | null;
|
|
1215
|
+
fields: Record<string, string | number | boolean | null> | null;
|
|
1216
|
+
relationships: Record<string, string | string[]> | null;
|
|
1217
|
+
status: RecordImportItemStatus;
|
|
1218
|
+
attempts: number;
|
|
1219
|
+
errorMessage: string | null;
|
|
1220
|
+
resultPath: string | null;
|
|
1221
|
+
resultCreated: boolean | null;
|
|
1222
|
+
createdAt: number;
|
|
1223
|
+
updatedAt: number;
|
|
1224
|
+
processedAt: number | null;
|
|
1225
|
+
}
|
|
1226
|
+
interface RecordImport {
|
|
1227
|
+
importId: string;
|
|
1228
|
+
tenantId: string;
|
|
1229
|
+
environmentId: string;
|
|
1230
|
+
sandboxId: string;
|
|
1231
|
+
subjectId: string;
|
|
1232
|
+
setupRunId?: string | null;
|
|
1233
|
+
status: RecordImportStatus;
|
|
1234
|
+
batchSize: number;
|
|
1235
|
+
errorMessage: string | null;
|
|
1236
|
+
createdAt: number;
|
|
1237
|
+
updatedAt: number;
|
|
1238
|
+
startedAt: number | null;
|
|
1239
|
+
finishedAt: number | null;
|
|
1240
|
+
canceledAt: number | null;
|
|
1241
|
+
stats: RecordImportStats;
|
|
1242
|
+
}
|
|
1243
|
+
interface EnvironmentRecordImportSummary extends RecordImportStats {
|
|
1244
|
+
environmentId: string;
|
|
1245
|
+
totalImports: number;
|
|
1246
|
+
activeImports: number;
|
|
1247
|
+
updatedAt: number;
|
|
1248
|
+
}
|
|
1249
|
+
type EnvironmentSetupTriggerReason = "new_environment" | "fresh_after_version_update";
|
|
1250
|
+
interface RunEnvironmentImporterOptions {
|
|
1251
|
+
/**
|
|
1252
|
+
* Ontology name/id used to resolve the registered importer. Defaults to the
|
|
1253
|
+
* environment sandbox id.
|
|
1254
|
+
*/
|
|
1255
|
+
ontology?: string;
|
|
1256
|
+
/**
|
|
1257
|
+
* Reason recorded on the setup run. Defaults to `new_environment`.
|
|
1258
|
+
*/
|
|
1259
|
+
reason?: EnvironmentSetupTriggerReason;
|
|
1260
|
+
}
|
|
1261
|
+
type EnvironmentSetupLifecycleStatus = "running" | "completed" | "failed";
|
|
1262
|
+
interface EnvironmentSetupSummary extends RecordImportStats {
|
|
1263
|
+
setupRunId: string;
|
|
1264
|
+
environmentId: string;
|
|
1265
|
+
sandboxId: string;
|
|
1266
|
+
subjectId: string;
|
|
1267
|
+
triggerReason: EnvironmentSetupTriggerReason;
|
|
1268
|
+
lifecycleStatus: EnvironmentSetupLifecycleStatus;
|
|
1269
|
+
stage: string | null;
|
|
1270
|
+
totalObjectsToImport: number;
|
|
1271
|
+
totalImports: number;
|
|
1272
|
+
activeImports: number;
|
|
1273
|
+
errorMessage: string | null;
|
|
1274
|
+
startedAt: number;
|
|
1275
|
+
hookCompletedAt: number | null;
|
|
1276
|
+
finishedAt: number | null;
|
|
1277
|
+
updatedAt: number;
|
|
1278
|
+
}
|
|
1279
|
+
interface EnvironmentImporterImportOptions {
|
|
1280
|
+
batchSize?: number;
|
|
1281
|
+
writeMode?: RecordImportWriteMode;
|
|
1282
|
+
}
|
|
1283
|
+
interface EnvironmentImporter {
|
|
1284
|
+
environmentId: string;
|
|
1285
|
+
sandboxId: string;
|
|
1286
|
+
subjectId: string;
|
|
1287
|
+
reason: EnvironmentSetupTriggerReason;
|
|
1288
|
+
incrementTotalObjectsToImportCount: (n: number) => Promise<void>;
|
|
1289
|
+
setStage: (stage: string | null) => Promise<void>;
|
|
1290
|
+
importRecords: (records: RecordObjectOptions[], options?: EnvironmentImporterImportOptions) => Promise<RecordImport>;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Property specification in a manifest operation
|
|
1294
|
+
*/
|
|
1295
|
+
interface ManifestPropertySpec {
|
|
1296
|
+
value?: string | number | boolean;
|
|
1297
|
+
ref?: string;
|
|
1298
|
+
instanceOf?: string;
|
|
1299
|
+
create?: string;
|
|
1300
|
+
has?: Record<string, ManifestPropertySpec>;
|
|
1301
|
+
type?: string;
|
|
1302
|
+
description?: string;
|
|
1303
|
+
required?: boolean;
|
|
1304
|
+
note?: string | string[];
|
|
1305
|
+
enum?: string[] | ManifestEnumRuleSpec;
|
|
1306
|
+
filterBy?: boolean | string[] | ManifestFilterBySpec;
|
|
1307
|
+
validate?: ManifestValidationRuleSpec[];
|
|
1308
|
+
}
|
|
1309
|
+
type ManifestValidationOperator = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "true" | "false" | "regex" | "contains" | "not_contains" | "starts_with" | "ends_with";
|
|
1310
|
+
interface ManifestEnumRuleSpec {
|
|
1311
|
+
values: string[];
|
|
1312
|
+
message?: string;
|
|
1313
|
+
}
|
|
1314
|
+
interface ManifestFilterBySpec {
|
|
1315
|
+
operators: string[];
|
|
1316
|
+
scalarType?: string;
|
|
1317
|
+
}
|
|
1318
|
+
interface ManifestValidationRuleSpec {
|
|
1319
|
+
operator: ManifestValidationOperator;
|
|
1320
|
+
stringValue?: string;
|
|
1321
|
+
numberValue?: number;
|
|
1322
|
+
booleanValue?: boolean;
|
|
1323
|
+
message?: string;
|
|
1324
|
+
}
|
|
1325
|
+
interface ManifestStateMachineStateSpec {
|
|
1326
|
+
name: string;
|
|
1327
|
+
isFinal?: boolean;
|
|
1328
|
+
}
|
|
1329
|
+
interface ManifestStateMachineTransitionSpec {
|
|
1330
|
+
name: string;
|
|
1331
|
+
from: string;
|
|
1332
|
+
to: string;
|
|
1333
|
+
}
|
|
1334
|
+
interface ManifestStateMachineSpec {
|
|
1335
|
+
name: string;
|
|
1336
|
+
entryState: string;
|
|
1337
|
+
states: Array<string | ManifestStateMachineStateSpec>;
|
|
1338
|
+
transitions: ManifestStateMachineTransitionSpec[];
|
|
1339
|
+
finalStates?: string[];
|
|
1340
|
+
}
|
|
1341
|
+
interface ManifestPostConditionSpec {
|
|
1342
|
+
condition: string;
|
|
1343
|
+
description?: string;
|
|
1344
|
+
}
|
|
1345
|
+
interface ManifestDryRunSpec {
|
|
1346
|
+
enabled?: boolean;
|
|
1347
|
+
description?: string;
|
|
1348
|
+
}
|
|
1349
|
+
interface ManifestReverseSpec {
|
|
1350
|
+
handler?: string;
|
|
1351
|
+
description?: string;
|
|
1352
|
+
}
|
|
1353
|
+
interface ManifestApprovalRequiredSpec {
|
|
1354
|
+
required?: boolean;
|
|
1355
|
+
reason?: string;
|
|
1356
|
+
mode?: string;
|
|
1357
|
+
}
|
|
1358
|
+
interface ManifestEffectMetamodelSpec {
|
|
1359
|
+
postCondition?: string | ManifestPostConditionSpec;
|
|
1360
|
+
dryRun?: boolean | ManifestDryRunSpec;
|
|
1361
|
+
reverse?: string | ManifestReverseSpec;
|
|
1362
|
+
approvalRequired?: boolean | ManifestApprovalRequiredSpec;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Relationship definition between two classes
|
|
1366
|
+
*/
|
|
1367
|
+
interface ManifestRelationshipDef {
|
|
1368
|
+
/** Optional name (auto-generated from left_right if omitted) */
|
|
1369
|
+
name?: string;
|
|
1370
|
+
/** Left model path */
|
|
1371
|
+
left: string;
|
|
1372
|
+
/** Right model path */
|
|
1373
|
+
right: string;
|
|
1374
|
+
/** Submodel name on the left model */
|
|
1375
|
+
leftSubmodel: string;
|
|
1376
|
+
/** Submodel name on the right model */
|
|
1377
|
+
rightSubmodel: string;
|
|
1378
|
+
/** Whether the left side is a collection */
|
|
1379
|
+
leftIsMany: boolean;
|
|
1380
|
+
/** Whether the right side is a collection */
|
|
1381
|
+
rightIsMany: boolean;
|
|
1382
|
+
}
|
|
1383
|
+
interface ManifestEffectSchema {
|
|
1384
|
+
type: string;
|
|
1385
|
+
properties?: Record<string, unknown>;
|
|
1386
|
+
required?: string[];
|
|
1387
|
+
items?: unknown;
|
|
1388
|
+
description?: string;
|
|
1389
|
+
[key: string]: unknown;
|
|
1390
|
+
}
|
|
1391
|
+
interface ManifestEffectDeclaration {
|
|
1392
|
+
name: string;
|
|
1393
|
+
description?: string;
|
|
1394
|
+
attachedClass?: string;
|
|
1395
|
+
isStatic?: boolean;
|
|
1396
|
+
inputSchema: ManifestEffectSchema;
|
|
1397
|
+
outputSchema?: ManifestEffectSchema;
|
|
1398
|
+
stability?: "stable" | "experimental" | "deprecated";
|
|
1399
|
+
tags?: string[];
|
|
1400
|
+
metamodels?: ManifestEffectMetamodelSpec;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* An event type within an event stream definition
|
|
1404
|
+
*/
|
|
1405
|
+
interface ManifestEventTypeDef {
|
|
1406
|
+
name: string;
|
|
1407
|
+
description?: string;
|
|
1408
|
+
payloadSchema: ManifestEffectSchema;
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Event stream definition for outgoing typed events
|
|
1412
|
+
*/
|
|
1413
|
+
interface ManifestEventStreamDef {
|
|
1414
|
+
name: string;
|
|
1415
|
+
description?: string;
|
|
1416
|
+
eventTypes: ManifestEventTypeDef[];
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* A single operation in a manifest volume
|
|
1420
|
+
*/
|
|
1421
|
+
interface ManifestOperation {
|
|
1422
|
+
/** Create a new model/class */
|
|
1423
|
+
create?: string;
|
|
1424
|
+
/** Target an existing model for modification */
|
|
1425
|
+
on?: string;
|
|
1426
|
+
/** Extend from a parent class */
|
|
1427
|
+
extends?: string;
|
|
1428
|
+
/** Instantiate a type */
|
|
1429
|
+
instanceOf?: string;
|
|
1430
|
+
/** Define submodels/fields */
|
|
1431
|
+
has?: Record<string, ManifestPropertySpec>;
|
|
1432
|
+
/** Advisory notes attached to the model/class itself */
|
|
1433
|
+
note?: string | string[];
|
|
1434
|
+
/** State machines attached to the created or targeted class */
|
|
1435
|
+
stateMachines?: ManifestStateMachineSpec[];
|
|
1436
|
+
/** Define a relationship between two classes */
|
|
1437
|
+
defineRelationship?: ManifestRelationshipDef;
|
|
1438
|
+
/** Declare a build-owned effect */
|
|
1439
|
+
withEffect?: ManifestEffectDeclaration;
|
|
1440
|
+
/** Define an outgoing event stream with typed events */
|
|
1441
|
+
defineEventStream?: ManifestEventStreamDef;
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* A volume in a manifest
|
|
1445
|
+
*/
|
|
1446
|
+
/**
|
|
1447
|
+
* Import descriptor for referencing modules
|
|
1448
|
+
*/
|
|
1449
|
+
interface ManifestImport {
|
|
1450
|
+
/** Alias prefix used in operations (e.g., "@std") */
|
|
1451
|
+
alias: string;
|
|
1452
|
+
/** Module name (e.g., "standard_modules") */
|
|
1453
|
+
name: string;
|
|
1454
|
+
/** Version label (e.g., "prod", "v1.2.3") */
|
|
1455
|
+
label?: string;
|
|
1456
|
+
}
|
|
1457
|
+
interface ManifestVolume {
|
|
1458
|
+
name: string;
|
|
1459
|
+
scope: "sandbox" | "build" | "user";
|
|
1460
|
+
imports?: ManifestImport[];
|
|
1461
|
+
operations: ManifestOperation[];
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* A manifest defines the structure of a sandbox's data model
|
|
1465
|
+
*/
|
|
1466
|
+
interface ManifestContent {
|
|
1467
|
+
schemaVersion: 2;
|
|
1468
|
+
name: string;
|
|
1469
|
+
description?: string;
|
|
1470
|
+
volumes: ManifestVolume[];
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Result from a GraphQL query execution
|
|
1474
|
+
*/
|
|
1475
|
+
interface GraphQLResult<T = any> {
|
|
1476
|
+
data?: T;
|
|
1477
|
+
errors?: Array<{
|
|
1478
|
+
message: string;
|
|
1479
|
+
locations?: Array<{
|
|
1480
|
+
line: number;
|
|
1481
|
+
column: number;
|
|
1482
|
+
}>;
|
|
1483
|
+
path?: Array<string | number>;
|
|
1484
|
+
extensions?: Record<string, any>;
|
|
1485
|
+
}>;
|
|
1486
|
+
}
|
|
1487
|
+
interface APIError {
|
|
1488
|
+
error: string;
|
|
1489
|
+
message?: string;
|
|
1490
|
+
}
|
|
1491
|
+
interface DeleteResponse {
|
|
1492
|
+
deleted: boolean;
|
|
1493
|
+
}
|
|
1494
|
+
interface StreamEvent {
|
|
1495
|
+
eventId: string;
|
|
1496
|
+
streamName: string;
|
|
1497
|
+
eventType: string;
|
|
1498
|
+
payload: Record<string, unknown>;
|
|
1499
|
+
environmentId: string;
|
|
1500
|
+
sessionId?: string;
|
|
1501
|
+
subjectId?: string;
|
|
1502
|
+
source: "sandbox" | "api";
|
|
1503
|
+
isAcked: boolean;
|
|
1504
|
+
createdAt: number;
|
|
1505
|
+
}
|
|
1506
|
+
interface StreamSubscription {
|
|
1507
|
+
unsubscribe(): void;
|
|
1508
|
+
}
|
|
1509
|
+
interface StreamStats {
|
|
1510
|
+
streamName: string;
|
|
1511
|
+
eventType: string;
|
|
1512
|
+
total: number;
|
|
1513
|
+
last1h: number;
|
|
1514
|
+
last24h: number;
|
|
1515
|
+
unacked: number;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
interface OpenAIModelPricing {
|
|
1519
|
+
provider: "openai";
|
|
1520
|
+
model: string;
|
|
1521
|
+
currency: "USD";
|
|
1522
|
+
inputUsdPerMillion: number;
|
|
1523
|
+
cachedInputUsdPerMillion: number;
|
|
1524
|
+
outputUsdPerMillion: number;
|
|
1525
|
+
sourceUrl: string;
|
|
1526
|
+
effectiveDate: string;
|
|
1527
|
+
}
|
|
1528
|
+
interface NormalizedOpenAIUsage {
|
|
1529
|
+
inputTokens: number;
|
|
1530
|
+
cachedInputTokens: number;
|
|
1531
|
+
uncachedInputTokens: number;
|
|
1532
|
+
outputTokens: number;
|
|
1533
|
+
reasoningTokens: number;
|
|
1534
|
+
totalTokens: number;
|
|
1535
|
+
}
|
|
1536
|
+
interface OpenAITokenSpend {
|
|
1537
|
+
provider: "openai";
|
|
1538
|
+
model: string;
|
|
1539
|
+
inputTokens: number;
|
|
1540
|
+
cachedInputTokens: number;
|
|
1541
|
+
uncachedInputTokens: number;
|
|
1542
|
+
outputTokens: number;
|
|
1543
|
+
reasoningTokens: number;
|
|
1544
|
+
totalTokens: number;
|
|
1545
|
+
amountMicros: number;
|
|
1546
|
+
currency: "USD";
|
|
1547
|
+
inputPricePerMillionMicros: number;
|
|
1548
|
+
cachedInputPricePerMillionMicros: number;
|
|
1549
|
+
outputPricePerMillionMicros: number;
|
|
1550
|
+
pricingSource: string;
|
|
1551
|
+
pricingEffectiveAt: string;
|
|
1552
|
+
usage: NormalizedOpenAIUsage;
|
|
1553
|
+
}
|
|
1554
|
+
declare const OPENAI_MODEL_PRICING_USD_PER_MILLION: Record<string, OpenAIModelPricing>;
|
|
1555
|
+
declare function getOpenAIModelPricing(model: string): OpenAIModelPricing | null;
|
|
1556
|
+
declare function normalizeOpenAIUsage(rawUsage: unknown): NormalizedOpenAIUsage;
|
|
1557
|
+
declare function calculateOpenAITokenSpend(model: string, rawUsage: unknown): OpenAITokenSpend | null;
|
|
1558
|
+
|
|
1559
|
+
interface GranularSpendContext {
|
|
1560
|
+
tenantId?: string | null;
|
|
1561
|
+
sandboxId?: string | null;
|
|
1562
|
+
environmentId?: string | null;
|
|
1563
|
+
sessionId?: string | null;
|
|
1564
|
+
subjectId?: string | null;
|
|
1565
|
+
permissionProfileId?: string | null;
|
|
1566
|
+
[key: string]: string | null | undefined;
|
|
1567
|
+
}
|
|
1568
|
+
interface OpenAIUsageSpendEvent extends OpenAITokenSpend {
|
|
1569
|
+
spendEventId?: string;
|
|
1570
|
+
source?: "openai";
|
|
1571
|
+
lineItemType?: "llm_tokens";
|
|
1572
|
+
operation?: string;
|
|
1573
|
+
requestId?: string | null;
|
|
1574
|
+
usageContext?: GranularSpendContext;
|
|
1575
|
+
rawUsage?: unknown;
|
|
1576
|
+
}
|
|
1577
|
+
interface RecordOpenAIUsageSpendOptions {
|
|
1578
|
+
apiUrl: string;
|
|
1579
|
+
token: string;
|
|
1580
|
+
usage: OpenAIUsageSpendEvent;
|
|
1581
|
+
context?: GranularSpendContext | null;
|
|
1582
|
+
metadata?: Record<string, unknown> | null;
|
|
1583
|
+
}
|
|
1584
|
+
interface RecordOpenAIUsageSpendResult {
|
|
1585
|
+
spendEventId: string;
|
|
1586
|
+
inserted: boolean;
|
|
1587
|
+
quota: GranularQuotaProgress | null;
|
|
1588
|
+
}
|
|
1589
|
+
declare function toGranularHttpBase(apiUrl: string): string;
|
|
1590
|
+
declare function buildOpenAISpendEventId(usage: Pick<OpenAIUsageSpendEvent, "requestId">, context?: GranularSpendContext): string | undefined;
|
|
1591
|
+
declare function recordOpenAIUsageSpend(options: RecordOpenAIUsageSpendOptions): Promise<RecordOpenAIUsageSpendResult>;
|
|
1592
|
+
|
|
1593
|
+
export { type PermissionProfileListResponse as $, type AccessTokenProvider as A, type QuotaPeriod as B, type ConnectOptions as C, type DomainState as D, type EndpointMode as E, type QuotaStatus as F, type GranularSpendContext as G, type SpendSummary as H, type InstanceToolHandler as I, type QuotaLineItemFilter as J, type GranularQuotaPolicy as K, type GranularQuotaProgress as L, type ManifestEffectMetamodelSpec as M, type NormalizedOpenAIUsage as N, type OpenAIModelPricing as O, type Prompt as P, type QuotaScopeType as Q, type ResolvedEffectBehaviors as R, type SessionHeapEntry as S, type ToolWithHandler as T, type User as U, type Sandbox as V, type CreateSandboxData as W, type SandboxListResponse as X, type PermissionRules as Y, type PermissionProfile as Z, type CreatePermissionProfileData as _, type EffectHandlerContext as a, type WSReconnectErrorInfo as a$, type Assignment as a0, type AssignmentListResponse as a1, type BuildPolicy as a2, type VersionTracking as a3, type VersionTag as a4, type EnvironmentData as a5, type CreateEnvironmentData as a6, type EnvironmentListResponse as a7, type Manifest as a8, type ManifestListResponse as a9, type JobFeedbackInput as aA, type JobFeedbackRecord as aB, type EnvironmentFeedbackRecord as aC, type JobSubmitResult as aD, type Job as aE, type ConversationMessageShowRefs as aF, type ConversationMessageInput as aG, type ConversationAppendResult as aH, type SessionConversationMessage as aI, type SessionTimelineEvent as aJ, type SessionFileSource as aK, type SessionFileKind as aL, type SessionFileStatus as aM, type SessionFileRecord as aN, type SessionFileUploadOptions as aO, type SessionJobRecord as aP, type SessionHeapFieldType as aQ, type SessionHeapFieldValue as aR, type SessionHeapVariable as aS, type RecordSearchResult as aT, type RecordSearchOptions as aU, type RecordMentionInput as aV, type SessionDocumentResult as aW, type SessionCollectionListOptions as aX, type SessionJobListOptions as aY, type SessionCollectionListResult as aZ, type WSDisconnectInfo as a_, type BuildStatus as aa, type Build as ab, type Version as ac, type BuildListResponse as ad, type SemanticVersionDiffEntry as ae, type SemanticVersionDiff as af, type ResolvedEffectPostCondition as ag, type ResolvedEffectDryRun as ah, type ResolvedEffectReverse as ai, type ResolvedEffectApprovalRequired as aj, type EffectInvocationMode as ak, type EffectInvocationMetadata as al, type EffectSchema as am, type EffectWithHandler as an, type PublishEffectsResult as ao, type EffectVersionSelector as ap, type ToolInfo as aq, type EffectInfo as ar, type ToolsChangedEvent as as, type EffectsChangedEvent as at, type EffectHandler as au, type InstanceEffectHandler as av, type JobStatus as aw, type JobFeedbackSentiment as ax, type JobFeedbackToolCall as ay, type JobFeedbackMetadata as az, type SessionHeapList as b, type WSClientOptions as b0, type RPCRequest as b1, type RPCResponse as b2, type SyncMessage as b3, type RPCRequestFromServer as b4, type ToolInvokeParams as b5, type ToolResultParams as b6, type ModelRef as b7, type RelationshipInfo as b8, type DefineRelationshipOptions as b9, type ManifestPostConditionSpec as bA, type ManifestDryRunSpec as bB, type ManifestReverseSpec as bC, type ManifestApprovalRequiredSpec as bD, type ManifestRelationshipDef as bE, type ManifestEffectSchema as bF, type ManifestEffectDeclaration as bG, type ManifestEventTypeDef as bH, type ManifestEventStreamDef as bI, type ManifestOperation as bJ, type ManifestImport as bK, type ManifestVolume as bL, type ManifestContent as bM, type GraphQLResult as bN, type APIError as bO, type DeleteResponse as bP, type StreamEvent as bQ, type StreamSubscription as bR, type StreamStats as bS, type RecordObjectOptions as ba, type RecordObjectResult as bb, type RecordObjectsChunkInfo as bc, type RecordObjectsOptions as bd, type RecordImportWriteMode as be, type RecordImportOptions as bf, type RecordImportStatus as bg, type RecordImportItemStatus as bh, type RecordImportStats as bi, type RecordImportItem as bj, type RecordImport as bk, type EnvironmentRecordImportSummary as bl, type EnvironmentSetupTriggerReason as bm, type RunEnvironmentImporterOptions as bn, type EnvironmentSetupLifecycleStatus as bo, type EnvironmentSetupSummary as bp, type EnvironmentImporterImportOptions as bq, type EnvironmentImporter as br, type ManifestPropertySpec as bs, type ManifestValidationOperator as bt, type ManifestEnumRuleSpec as bu, type ManifestFilterBySpec as bv, type ManifestValidationRuleSpec as bw, type ManifestStateMachineStateSpec as bx, type ManifestStateMachineTransitionSpec as by, type ManifestStateMachineSpec as bz, type SessionHeapSnapshot as c, type SessionTranscriptEntry as d, type ToolSchema as e, type PublishToolsResult as f, type ToolHandler as g, type OpenAITokenSpend as h, OPENAI_MODEL_PRICING_USD_PER_MILLION as i, getOpenAIModelPricing as j, calculateOpenAITokenSpend as k, type OpenAIUsageSpendEvent as l, type RecordOpenAIUsageSpendOptions as m, normalizeOpenAIUsage as n, type RecordOpenAIUsageSpendResult as o, buildOpenAISpendEventId as p, type GranularOptions as q, recordOpenAIUsageSpend as r, type GranularAuth as s, toGranularHttpBase as t, type RecordUserOptions as u, type Subject as v, type OpenEnvironmentOptions as w, type CreateSessionOptions as x, type ConversationSessionInfo as y, type SpendLineItemType as z };
|