Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ public sealed record ChatTruncatedAction
/// <summary>Loads older completed turns into this chat's state.
///
/// Hosts dispatch this before responding to `fetchTurns`, and before applying
/// any operation that references a turn older than the currently loaded window.
/// any state-changing operation that references a turn older than the currently loaded window.
/// `turns` is ordered oldest-first and is prepended to the current `turns`
/// window. `turnsNextCursor` replaces the state's cursor; omit it when all
/// retained turns are now loaded.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ public sealed record CreateResourceWatchResult
/// channel's `turns` state, ahead of the already-loaded window, and update or
/// clear `turnsNextCursor`.
///
/// Before applying any operation that references a turn outside the currently
/// Before applying any state-changing operation that references a turn outside the currently
/// loaded window, the host MUST eagerly load enough older turns into state for
/// that operation to reduce against valid state.</summary>
public sealed record FetchTurnsParams
Expand Down Expand Up @@ -1832,6 +1832,96 @@ public sealed record FetchTurnsResult
{
}

/// <summary>A prompt in the retained history, identified by its turn rather than its position.</summary>
public sealed record ChatTurnIndexEntry
{
/// <summary>Stable identifier of the completed turn in this chat.</summary>
public required string TurnId { get; init; }

/// <summary>First nonempty trimmed prompt line, or empty string. If truncated, the
/// 80 Unicode scalar values include the trailing ellipsis.</summary>
public required string Preview { get; init; }

/// <summary>The turn's ISO 8601 start time, if known.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? StartedAt { get; init; }
}

