@mitralab.io/sdk-core 0.3.9 → 0.3.11

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/index.d.cts CHANGED
@@ -858,6 +858,98 @@ interface ImportExecution {
858
858
  durationSeconds: number | null;
859
859
  errorMessage: string | null;
860
860
  }
861
+ /**
862
+ * Once confirmed, `TEMPORARY` expires seven days after the upload request and `PERMANENT` never
863
+ * does. Each kind has its own quota in the app and its own quota per owner; a file without an
864
+ * owner counts only toward the app's.
865
+ */
866
+ type FileKind = "TEMPORARY" | "PERMANENT";
867
+ /**
868
+ * Who gets a read link: `PRIVATE` the owner only, `RESTRICTED` the owner or a Server Function of
869
+ * the app running for a user (a public execution does not), `APP` anyone with `FILE_READ` on the
870
+ * app. A file without an owner is always `APP`.
871
+ */
872
+ type FileVisibility = "PRIVATE" | "RESTRICTED" | "APP";
873
+ /** `PENDING` until the upload is confirmed; only `READY` files can be read. */
874
+ type FileStatus = "PENDING" | "READY" | "DELETED";
875
+ type FileCreator = "USER" | "FUNCTION";
876
+ interface FileUploadInput {
877
+ /** Original file name, at most 255 characters and without control characters. */
878
+ name: string;
879
+ /** Media type such as `image/png`; storage serves the file back with it. */
880
+ contentType: string;
881
+ /** Exact size in bytes. The upload link is signed with it, so storage refuses any other size. */
882
+ sizeBytes: number;
883
+ kind: FileKind;
884
+ visibility: FileVisibility;
885
+ /**
886
+ * Server Functions only: the file belongs to the app instead of the token's user, and must be
887
+ * `APP`. Any other caller gets `400 INVALID_FILE_REQUEST`.
888
+ */
889
+ appOwned?: boolean;
890
+ }
891
+ /** A `PENDING` file and the signed link that takes its bytes. */
892
+ interface FileUpload {
893
+ fileId: string;
894
+ /** Signed storage URL. It authorizes the upload by itself, so it is never logged. */
895
+ uploadUrl: string;
896
+ /** HTTP method the upload must use. */
897
+ uploadMethod: string;
898
+ /** Headers the upload must repeat exactly, because the link is signed with them. */
899
+ uploadHeaders: Record<string, string>;
900
+ /** When the link stops accepting the upload. */
901
+ expiresAt: string;
902
+ }
903
+ interface FileMetadata {
904
+ id: string;
905
+ name: string;
906
+ contentType: string;
907
+ sizeBytes: number;
908
+ kind: FileKind;
909
+ visibility: FileVisibility;
910
+ status: FileStatus;
911
+ /**
912
+ * Null for a file of the app: one a Server Function uploaded with `appOwned`, or uploaded by a
913
+ * Server Function running without a user, such as a public execution.
914
+ */
915
+ ownerUserId: string | null;
916
+ createdBy: FileCreator;
917
+ createdAt: string;
918
+ /** Null while the file is `PENDING`. */
919
+ confirmedAt: string | null;
920
+ /**
921
+ * When the file stops answering: 24 hours after the request while `PENDING`, of either kind.
922
+ * Null only for a confirmed `PERMANENT` file.
923
+ */
924
+ expiresAt: string | null;
925
+ }
926
+ interface FileReadUrlOptions {
927
+ /**
928
+ * Requested link validity. Only `APP` files get more than the service default, up to its
929
+ * ceiling; `expiresAt` in the response carries the validity actually granted.
930
+ */
931
+ expiresInSeconds?: number;
932
+ }
933
+ interface FileReadUrl {
934
+ /** Signed storage URL that opens the file by itself, so it is never logged. */
935
+ url: string;
936
+ expiresAt: string;
937
+ }
938
+ /**
939
+ * One item per distinct `fileId`, in the order asked. A file the caller cannot read, for any
940
+ * reason, comes with `errorCode` (`NOT_FOUND`) instead of a link, without failing the others.
941
+ */
942
+ type FileReadUrlItem = {
943
+ fileId: string;
944
+ url: string;
945
+ expiresAt: string;
946
+ } | {
947
+ fileId: string;
948
+ errorCode: string;
949
+ };
950
+ interface FileReadUrls {
951
+ results: FileReadUrlItem[];
952
+ }
861
953
  interface AgentInput {
862
954
  /** Agent name, 3 to 255 characters. */
863
955
  name: string;
@@ -1059,6 +1151,26 @@ interface AgentTaskCreateInput {
1059
1151
  * agent holding a connection; mutually exclusive with `userId`.
1060
1152
  */
1061
1153
  autonomous?: boolean;
1154
+ /**
1155
+ * The chat's own instructions, added to the agent's, at most 32,768 characters. They are set
1156
+ * at creation: a chat opened without them (or with blank text) can never get them later, and
1157
+ * `agentTasks.setInstructions` refuses it with 409 `TASK_INSTRUCTIONS_NEED_A_NEW_CHAT`, unless
1158
+ * it was created with a `folderKey`. To give a chat instructions later, open it with some text
1159
+ * or with a `folderKey`.
1160
+ */
1161
+ instructions?: string;
1162
+ /**
1163
+ * Names the chat's folder on the box: 1 to 64 characters of `[A-Za-z0-9_-]`, refused with 400
1164
+ * otherwise, and fixed once the chat exists. Chats created with the same key for the same app,
1165
+ * agent and owner share one folder and one set of instructions: `instructions` sent here
1166
+ * replaces the text of all of them, and a chat created without `instructions` takes the text
1167
+ * the others have. The files are shared only among the chats that run on the same box (same
1168
+ * person, app, provider harness and credential profile): chats with the same key on different
1169
+ * boxes share the instructions but not the files. A chat with a key always has its own folder,
1170
+ * so its `instructions` come back `""` when there is no text and `agentTasks.setInstructions`
1171
+ * accepts it. An ownerless chat shares with no other.
1172
+ */
1173
+ folderKey?: string;
1062
1174
  }
1063
1175
  interface AgentTask {
1064
1176
  id: string;
@@ -1073,6 +1185,64 @@ interface AgentTask {
1073
1185
  archived: boolean;
1074
1186
  createdAt: string | null;
1075
1187
  updatedAt: string;
1188
+ /**
1189
+ * Where the chat's turn stands. Only `get` carries it, and only for a chat on an agent box:
1190
+ * absent from the listing, from the writes, from a chat on another runtime and from a Copilot
1191
+ * that predates it.
1192
+ */
1193
+ turn?: AgentTaskTurn | null;
1194
+ /**
1195
+ * The chat's own instructions. Absent on a chat created without them, which never has them,
1196
+ * unless it was created with a `folderKey`: that one always carries them, `""` or the text its
1197
+ * folder already had. Also absent from the listing and from a Copilot that predates them. `""`
1198
+ * on a chat whose text was cleared, which can get text again. A value that is not text is left
1199
+ * out, with no error. Absent from the `rename` answer too, even on a chat that has them.
1200
+ */
1201
+ instructions?: string;
1202
+ /**
1203
+ * The folder key the chat was created with, which never changes. Absent on a chat created
1204
+ * without one and from a Copilot that predates it; the listing may leave it out. A value that
1205
+ * is not text is left out, with no error.
1206
+ */
1207
+ folderKey?: string;
1208
+ }
1209
+ /**
1210
+ * Where a chat's turn stands, as the Copilot reads it without the live session. The two readings
1211
+ * behind it are not of the same instant: a turn that ends between them can show as `RUNNING` and
1212
+ * as `lastTurn` in one answer, and the next read is right.
1213
+ */
1214
+ interface AgentTaskTurn {
1215
+ /**
1216
+ * `RUNNING` with a box holding a message, `QUEUED` with messages waiting and none running,
1217
+ * `IDLE` otherwise. Open to other strings so a state the Copilot adds later still compiles.
1218
+ */
1219
+ state: "RUNNING" | "QUEUED" | "IDLE" | (string & {});
1220
+ /** The message that opened the turn that runs; null outside `RUNNING`. */
1221
+ currentTurnId: string | null;
1222
+ /** Messages waiting for a box to take them. */
1223
+ queuedCount: number;
1224
+ /** The turn that last reached a final state; null when none did, or after the retention took it. */
1225
+ lastTurn: AgentTaskLastTurn | null;
1226
+ }
1227
+ interface AgentTaskLastTurn {
1228
+ /** The message that opened the turn. */
1229
+ turnId: string;
1230
+ /** Every message the turn closed, oldest first: more than one when it took steers. */
1231
+ messageIds: string[];
1232
+ status: "COMPLETED" | "INTERRUPTED" | "FAILED" | "REJECTED" | "EXPIRED" | "LOST" | (string & {});
1233
+ /** The reason the box closed the turn with; null on a turn that ended with an error or never ran. */
1234
+ finishReason: string | null;
1235
+ /** Not a closed set: an unknown value is a generic error. Null on an end without an error. */
1236
+ errorCode: string | null;
1237
+ /** ISO instant a box took the turn's first message; null for a message no box took. */
1238
+ startedAt: string | null;
1239
+ /** ISO instant; null on a turn that ended before the Copilot recorded it. */
1240
+ endedAt: string | null;
1241
+ }
1242
+ /** One chat of `agentTasks.turnStates`; `turn` is null for a chat that does not run on an agent box. */
1243
+ interface AgentTaskTurnStateEntry {
1244
+ taskId: string;
1245
+ turn: AgentTaskTurn | null;
1076
1246
  }
1077
1247
  interface AgentTaskListOptions extends PageOptions {
1078
1248
  /** Include archived chats. Defaults to false. */
@@ -1217,6 +1387,19 @@ interface AgentTurnUsage {
1217
1387
  */
1218
1388
  contextWindow?: number;
1219
1389
  }
1390
+ /** One time the provider compacted the conversation's context during a turn, as the box sent it. */
1391
+ interface AgentTurnCompaction {
1392
+ /**
1393
+ * `manual` when the person asked for it, `auto` when the provider did it because the context
1394
+ * filled up. Open to other strings so a trigger the box adds later still compiles.
1395
+ */
1396
+ trigger: "auto" | "manual" | (string & {});
1397
+ /** The context's size before it, in tokens; null when the provider reports none. */
1398
+ tokensBefore: number | null;
1399
+ tokensAfter: number | null;
1400
+ /** ISO instant the compaction finished; null when the box did not say. */
1401
+ at: string | null;
1402
+ }
1220
1403
  interface AgentMessage {
1221
1404
  id: string;
1222
1405
  sender: string;
@@ -1597,6 +1780,29 @@ interface AgentTasksModule {
1597
1780
  * modules keep compiling; a module without it never takes the direct channel.
1598
1781
  */
1599
1782
  channel?(id: string): Promise<AgentTaskChannel | null>;
1783
+ /**
1784
+ * Reads where the turn of each chat stands without opening a session, with
1785
+ * `GET /api/v1/tasks/turn-states?taskIds=a,b`. One entry per chat the
1786
+ * caller may read, in the order asked: an id it may not read, or that does not exist, is left
1787
+ * out with no error. An id that is not a UUID is left out before the request, because the
1788
+ * Copilot refuses the whole request for one. `turn` is null for a chat that does not run on an
1789
+ * agent box. No ids, no request. Above 100 ids it asks in requests of 100, and one that fails rejects the whole call:
1790
+ * no partial answer. Optional so hand-written modules keep compiling.
1791
+ */
1792
+ turnStates?(ids: string[]): Promise<AgentTaskTurnStateEntry[]>;
1793
+ /**
1794
+ * Replaces the chat's own instructions with `PUT /api/v1/tasks/{id}/instructions`, at most
1795
+ * 32,768 characters, and answers the task. `null` or blank text clears them (`instructions`
1796
+ * comes back `""`) and the chat can get text again. Only a chat created with instructions
1797
+ * or with a `folderKey` accepts it: one created without either is refused with 409
1798
+ * `TASK_INSTRUCTIONS_NEED_A_NEW_CHAT`, and needs a new chat. Who may rename a chat may change
1799
+ * them. The box gets the new text before the chat's next turn, but the conversation under way
1800
+ * only uses it after a compaction (or in a new conversation), as with the agent's
1801
+ * instructions; to apply it at once, set it and send `/compact`. On a chat created with a
1802
+ * `folderKey` the text belongs to the folder: it changes for every chat of the same app, agent
1803
+ * and owner created with that key. Optional so hand-written modules keep compiling.
1804
+ */
1805
+ setInstructions?(id: string, instructions: string | null): Promise<AgentTask>;
1600
1806
  }
1601
1807
  declare function createAgentTasksModule(transport: Transport, errors?: SdkCoreErrorFactory): AgentTasksModule;
1602
1808
 
@@ -1867,6 +2073,95 @@ type EntitiesProxy = EntitiesModule & {
1867
2073
  };
1868
2074
  declare function createEntitiesModule(transport: Transport, errors?: SdkCoreErrorFactory): EntitiesProxy;
1869
2075
 
2076
+ /** The part of a fetch response the signed storage links need. */
2077
+ interface FilesFetchResponse {
2078
+ readonly ok: boolean;
2079
+ readonly status: number;
2080
+ /** Cancelled when the content is not read. */
2081
+ readonly body?: {
2082
+ cancel(): Promise<void>;
2083
+ } | null;
2084
+ blob(): Promise<Blob>;
2085
+ }
2086
+ type FilesFetch = (url: string, init: {
2087
+ method: string;
2088
+ headers?: Record<string, string>;
2089
+ body?: Blob;
2090
+ redirect: "error";
2091
+ signal?: AbortSignal;
2092
+ }) => Promise<FilesFetchResponse>;
2093
+ interface FilesModuleOptions {
2094
+ /**
2095
+ * fetch for the signed storage links. Defaults to `globalThis.fetch`. It must send the request
2096
+ * as given, without adding `Authorization` or any other header: the link is already the
2097
+ * credential, so a fetch that adds the app token leaks it to storage, which refuses a request
2098
+ * with a second credential, and one that sets headers can replace the ones the link was signed
2099
+ * with, such as `content-type`.
2100
+ */
2101
+ fetch?: FilesFetch;
2102
+ }
2103
+ interface FileUploadOptions {
2104
+ kind: FileKind;
2105
+ visibility: FileVisibility;
2106
+ /** Defaults to the name of a `File`; required for any other `Blob`. */
2107
+ name?: string;
2108
+ /** Defaults to the type of the `Blob`, and to `application/octet-stream` when it has none. */
2109
+ contentType?: string;
2110
+ /** Server Functions only, as in `FileUploadInput`. */
2111
+ appOwned?: boolean;
2112
+ /**
2113
+ * Aborts the upload until the bytes reach storage, and the upload then rejects with
2114
+ * `signal.reason`: before any request when it is already aborted, after deleting the `PENDING`
2115
+ * file otherwise. The API calls do not take it, so the confirmation runs to the end.
2116
+ */
2117
+ signal?: AbortSignal;
2118
+ }
2119
+ interface FileDownloadOptions {
2120
+ /**
2121
+ * Aborts the transfer of the content from storage, and the download then rejects with
2122
+ * `signal.reason`. Already aborted, it rejects before asking for the read link, which does not
2123
+ * take it.
2124
+ */
2125
+ signal?: AbortSignal;
2126
+ }
2127
+ interface FilesModule {
2128
+ /** Records a `PENDING` file and returns the signed link that takes its bytes. */
2129
+ requestUpload(input: FileUploadInput): Promise<FileUpload>;
2130
+ /**
2131
+ * Marks the file `READY` once storage holds bytes of the declared size. Only the uploader
2132
+ * confirms, and repeating it returns the same file.
2133
+ */
2134
+ confirmUpload(fileId: string): Promise<FileMetadata>;
2135
+ /**
2136
+ * Requests the upload, sends the bytes straight to storage with the method and headers the API
2137
+ * returned, and confirms. Resolves only once the file is `READY`. A failure of the request
2138
+ * propagates unchanged. When the send fails, the `PENDING` file is deleted, even if the bytes
2139
+ * may already be in storage, and an abort then rejects with `signal.reason`. Any other failure
2140
+ * after the request is a `FileTransferError` with the step and the `fileId`: a failed `send`
2141
+ * says in `cleanedUp` whether the delete worked, and a failed `confirm` keeps the file, so the
2142
+ * caller can confirm again or delete it.
2143
+ */
2144
+ upload(content: Blob, options: FileUploadOptions): Promise<FileMetadata>;
2145
+ /** Signed read link of one `READY` file the caller may read; any other file answers 404. */
2146
+ getUrl(fileId: string, options?: FileReadUrlOptions): Promise<FileReadUrl>;
2147
+ /** Signed read links of 1 to 100 files in one call, one item per distinct id. */
2148
+ getUrls(fileIds: string[], options?: FileReadUrlOptions): Promise<FileReadUrls>;
2149
+ /**
2150
+ * Asks for a read link and downloads the content from storage. A failure of the link request
2151
+ * propagates unchanged, an abort rejects with `signal.reason`, and a failed transfer is a
2152
+ * `FileTransferError` with the `download` step.
2153
+ */
2154
+ download(fileId: string, options?: FileDownloadOptions): Promise<Blob>;
2155
+ /** Metadata only, without a link. */
2156
+ get(fileId: string): Promise<FileMetadata>;
2157
+ /**
2158
+ * Deletes the file. The uploader deletes their own, `PENDING` included; a file of someone else
2159
+ * or of the app needs `FILE_DELETE`.
2160
+ */
2161
+ delete(fileId: string): Promise<void>;
2162
+ }
2163
+ declare function createFilesModule(transport: Transport, options?: FilesModuleOptions, errors?: SdkCoreErrorFactory): FilesModule;
2164
+
1870
2165
  type InvocationType = "sync" | "async";
1871
2166
  type EmptyFunctionInput = "empty-object" | "omit-body";
1872
2167
  interface FunctionsModuleOptions {
@@ -2044,6 +2339,7 @@ interface SdkCoreOptions {
2044
2339
  /** Resolves the app fixed by the concrete client without inspecting tokens in core. */
2045
2340
  getAppId?: () => string | undefined;
2046
2341
  functions?: FunctionsModuleOptions;
2342
+ files?: FilesModuleOptions;
2047
2343
  errors?: SdkCoreErrorFactory;
2048
2344
  }
2049
2345
  interface SdkCore {
@@ -2058,6 +2354,7 @@ interface SdkCore {
2058
2354
  readonly customQueries: CustomQueriesModule;
2059
2355
  readonly dataSources: DataSourcesModule;
2060
2356
  readonly entities: EntitiesProxy;
2357
+ readonly files: FilesModule;
2061
2358
  readonly functions: FunctionsModule;
2062
2359
  readonly functionsAdmin: FunctionsAdminModule;
2063
2360
  readonly imports: ImportsModule;
@@ -2134,7 +2431,9 @@ type AgentFetch = (url: string, init: {
2134
2431
 
2135
2432
  declare class AgentTaskTurnError extends Error {
2136
2433
  readonly code: string | undefined;
2137
- constructor(message: string, code?: string);
2434
+ /** The compactions of a turn the box closed with an error; empty when it reported none. */
2435
+ readonly compactions: readonly AgentTurnCompaction[];
2436
+ constructor(message: string, code?: string, compactions?: readonly AgentTurnCompaction[]);
2138
2437
  }
2139
2438
 
2140
2439
  interface AgentTaskEventObserver {
@@ -2401,6 +2700,13 @@ interface AgentTurnResult {
2401
2700
  sequence?: number;
2402
2701
  /** The `lifecycle.turnId` of that `stepFinish`. */
2403
2702
  turnId?: string;
2703
+ /**
2704
+ * The times the provider compacted the context during the turn, oldest first, as the box listed
2705
+ * them on the frame that ended it; a subagent's own compactions are not among them. The session
2706
+ * always sets it, empty for a turn that compacted nothing, for a box that does not report it and
2707
+ * for a turn closed from the history. Optional so a result built by hand keeps compiling.
2708
+ */
2709
+ compactions?: AgentTurnCompaction[];
2404
2710
  }
2405
2711
  interface AgentTaskSessionEventMap {
2406
2712
  statusChange: {
@@ -2489,10 +2795,23 @@ interface AgentTaskSessionEventMap {
2489
2795
  subagentTool: AgentToolEvent & {
2490
2796
  parentToolId: string;
2491
2797
  };
2798
+ /**
2799
+ * `compactions` comes on the error that ended a turn, and there the session always sets it, as
2800
+ * on `turnEnd`: the list the box sent with the error, empty when it sent none. An error that
2801
+ * ended no turn (a refused steer, a failure to open or to send) has no such field.
2802
+ */
2492
2803
  error: {
2493
2804
  code?: string;
2494
2805
  error: string;
2495
2806
  sequence?: number;
2807
+ compactions?: AgentTurnCompaction[];
2808
+ };
2809
+ /**
2810
+ * The provider compacted the conversation's context. On a subagent's own thread, `parentToolId`
2811
+ * is the tool call that spawned it, and the compaction is not in the turn's `compactions`.
2812
+ */
2813
+ contextCompacted: AgentTurnCompaction & AgentPieceIdentity & {
2814
+ parentToolId?: string;
2496
2815
  };
2497
2816
  /**
2498
2817
  * The subscription window the chat's harness reported during a turn. It comes only on the
@@ -2591,6 +2910,135 @@ declare function toAgentTimelineItem(message: AgentMessage): AgentTimelineItem;
2591
2910
  declare function createAgentTaskSessionManager(options: AgentTaskSessionManagerOptions): AgentTaskSessionManager;
2592
2911
  declare function withAgentTaskSessions(tasks: AgentTasksModule, manager: AgentTaskSessionManager): AgentTasksWithSessions;
2593
2912
 
2913
+ /**
2914
+ * What the Server Function of an app's agent turn hook receives as `event`: the start or the end
2915
+ * of an agent turn of a chat on an agent box, as `mitra-functions` hands it over. Every field is
2916
+ * always there and one without a value is null, so both types have the same shape.
2917
+ *
2918
+ * Delivery is at least once and out of order: the function must be idempotent by `eventId`, and
2919
+ * tell start from end by `type` and `turnId`, never by arrival. It runs as whoever configured the
2920
+ * hook, not as `userId`, who owns the chat.
2921
+ */
2922
+ type AgentTurnEvent = AgentTurnStartedEvent | AgentTurnEndedEvent;
2923
+ interface AgentTurnEventBase {
2924
+ /** The same start or end always carries the same id. */
2925
+ eventId: string;
2926
+ appId: string | null;
2927
+ /** The chat. */
2928
+ taskId: string;
2929
+ agentId: string | null;
2930
+ /** The owner of the chat; null for a chat nobody owns (autonomous agent). */
2931
+ userId: string | null;
2932
+ /**
2933
+ * The message that opened the turn. A message that never ran (refused, expired, failed before
2934
+ * any box, cancelled in the queue) is a turn of its own.
2935
+ */
2936
+ turnId: string;
2937
+ /** The id the client sent the opening message with, when it sent one. */
2938
+ clientMessageId: string | null;
2939
+ /** ISO-8601 in UTC, always with milliseconds (`2026-11-11T10:00:42.000Z`), as every date here. */
2940
+ occurredAt: string;
2941
+ }
2942
+ interface AgentTurnStartedEvent extends AgentTurnEventBase {
2943
+ type: "STARTED";
2944
+ status: null;
2945
+ finishReason: null;
2946
+ errorCode: null;
2947
+ messageIds: string[];
2948
+ startedAt: null;
2949
+ endedAt: null;
2950
+ usage: null;
2951
+ taskStateAfter: null;
2952
+ supersedes: false;
2953
+ /** Absent from a `mitra-functions` that predates it. */
2954
+ compactions?: AgentTurnEventCompaction[];
2955
+ }
2956
+ interface AgentTurnEndedEvent extends AgentTurnEventBase {
2957
+ type: "ENDED";
2958
+ /**
2959
+ * `UNKNOWN` is a status the publisher added after `mitra-functions` last read the schema. Open
2960
+ * to other strings so one the schema gains later still compiles.
2961
+ */
2962
+ status: "COMPLETED" | "INTERRUPTED" | "FAILED" | "REJECTED" | "EXPIRED" | "LOST" | "UNKNOWN" | (string & {});
2963
+ /** The reason the box closed the turn with; null on an end with an error or a message that never ran. */
2964
+ finishReason: string | null;
2965
+ /** Not a closed set: an unknown value is a generic error. Null on an end without an error. */
2966
+ errorCode: string | null;
2967
+ /** Every message this end closes, oldest first. */
2968
+ messageIds: string[];
2969
+ /** When a box took the first message of the turn; null for a message that never ran. */
2970
+ startedAt: string | null;
2971
+ endedAt: string | null;
2972
+ usage: AgentTurnEventUsage | null;
2973
+ /** Where the chat stands once this end is written. */
2974
+ taskStateAfter: "IDLE" | "QUEUED" | "RUNNING" | "UNKNOWN" | (string & {}) | null;
2975
+ /** True on the end of a turn already announced as `LOST` that the box answered after all. */
2976
+ supersedes: boolean;
2977
+ /**
2978
+ * The compactions of the turn, oldest first; empty for a turn that compacted nothing and for an
2979
+ * end no box closed. Absent from a `mitra-functions` that predates it.
2980
+ */
2981
+ compactions?: AgentTurnEventCompaction[];
2982
+ }
2983
+ /** What the turn consumed. A null field is one the provider did not report, never zero. */
2984
+ interface AgentTurnEventUsage {
2985
+ inputTokens: number | null;
2986
+ outputTokens: number | null;
2987
+ cacheReadTokens: number | null;
2988
+ cacheCreationTokens: number | null;
2989
+ model: string | null;
2990
+ /** A decimal as text, so no precision is lost. */
2991
+ costUsd: string | null;
2992
+ contextTokens: number | null;
2993
+ contextWindow: number | null;
2994
+ }
2995
+ interface AgentTurnEventCompaction {
2996
+ /** When the compaction finished; null when the box did not say. */
2997
+ at: string | null;
2998
+ /** `MANUAL` is the person asking for it, `AUTO` the provider doing it because the context filled up. */
2999
+ trigger: "AUTO" | "MANUAL" | "UNKNOWN" | (string & {});
3000
+ /** The size of the context before it, in tokens; null when the provider did not report it. */
3001
+ tokensBefore: number | null;
3002
+ tokensAfter: number | null;
3003
+ }
3004
+ /**
3005
+ * Whether a Server Function's input is an agent turn event: it checks the fields that identify
3006
+ * one, not every field of the shape.
3007
+ */
3008
+ declare function isAgentTurnEvent(value: unknown): value is AgentTurnEvent;
3009
+
3010
+ type FileTransferStep = "send" | "confirm" | "download";
3011
+ interface FileTransferErrorDetails {
3012
+ fileId: string;
3013
+ step: FileTransferStep;
3014
+ status?: number | null;
3015
+ cause?: unknown;
3016
+ cleanedUp?: boolean;
3017
+ }
3018
+ /**
3019
+ * A file upload or download that failed after the file already existed: the bytes did not reach
3020
+ * storage (`send`), the upload was not confirmed (`confirm`) or the content did not come back
3021
+ * (`download`). In `send` and `download`, `cause` is never the error of the fetch: it is a new
3022
+ * `Error` with its name, message, stack and text `code`, with the signed link, its query and each
3023
+ * long query value, raw or decoded, cut out, and its causes rebuilt the same way up to five
3024
+ * levels. In `confirm` it is the `Transport` error as it came.
3025
+ */
3026
+ declare class FileTransferError extends Error {
3027
+ readonly fileId: string;
3028
+ readonly step: FileTransferStep;
3029
+ /**
3030
+ * HTTP status storage answered in `send` and `download`; null when storage gave no status or the
3031
+ * content failed to arrive, and always in `confirm`.
3032
+ */
3033
+ readonly status: number | null;
3034
+ /**
3035
+ * True when the `PENDING` file a failed `send` left behind was deleted. False when that delete
3036
+ * failed too, and always in `confirm` and `download`, where nothing is deleted.
3037
+ */
3038
+ readonly cleanedUp: boolean;
3039
+ constructor(message: string, details: FileTransferErrorDetails);
3040
+ }
3041
+
2594
3042
  /**
2595
3043
  * What the SDKs have to know about trading an api key for a token.
2596
3044
  *
@@ -2645,4 +3093,4 @@ declare function expectPage<T extends object>(value: unknown, context: string, e
2645
3093
  declare function expectLegacyPage<T extends object>(value: unknown, context: string, errors?: SdkCoreErrorFactory, validateItem?: (value: unknown, context: string, errors: SdkCoreErrorFactory) => T): LegacyPage<T>;
2646
3094
  declare function expectEmpty(value: unknown, context: string, errors?: SdkCoreErrorFactory): void;
2647
3095
 
2648
- export { API_KEY_EXCHANGE_PATH, type AgentBackgroundTask, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentHistoryCursor, type AgentInput, type AgentMessage, type AgentMessageListOptions, type AgentModel, type AgentNotification, type AgentPieceIdentity, type AgentPlan, type AgentPlanStep, type AgentProviderUsage, type AgentQueueItem, type AgentReadyProvider, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentSubagent, type AgentSubagentFrame, type AgentSubagentStatus, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, AgentTaskTurnError, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentTimelineItemIdentity, type AgentToolEvent, type AgentTurnResult, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type AiProviders, type AiProvidersModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IncludedAiQuota, type IncludedAiQuotaWindow, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type ManagedAiProfile, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type OpencodeAiProvider, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAiProvidersModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };
3096
+ export { API_KEY_EXCHANGE_PATH, type AgentBackgroundTask, type AgentBulkDeleteResult, type AgentConnection, type AgentConnectionCreateInput, type AgentConnectionCustomProvider, type AgentConnectionCustomProviderInput, type AgentConnectionsModule, type AgentCredentialOptions, type AgentCredentialScope, type AgentCredentialsModule, type AgentDefinition, type AgentDirectChannelOptions, type AgentFetch, type AgentFetchResponse, type AgentHistoryCursor, type AgentInput, type AgentMessage, type AgentMessageListOptions, type AgentModel, type AgentNotification, type AgentPieceIdentity, type AgentPlan, type AgentPlanStep, type AgentProviderUsage, type AgentQueueItem, type AgentReadyProvider, type AgentSendAndWaitOptions, type AgentSendOptions, type AgentSessionTransport, type AgentSubagent, type AgentSubagentFrame, type AgentSubagentStatus, type AgentTask, type AgentTaskChannel, type AgentTaskCreateInput, type AgentTaskEvent, type AgentTaskEventConnection, type AgentTaskEventObserver, type AgentTaskEventSource, type AgentTaskInput, type AgentTaskLastTurn, type AgentTaskListOptions, type AgentTaskRuntime, type AgentTaskSession, type AgentTaskSessionEventMap, type AgentTaskSessionManager, type AgentTaskSessionManagerOptions, type AgentTaskSessionOptions, type AgentTaskSessionStatus, type AgentTaskTurn, AgentTaskTurnError, type AgentTaskTurnStateEntry, type AgentTasksModule, type AgentTasksWithSessions, type AgentTimelineItem, type AgentTimelineItemIdentity, type AgentToolEvent, type AgentTurnCompaction, type AgentTurnEndedEvent, type AgentTurnEvent, type AgentTurnEventCompaction, type AgentTurnEventUsage, type AgentTurnResult, type AgentTurnStartedEvent, type AgentTurnUsage, type AgentTurnUsageRequest, type AgentUpdateItem, type AgentWebSocket, type AgentWebSocketConstructor, type AgentsModule, type AiProviders, type AiProvidersModule, type ApiKeyExchangeCaller, type AppColor, type AppContext, type AppCreateInput, type AppDefinition, type AppDeploy, type AppDomain, type AppFiles, type AppGetOptions, type AppListOptions, type AppMember, type AppPublishOptions, type AppSummary, type AppUpdateInput, type AppVersion, type AppVersionStatus, type AppsModule, type AuthModule, type AuthenticationResult, type BatchExecution, type BatchStatementResult, type BulkUnsubscribeResult, type ColumnInput, type ConnectionConfig, type ConnectionConfigResponse, type ConnectionTestResult, type ContextModule, type ContextModuleDependencies, type CopilotProvider, type CredentialStatus, type CredentialUsage, type CredentialUsageWindow, type CustomQueriesModule, type CustomQueryDefinition, type CustomQueryInput, type CustomQuerySummary, type CustomQueryUpdateInput, type DataSourceBulkItemResult, type DataSourceBulkResult, type DataSourceCreateInput, type DataSourceDbType, type DataSourceDefinition, type DataSourceInstanceType, type DataSourceUpdateInput, type DataSourcesModule, type DdlStatement, type DeviceAuthorization, type DmlStatement, type EmptyFunctionInput, type EntitiesModule, type EntitiesProxy, type EntityListOptions, type EntityListResponse, type EntityTable, type ExistingAgentTaskSessionOptions, type FileCreator, type FileDownloadOptions, type FileKind, type FileMetadata, type FileReadUrl, type FileReadUrlItem, type FileReadUrlOptions, type FileReadUrls, type FileStatus, FileTransferError, type FileTransferErrorDetails, type FileTransferStep, type FileUpload, type FileUploadInput, type FileUploadOptions, type FileVisibility, type FilesFetch, type FilesFetchResponse, type FilesModule, type FilesModuleOptions, type FunctionBulkCreateInput, type FunctionBulkDeleteInput, type FunctionBulkDeleteResult, type FunctionBulkPatchInput, type FunctionBulkPatchItem, type FunctionBulkUpdateItem, type FunctionCreateInput, type FunctionDefinition, type FunctionExecution, type FunctionListOptions, type FunctionPatchInput, type FunctionRuntime, type FunctionSecrets, type FunctionSummary, type FunctionUpdateInput, type FunctionVersion, type FunctionVersionListOptions, type FunctionVisibility, type FunctionsAdminModule, type FunctionsModule, type FunctionsModuleOptions, type HttpMethod, type ImportColumnMapping, type ImportDefinition, type ImportExecution, type ImportExecutionListOptions, type ImportInput, type ImportProcessing, type ImportSchedule, type ImportSource, type ImportSourceResponse, type ImportTarget, type ImportsModule, type IncludedAiQuota, type IncludedAiQuotaWindow, type IntegrationAdminModule, type IntegrationConnectionStatus, type IntegrationCredentialRule, type IntegrationExecution, type IntegrationFieldSchema, type IntegrationFieldSchemaInput, type IntegrationLoginConfig, type IntegrationModule, type IntegrationProxyMode, type IntegrationRequestConfig, type IntegrationResource, type IntegrationResourceInput, type IntegrationResourceParam, type IntegrationResourceSummary, type IntegrationResourceUpdateInput, type IntegrationResourcesModule, type IntegrationTemplate, type IntegrationTemplateSummary, type IntegrationTemplateType, type IntegrationTemplatesModule, type IntegrationTokenExtraction, type InviteAppUserInput, type InvocationType, type JsonValue, type LegacyPage, type ListTablesOptions, type ListTemplateConfigsOptions, type ManagedAiProfile, type MembersModule, type MessageAccepted, type MessengerModule, type NewAgentTaskSessionOptions, type OAuthExchangeInput, type OAuthStartResult, type OpencodeAiProvider, type Page, type PageOptions, type PlanPrice, type ProviderCredentialStatus, type ProxyInput, type ProxyResult, type PublicFunctionAsyncResult, type PublicFunctionResult, type PublicFunctionsModule, type QueriesModule, type QueryParamPrimitive, type QueryParamValue, type QueryResult, type SchemaModule, type SchemaScope, type SchemaTables, type SdkCore, SdkCoreConfigurationError, type SdkCoreErrorFactory, type SdkCoreOptions, SdkCoreResponseError, type SdkCoreTransports, type SendEmailInput, type SqlModule, type TableColumn, type TableDefinition, type TableForeignKey, type TemplateConfig, type TemplateConfigBulkItemResult, type TemplateConfigBulkResult, type TemplateConfigCreateInput, type TemplateConfigPage, type TemplateConfigSummary, type TemplateConfigUpdateInput, type Tenant, type TestCredentialsInput, type Transport, type TransportRequestOptions, type User, type UserPlan, type WorkflowDefinition, type WorkflowExecution, type WorkflowInput, type WorkflowSummary, type WorkflowsModule, appAccessTokenPath, createAgentConnectionsModule, createAgentCredentialsModule, createAgentTaskSessionManager, createAgentTasksModule, createAgentsModule, createAiProvidersModule, createAppsModule, createAuthModule, createContextModule, createCustomQueriesModule, createDataSourcesModule, createEntitiesModule, createFilesModule, createFunctionsAdminModule, createFunctionsModule, createImportsModule, createIntegrationAdminModule, createIntegrationModule, createIntegrationResourcesModule, createIntegrationTemplatesModule, createMembersModule, createMessengerModule, createPublicFunctionsModule, createQueriesModule, createSchemaModule, createSdkCore, createSqlModule, createWorkflowsModule, defaultSdkCoreErrorFactory, encodePathSegment, expectEmpty, expectLegacyPage, expectNullableObject, expectObject, expectObjectArray, expectPage, expectStringArray, isAgentTurnEvent, isWorkspaceSession, readTokenAppId, readTokenExpiry, resolveApiKeyToken, toAgentTimelineItem, tokenAuthorizesApp, withAgentTaskSessions };