Class: Kward::Tools::WriteFile

Inherits:
Base
  • Object
show all
Defined in:
lib/kward/tools/write_file.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#schema

Constructor Details

#initialize(workspace:) ⇒ WriteFile

Returns a new instance of WriteFile.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kward/tools/write_file.rb', line 6

def initialize(workspace:)
  @workspace = workspace
  super(
    "write_file",
    "Write a workspace file. Existing files must be read first.",
    properties: {
      path: { type: "string", description: "Workspace-relative path." },
      content: { type: "string", description: "Complete file content." }
    },
    required: ["path", "content"]
  )
end

Instance Method Details

#call(args, conversation, cancellation: nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/kward/tools/write_file.rb', line 19

def call(args, conversation, cancellation: nil)
  path = argument(args, :path, "")
  content = argument(args, :content, "")

  result = @workspace.write_file(path, content, read_paths: conversation.read_paths)
  conversation.refresh_system_message! if agents_file_changed?(@workspace, path, result)
  result
end