/// <summary>Lists every visible non-system prompt in retained turns, oldest first, across pages.
/// Requires `ChatState.historyBrowsing`. Does not load turns into state.</summary>
public sealed record ListChatTurnsParams
{
/// <summary>Chat URI.</summary>
public required string Channel { get; init; }

/// <summary>Optional JSON-serializable metadata associated with this request.
/// Receivers MUST ignore keys they do not understand.</summary>
[JsonPropertyName("_meta")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, JsonElement>? Meta { get; init; }

/// <summary>Maximum entries in the page; defaults to 100. The host may return fewer.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public long? Limit { get; init; }

/// <summary>Opaque index cursor for this chat; omit to start at the oldest eligible prompt.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Cursor { get; init; }
}

/// <summary>One chronological page of the prompt index.</summary>
public sealed record ListChatTurnsResult
{
/// <summary>Continue this index after the last entry; absent at the end of the index.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? NextCursor { get; init; }

/// <summary>One entry per eligible prompt in transcript order.</summary>
public required List<ChatTurnIndexEntry> Items { get; init; }
}

/// <summary>Reads a byte-bounded page of completed turns without changing a subscription.
/// Supply exactly one of `fromTurnId` (open at that turn) or `cursor` (scroll).
/// Requires `ChatState.historyBrowsing`.</summary>
public sealed record ReadChatTurnsParams
{
/// <summary>Chat URI.</summary>
public required string Channel { get; init; }

/// <summary>Optional JSON-serializable metadata associated with this request.
/// Receivers MUST ignore keys they do not understand.</summary>
[JsonPropertyName("_meta")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, JsonElement>? Meta { get; init; }

/// <summary>Stable ID of the first turn to return. Omit when continuing by cursor.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? FromTurnId { get; init; }

/// <summary>Echo either cursor from a previous read page. Omit when opening by ID.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Cursor { get; init; }

/// <summary>Maximum number of whole turns on this page; defaults to 10.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public long? Limit { get; init; }
}

/// <summary>A contiguous page of the transcript, not a chat snapshot or a state update.</summary>
public sealed record ReadChatTurnsResult
{
/// <summary>Read immediately after the last returned turn; absent at the end.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? NextCursor { get; init; }

/// <summary>Consecutive whole turns, oldest first, including on a previous-page read.</summary>
public required List<Turn> Turns { get; init; }

/// <summary>Read immediately before the first returned turn; absent at the start.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? PreviousCursor { get; init; }
}

/// <summary>Stop receiving updates for a channel.</summary>
public sealed record UnsubscribeParams
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace Microsoft.AgentHostProtocol;
[JsonSerializable(typeof(ChatDeltaAction))]
[JsonSerializable(typeof(ChatDraftChangedAction))]
[JsonSerializable(typeof(ChatErrorAction))]
[JsonSerializable(typeof(ChatHistoryBrowsingCapability))]
[JsonSerializable(typeof(ChatInputAnswer))]
[JsonSerializable(typeof(ChatInputAnswerChangedAction))]
[JsonSerializable(typeof(ChatInputAnswered))]
Expand Down Expand Up @@ -197,6 +198,7 @@ namespace Microsoft.AgentHostProtocol;
[JsonSerializable(typeof(ChatTruncatedAction))]
[JsonSerializable(typeof(ChatTurnCancelledAction))]
[JsonSerializable(typeof(ChatTurnCompleteAction))]
[JsonSerializable(typeof(ChatTurnIndexEntry))]
[JsonSerializable(typeof(ChatTurnResumeAction))]
[JsonSerializable(typeof(ChatTurnsLoadedAction))]
[JsonSerializable(typeof(ChatTurnStartedAction))]
Expand Down Expand Up @@ -272,6 +274,8 @@ namespace Microsoft.AgentHostProtocol;
[JsonSerializable(typeof(JsonRpcSuccessResponse))]
[JsonSerializable(typeof(ListAutomationTriggerDefinitionsParams))]
[JsonSerializable(typeof(ListAutomationTriggerDefinitionsResult))]
[JsonSerializable(typeof(ListChatTurnsParams))]
[JsonSerializable(typeof(ListChatTurnsResult))]
[JsonSerializable(typeof(ListSessionsParams))]
[JsonSerializable(typeof(ListSessionsResult))]
[JsonSerializable(typeof(MarkdownResponsePart))]
Expand Down Expand Up @@ -318,6 +322,8 @@ namespace Microsoft.AgentHostProtocol;
[JsonSerializable(typeof(ProjectInfo))]
[JsonSerializable(typeof(PromptCustomization))]
[JsonSerializable(typeof(ProtectedResourceMetadata))]
[JsonSerializable(typeof(ReadChatTurnsParams))]
[JsonSerializable(typeof(ReadChatTurnsResult))]
[JsonSerializable(typeof(ReasoningResponsePart))]
[JsonSerializable(typeof(ReconnectParams))]
[JsonSerializable(typeof(ReconnectReplayResult))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,11 @@ public sealed record MultipleChatsCapability
public bool? SideChat { get; init; }
}

/// <summary>Presence advertises `listChatTurns` and `readChatTurns` for this chat.</summary>
public sealed record ChatHistoryBrowsingCapability
{
}

/// <summary>Options for the {@link AgentCapabilities.multipleWorkingDirectories} capability.</summary>
public sealed record MultipleWorkingDirectoriesCapability
{
Expand Down Expand Up @@ -2643,6 +2648,10 @@ public sealed class ChatState
/// <summary>Completed turns</summary>
public required List<Turn> Turns { get; set; }

/// <summary>Browse retained history independently of the subscription window. Absent when unsupported.</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ChatHistoryBrowsingCapability? HistoryBrowsing { get; set; }

/// <summary>Cursor for loading older completed turns into this chat state.
///
/// Presence means `turns` is a tail window and more historical turns are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ private static (object decoded, string reencoded) DecodeAndReencode(string type,
return Wrap(Ser.Deserialize<InitializeResult>(inputJson));
case "CreateChatParams":
return Wrap(Ser.Deserialize<CreateChatParams>(inputJson));
case "ListChatTurnsParams":
return Wrap(Ser.Deserialize<ListChatTurnsParams>(inputJson));
case "ListChatTurnsResult":
return Wrap(Ser.Deserialize<ListChatTurnsResult>(inputJson));
case "ReadChatTurnsParams":
return Wrap(Ser.Deserialize<ReadChatTurnsParams>(inputJson));
case "ReadChatTurnsResult":
return Wrap(Ser.Deserialize<ReadChatTurnsResult>(inputJson));
case "Snapshot":
return Wrap(Ser.Deserialize<Snapshot>(inputJson));
case "SubscribeParams":
Expand Down
2 changes: 1 addition & 1 deletion clients/go/ahptypes/actions.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ type ChatTruncatedAction struct {
// Loads older completed turns into this chat's state.
//
// Hosts dispatch this before responding to `fetchTurns`, and before applying
// any operation that references a turn older than the currently loaded window.
// any state-changing operation that references a turn older than the currently loaded window.
// `turns` is ordered oldest-first and is prepended to the current `turns`
// window. `turnsNextCursor` replaces the state's cursor; omit it when all
// retained turns are now loaded.
Expand Down
71 changes: 70 additions & 1 deletion clients/go/ahptypes/commands.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ type CreateResourceWatchResult struct {
// channel's `turns` state, ahead of the already-loaded window, and update or
// clear `turnsNextCursor`.
//
// Before applying any operation that references a turn outside the currently
// Before applying any state-changing operation that references a turn outside the currently
// loaded window, the host MUST eagerly load enough older turns into state for
// that operation to reduce against valid state.
type FetchTurnsParams struct {
Expand All @@ -1308,6 +1308,75 @@ type FetchTurnsParams struct {
type FetchTurnsResult struct {
}

// A prompt in the retained history, identified by its turn rather than its position.
type ChatTurnIndexEntry struct {
// Stable identifier of the completed turn in this chat.
TurnId string `json:"turnId"`
// First nonempty trimmed prompt line, or empty string. If truncated, the
// 80 Unicode scalar values include the trailing ellipsis.
Preview string `json:"preview"`
// The turn's ISO 8601 start time, if known.
StartedAt *string `json:"startedAt,omitempty"`
}

// Lists every visible non-system prompt in retained turns, oldest first, across pages.
// Requires `ChatState.historyBrowsing`. Does not load turns into state.
type ListChatTurnsParams struct {
// Channel URI this command targets.
Channel URI `json:"channel"`
// Optional JSON-serializable metadata associated with this request.
// Receivers MUST ignore keys they do not understand.
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
// Maximum number of entries to return in this page. The server SHOULD respect
// this bound but MAY return fewer entries and MAY impose its own upper cap.
// Omit to let the server choose the page size.
Limit *int64 `json:"limit,omitempty"`
// Opaque pagination cursor from a previous {@link PaginatedResult.nextCursor}.
// Omit to fetch the first page. Cursors are server-defined and MUST be treated
// as opaque — do not parse, modify, or persist them across connections. An
// unrecognised cursor SHOULD be rejected with an `InvalidParams` error.
Cursor *string `json:"cursor,omitempty"`
}

// One chronological page of the prompt index.
type ListChatTurnsResult struct {
// Opaque cursor for the next page. Present when more entries exist beyond the
// returned page; absent signals the end of the collection. Pass it back as
// {@link PaginatedParams.cursor} to fetch the following page.
NextCursor *string `json:"nextCursor,omitempty"`
// One entry per eligible prompt in transcript order.
Items []ChatTurnIndexEntry `json:"items"`
}

// Reads a byte-bounded page of completed turns without changing a subscription.
// Supply exactly one of `fromTurnId` (open at that turn) or `cursor` (scroll).
// Requires `ChatState.historyBrowsing`.
type ReadChatTurnsParams struct {
// Channel URI this command targets.
Channel URI `json:"channel"`
// Optional JSON-serializable metadata associated with this request.
// Receivers MUST ignore keys they do not understand.
Meta map[string]json.RawMessage `json:"_meta,omitempty"`
// Stable ID of the first turn to return. Omit when continuing by cursor.
FromTurnId *string `json:"fromTurnId,omitempty"`
// Echo either cursor from a previous read page. Omit when opening by ID.
Cursor *string `json:"cursor,omitempty"`
// Maximum number of whole turns on this page; defaults to 10.
Limit *int64 `json:"limit,omitempty"`
}

// A contiguous page of the transcript, not a chat snapshot or a state update.
type ReadChatTurnsResult struct {
// Opaque cursor for the next page. Present when more entries exist beyond the
// returned page; absent signals the end of the collection. Pass it back as
// {@link PaginatedParams.cursor} to fetch the following page.
NextCursor *string `json:"nextCursor,omitempty"`
// Consecutive whole turns, oldest first, including on a previous-page read.
Turns []Turn `json:"turns"`
// Read immediately before the first returned turn; absent at the start.
PreviousCursor *string `json:"previousCursor,omitempty"`
}

// Stop receiving updates for a channel.
type UnsubscribeParams struct {
// Channel URI to unsubscribe from
Expand Down
16 changes: 16 additions & 0 deletions clients/go/ahptypes/roundtrip_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ func decodeAndReencode(t *testing.T, name, typ, inputJSON string) string {
var v CreateChatParams
dec(&v)
return enc(&v)
case "ListChatTurnsParams":
var v ListChatTurnsParams
dec(&v)
return enc(&v)
case "ListChatTurnsResult":
var v ListChatTurnsResult
dec(&v)
return enc(&v)
case "ReadChatTurnsParams":
var v ReadChatTurnsParams
dec(&v)
return enc(&v)
case "ReadChatTurnsResult":
var v ReadChatTurnsResult
dec(&v)
return enc(&v)
case "ChatSource":
var v ChatSource
dec(&v)
Expand Down
6 changes: 6 additions & 0 deletions clients/go/ahptypes/state.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,10 @@ type MultipleChatsCapability struct {
SideChat *bool `json:"sideChat,omitempty"`
}

// Presence advertises `listChatTurns` and `readChatTurns` for this chat.
type ChatHistoryBrowsingCapability struct {
}

// Options for the {@link AgentCapabilities.multipleWorkingDirectories} capability.
type MultipleWorkingDirectoriesCapability struct {
// The agent's **first** working directory (index `0` of
Expand Down Expand Up @@ -1522,6 +1526,8 @@ type ChatState struct {
Config *ChatConfigState `json:"config,omitempty"`
// Completed turns
Turns []Turn `json:"turns"`
// Browse retained history independently of the subscription window. Absent when unsupported.
HistoryBrowsing *ChatHistoryBrowsingCapability `json:"historyBrowsing,omitempty"`
// Cursor for loading older completed turns into this chat state.
//
// Presence means `turns` is a tail window and more historical turns are
Expand Down
Loading
Loading