@mitralab.io/sdk-core 0.3.10 → 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/CHANGELOG.md +58 -0
- package/README.md +5 -0
- package/contracts/README.md +6 -0
- package/contracts/manifest.json +6 -1
- package/contracts/v0.3.11/sdk-parity.json +2902 -0
- package/dist/index.cjs +167 -28
- package/dist/index.d.cts +235 -2
- package/dist/index.d.ts +235 -2
- package/dist/index.js +166 -28
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1151,6 +1151,26 @@ interface AgentTaskCreateInput {
|
|
|
1151
1151
|
* agent holding a connection; mutually exclusive with `userId`.
|
|
1152
1152
|
*/
|
|
1153
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;
|
|
1154
1174
|
}
|
|
1155
1175
|
interface AgentTask {
|
|
1156
1176
|
id: string;
|
|
@@ -1165,6 +1185,64 @@ interface AgentTask {
|
|
|
1165
1185
|
archived: boolean;
|
|
1166
1186
|
createdAt: string | null;
|
|
1167
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;
|
|
1168
1246
|
}
|
|
1169
1247
|
interface AgentTaskListOptions extends PageOptions {
|
|
1170
1248
|
/** Include archived chats. Defaults to false. */
|
|
@@ -1309,6 +1387,19 @@ interface AgentTurnUsage {
|
|
|
1309
1387
|
*/
|
|
1310
1388
|
contextWindow?: number;
|
|
1311
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
|
+
}
|
|
1312
1403
|
interface AgentMessage {
|
|
1313
1404
|
id: string;
|
|
1314
1405
|
sender: string;
|
|
@@ -1689,6 +1780,29 @@ interface AgentTasksModule {
|
|
|
1689
1780
|
* modules keep compiling; a module without it never takes the direct channel.
|
|
1690
1781
|
*/
|
|
1691
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>;
|
|
1692
1806
|
}
|
|
1693
1807
|
declare function createAgentTasksModule(transport: Transport, errors?: SdkCoreErrorFactory): AgentTasksModule;
|
|
1694
1808
|
|
|
@@ -2317,7 +2431,9 @@ type AgentFetch = (url: string, init: {
|
|
|
2317
2431
|
|
|
2318
2432
|
declare class AgentTaskTurnError extends Error {
|
|
2319
2433
|
readonly code: string | undefined;
|
|
2320
|
-
|
|
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[]);
|
|
2321
2437
|
}
|
|
2322
2438
|
|
|
2323
2439
|
interface AgentTaskEventObserver {
|
|
@@ -2584,6 +2700,13 @@ interface AgentTurnResult {
|
|
|
2584
2700
|
sequence?: number;
|
|
2585
2701
|
/** The `lifecycle.turnId` of that `stepFinish`. */
|
|
2586
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[];
|
|
2587
2710
|
}
|
|
2588
2711
|
interface AgentTaskSessionEventMap {
|
|
2589
2712
|
statusChange: {
|
|
@@ -2672,10 +2795,23 @@ interface AgentTaskSessionEventMap {
|
|
|
2672
2795
|
subagentTool: AgentToolEvent & {
|
|
2673
2796
|
parentToolId: string;
|
|
2674
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
|
+
*/
|
|
2675
2803
|
error: {
|
|
2676
2804
|
code?: string;
|
|
2677
2805
|
error: string;
|
|
2678
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;
|
|
2679
2815
|
};
|
|
2680
2816
|
/**
|
|
2681
2817
|
* The subscription window the chat's harness reported during a turn. It comes only on the
|
|
@@ -2774,6 +2910,103 @@ declare function toAgentTimelineItem(message: AgentMessage): AgentTimelineItem;
|
|
|
2774
2910
|
declare function createAgentTaskSessionManager(options: AgentTaskSessionManagerOptions): AgentTaskSessionManager;
|
|
2775
2911
|
declare function withAgentTaskSessions(tasks: AgentTasksModule, manager: AgentTaskSessionManager): AgentTasksWithSessions;
|
|
2776
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
|
+
|
|
2777
3010
|
type FileTransferStep = "send" | "confirm" | "download";
|
|
2778
3011
|
interface FileTransferErrorDetails {
|
|
2779
3012
|
fileId: string;
|
|
@@ -2860,4 +3093,4 @@ declare function expectPage<T extends object>(value: unknown, context: string, e
|
|
|
2860
3093
|
declare function expectLegacyPage<T extends object>(value: unknown, context: string, errors?: SdkCoreErrorFactory, validateItem?: (value: unknown, context: string, errors: SdkCoreErrorFactory) => T): LegacyPage<T>;
|
|
2861
3094
|
declare function expectEmpty(value: unknown, context: string, errors?: SdkCoreErrorFactory): void;
|
|
2862
3095
|
|
|
2863
|
-
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 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, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1151,6 +1151,26 @@ interface AgentTaskCreateInput {
|
|
|
1151
1151
|
* agent holding a connection; mutually exclusive with `userId`.
|
|
1152
1152
|
*/
|
|
1153
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;
|
|
1154
1174
|
}
|
|
1155
1175
|
interface AgentTask {
|
|
1156
1176
|
id: string;
|
|
@@ -1165,6 +1185,64 @@ interface AgentTask {
|
|
|
1165
1185
|
archived: boolean;
|
|
1166
1186
|
createdAt: string | null;
|
|
1167
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;
|
|
1168
1246
|
}
|
|
1169
1247
|
interface AgentTaskListOptions extends PageOptions {
|
|
1170
1248
|
/** Include archived chats. Defaults to false. */
|
|
@@ -1309,6 +1387,19 @@ interface AgentTurnUsage {
|
|
|
1309
1387
|
*/
|
|
1310
1388
|
contextWindow?: number;
|
|
1311
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
|
+
}
|
|
1312
1403
|
interface AgentMessage {
|
|
1313
1404
|
id: string;
|
|
1314
1405
|
sender: string;
|
|
@@ -1689,6 +1780,29 @@ interface AgentTasksModule {
|
|
|
1689
1780
|
* modules keep compiling; a module without it never takes the direct channel.
|
|
1690
1781
|
*/
|
|
1691
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>;
|
|
1692
1806
|
}
|
|
1693
1807
|
declare function createAgentTasksModule(transport: Transport, errors?: SdkCoreErrorFactory): AgentTasksModule;
|
|
1694
1808
|
|
|
@@ -2317,7 +2431,9 @@ type AgentFetch = (url: string, init: {
|
|
|
2317
2431
|
|
|
2318
2432
|
declare class AgentTaskTurnError extends Error {
|
|
2319
2433
|
readonly code: string | undefined;
|
|
2320
|
-
|
|
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[]);
|
|
2321
2437
|
}
|
|
2322
2438
|
|
|
2323
2439
|
interface AgentTaskEventObserver {
|
|
@@ -2584,6 +2700,13 @@ interface AgentTurnResult {
|
|
|
2584
2700
|
sequence?: number;
|
|
2585
2701
|
/** The `lifecycle.turnId` of that `stepFinish`. */
|
|
2586
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[];
|
|
2587
2710
|
}
|
|
2588
2711
|
interface AgentTaskSessionEventMap {
|
|
2589
2712
|
statusChange: {
|
|
@@ -2672,10 +2795,23 @@ interface AgentTaskSessionEventMap {
|
|
|
2672
2795
|
subagentTool: AgentToolEvent & {
|
|
2673
2796
|
parentToolId: string;
|
|
2674
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
|
+
*/
|
|
2675
2803
|
error: {
|
|
2676
2804
|
code?: string;
|
|
2677
2805
|
error: string;
|
|
2678
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;
|
|
2679
2815
|
};
|
|
2680
2816
|
/**
|
|
2681
2817
|
* The subscription window the chat's harness reported during a turn. It comes only on the
|
|
@@ -2774,6 +2910,103 @@ declare function toAgentTimelineItem(message: AgentMessage): AgentTimelineItem;
|
|
|
2774
2910
|
declare function createAgentTaskSessionManager(options: AgentTaskSessionManagerOptions): AgentTaskSessionManager;
|
|
2775
2911
|
declare function withAgentTaskSessions(tasks: AgentTasksModule, manager: AgentTaskSessionManager): AgentTasksWithSessions;
|
|
2776
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
|
+
|
|
2777
3010
|
type FileTransferStep = "send" | "confirm" | "download";
|
|
2778
3011
|
interface FileTransferErrorDetails {
|
|
2779
3012
|
fileId: string;
|
|
@@ -2860,4 +3093,4 @@ declare function expectPage<T extends object>(value: unknown, context: string, e
|
|
|
2860
3093
|
declare function expectLegacyPage<T extends object>(value: unknown, context: string, errors?: SdkCoreErrorFactory, validateItem?: (value: unknown, context: string, errors: SdkCoreErrorFactory) => T): LegacyPage<T>;
|
|
2861
3094
|
declare function expectEmpty(value: unknown, context: string, errors?: SdkCoreErrorFactory): void;
|
|
2862
3095
|
|
|
2863
|
-
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 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, 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 };
|