Skip to content
Open
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 @@ -147,6 +147,7 @@ private static JsonSerializerOptions CreateDefaultOptions()
[JsonSerializable(typeof(ItemContentOutputText))]
[JsonSerializable(typeof(ItemContentOutputAudio))]
[JsonSerializable(typeof(ItemContentRefusal))]
[JsonSerializable(typeof(ItemContentFunctionApprovalResponse))]
[JsonSerializable(typeof(TextConfiguration))]
[JsonSerializable(typeof(ResponseTextFormatConfiguration))]
[JsonSerializable(typeof(ResponseTextFormatConfigurationText))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ private static string MediaTypeToAudioFormat(string mediaType) =>
ItemContentOutputAudio outputAudio =>
new DataContent(outputAudio.Data, "audio/*"),

// Function approval response - preserve raw representation for downstream processing
ItemContentFunctionApprovalResponse approvalResponse =>
new TextContent($"[Function approval response: request_id={approvalResponse.RequestId}, approved={approvalResponse.Approved}]"),
Comment on lines +73 to +75

_ => null
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ internal enum FunctionToolCallOutputItemResourceStatus
[JsonDerivedType(typeof(ItemContentOutputText), "output_text")]
[JsonDerivedType(typeof(ItemContentOutputAudio), "output_audio")]
[JsonDerivedType(typeof(ItemContentRefusal), "refusal")]
[JsonDerivedType(typeof(ItemContentFunctionApprovalResponse), "function_approval_response")]
internal abstract class ItemContent
{
/// <summary>
Expand Down Expand Up @@ -443,6 +444,29 @@ internal sealed class ItemContentRefusal : ItemContent
public required string Refusal { get; init; }
}

/// <summary>
/// A function approval response content item.
/// Used by DevUI for human-in-the-loop tool approval responses.
/// </summary>
internal sealed class ItemContentFunctionApprovalResponse : ItemContent
{
/// <inheritdoc/>
[JsonIgnore]
public override string Type => "function_approval_response";

/// <summary>
/// The unique identifier of the approval request being responded to.
/// </summary>
[JsonPropertyName("request_id")]
public required string RequestId { get; init; }

/// <summary>
/// Whether the request was approved.
/// </summary>
[JsonPropertyName("approved")]
public bool Approved { get; init; }
Comment on lines +463 to +467
}

// Additional ItemResource types from TypeSpec

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ForeachExecutor(Foreach model, WorkflowFormulaState state)
EvaluationResult<DataValue> expressionResult = this.Evaluator.GetValue(this.Model.Items);
if (expressionResult.Value is TableDataValue tableValue)
{
this._values = [.. tableValue.Values.Select(value => value.Properties.Values.First().ToFormula())];
this._values = [.. tableValue.Values.Select(value => value.ToFormula())];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,38 @@ public async Task ForeachRestoreWithNoSavedStateAsync()
Assert.False(executor.HasValue);
}

/// <summary>
/// Foreach over a table with multi-field records must preserve all fields in the loop value variable.
/// Regression test for GH-6183.
/// </summary>
[Fact]
public async Task ForeachPreservesMultiFieldRecordsAsync()
{
// Arrange
this.SetVariableState("CurrentValue");
TableDataValue tableValue = DataValue.TableFromRecords(
DataValue.RecordFromFields(
new KeyValuePair<string, DataValue>("name", new StringDataValue("Alice")),
new KeyValuePair<string, DataValue>("role", new StringDataValue("Engineer"))),
DataValue.RecordFromFields(
new KeyValuePair<string, DataValue>("name", new StringDataValue("Bob")),
new KeyValuePair<string, DataValue>("role", new StringDataValue("Designer"))));

Foreach model = this.CreateModel(
displayName: nameof(ForeachPreservesMultiFieldRecordsAsync),
items: ValueExpression.Literal(tableValue),
valueName: "CurrentValue",
indexName: null);

ForeachExecutor action = new(model, this.State);

// Act — execute the initialisation then take the first iteration.
await this.ExecuteAsync(action, ForeachExecutor.Steps.Next(action.Id), action.TakeNextAsync);

// Assert — the value must be present (all fields preserved, not collapsed to first field).
Assert.True(action.HasValue);
Comment on lines +322 to +323
}

/// <summary>
/// Checkpoint/restore around a foreach over an empty source must roundtrip cleanly
/// (zero-length <c>PortableValue[]</c> snapshot).
Expand Down