tools

package
v0.22.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnvironmentDefinition = BuiltinDefinition{
	Description: "Get all environment variables of the user's system.",
	Parameter: map[string]any{
		"type":                 "object",
		"properties":           map[string]any{},
		"additionalProperties": false,
		"required":             []string{},
	},
	Function: func(ctx context.Context, jsonArguments string) ([]byte, error) {
		var pArgs EnvironmentArguments
		err := json.Unmarshal([]byte(jsonArguments), &pArgs)
		if err != nil {
			return nil, fmt.Errorf("error parsing arguments: %w", err)
		}

		result := EnvironmentResult{
			Environment: map[string]string{},
		}

		for _, e := range os.Environ() {
			pair := strings.SplitN(e, "=", 2)
			result.Environment[pair[0]] = pair[1]
		}

		return json.Marshal(result)
	},
}
View Source
var SystemInfoDefinition = BuiltinDefinition{
	Description: "Get the following information about the user's system: OS, architecture, number of CPUs, hostname, user directory, user ID, group ID, working directory, process ID.",
	Parameter: map[string]any{
		"type":       "object",
		"properties": map[string]any{},
		"required":   []string{},
	},
	Function: func(ctx context.Context, jsonArguments string) ([]byte, error) {
		return json.Marshal(SystemInfoResult{
			OS:   runtime.GOOS,
			Arch: runtime.GOARCH,
			CPU:  runtime.NumCPU(),
			Hostname: func() string {
				h, err := os.Hostname()
				if err != nil {
					return "unknown"
				}
				return h
			}(),
			UserDir: func() string {
				home, err := os.UserHomeDir()
				if err != nil {
					return "unknown"
				}
				return home
			}(),
			UserId:  os.Getuid(),
			GroupId: os.Getgid(),
			WorkDir: func() string {
				dir, err := os.Getwd()
				if err != nil {
					return "unknown"
				}
				return dir
			}(),
			PID: os.Getpid(),
		})
	},
}
View Source
var SystemTimeDefinition = BuiltinDefinition{
	Description: "Get the current system time.",
	Parameter: map[string]any{
		"type":       "object",
		"properties": map[string]any{},
		"required":   []string{},
	},
	Function: func(ctx context.Context, jsonArguments string) ([]byte, error) {
		return []byte(time.Now().String()), nil
	},
}

Functions

This section is empty.

Types

type BuiltinDefinition

type BuiltinDefinition struct {
	Description string
	Parameter   map[string]any
	Function    func(ctx context.Context, jsonArguments string) ([]byte, error)
}

type EnvironmentArguments

type EnvironmentArguments struct {
}

type EnvironmentResult

type EnvironmentResult struct {
	Environment map[string]string `json:"env"`
}

type SystemInfoArguments

type SystemInfoArguments struct {
}

type SystemInfoResult

type SystemInfoResult struct {
	OS       string `json:"os"`
	Arch     string `json:"arch"`
	CPU      int    `json:"cpus"`
	Hostname string `json:"hostname"`
	UserDir  string `json:"user_dir"`
	UserId   int    `json:"user_id"`
	GroupId  int    `json:"group_id"`
	WorkDir  string `json:"working_directory"`
	PID      int    `json:"process_id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL