Skip to content

Commit

Permalink
refactor(ChannelProtocol): rename method update to updateAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Aug 15, 2024
1 parent 660bd63 commit 8203b8c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Sources/LangGraph/LangGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ public protocol ChannelProtocol {
Updates the channel with a new value.
- Parameters:
- name: The name of attribute that will be updated.
- oldValue: The old value of the channel.
- newValue: The new value to update the channel with.
- Throws: An error if the update fails.
- Returns: The updated value.
*/
func update(oldValue: Any?, newValue: Any) throws -> Any
func updateAttribute(_ name: String, oldValue: Any?, newValue: Any) throws -> Any
}
/**
A class representing a communication channel that conforms to `ChannelProtocol`.
Expand Down Expand Up @@ -108,14 +109,15 @@ public class Channel<T> : ChannelProtocol {
mismatches and provides default values when necessary.
- Parameters:
- name: The name of attribute that will be updated.
- oldValue: The old value of the channel, which can be `nil`.
- newValue: The new value to update the channel with.
- Throws: An error if the update fails due to type mismatches.
- Returns: The updated value.
*/
public func update( oldValue: Any?, newValue: Any ) throws -> Any {
public func updateAttribute( _ name: String, oldValue: Any?, newValue: Any ) throws -> Any {
guard let new = newValue as? T else {
throw CompiledGraphError.executionError( "Channel update 'newValue' type mismatch!")
throw CompiledGraphError.executionError( "Channel: Type mismatch updating 'newValue' for property \(name)!")
}

// var old:T?
Expand Down Expand Up @@ -185,16 +187,17 @@ public class AppenderChannel<T> : Channel<[T]> {
If the new value is a single element, it is converted to an array before appending.
- Parameters:
- name: The name of attribute that will be updated.
- oldValue: The old value of the channel, which can be `nil`.
- newValue: The new value to update the channel with.
- Throws: An error if the update fails due to type mismatches.
- Returns: The updated value.
*/
public override func update(oldValue: Any?, newValue: Any) throws -> Any {
public override func updateAttribute( _ name: String, oldValue: Any?, newValue: Any) throws -> Any {
if let new = newValue as? T {
return try super.update(oldValue: oldValue, newValue: [new])
return try super.updateAttribute( name, oldValue: oldValue, newValue: [new])
}
return try super.update(oldValue: oldValue, newValue: newValue)
return try super.updateAttribute( name, oldValue: oldValue, newValue: newValue)
}
}

Expand Down Expand Up @@ -763,7 +766,7 @@ extension StateGraph {
let mappedValues = try partialState.map { key, value in
if let channel = schema[key] {
do {
let newValue = try channel.update(oldValue: currentState.data[key], newValue: value)
let newValue = try channel.updateAttribute( key, oldValue: currentState.data[key], newValue: value)
return (key, newValue)
} catch CompiledGraphError.executionError(let message) {
throw CompiledGraphError.executionError("error processing property: '\(key)' - \(message)")
Expand Down

0 comments on commit 8203b8c

Please sign in to comment.