shell

package
v0.10.0-alpha.20 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package shell adapts recoverable logical commands to managed background tools.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRegistration

func NewRegistration(config *RegistrationConfig) (*backgroundtool.Registration, error)

NewRegistration builds a generic recoverable managed-tool registration.

Example
/*
 * Copyright 2026 CloudWeGo Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package main

import (
	"context"
	"fmt"

	"github.com/cloudwego/eino/adk/backgroundtask"
	backgroundshell "github.com/cloudwego/eino/adk/backgroundtask/shell"
	backgroundtool "github.com/cloudwego/eino/adk/backgroundtask/tool"
	"github.com/cloudwego/eino/schema"
)

type remoteShell struct{}

func (remoteShell) StartCommand(
	context.Context,
	*backgroundshell.StartCommandRequest,
) (backgroundtool.Run, error) {
	return commandRun{}, nil
}
func (remoteShell) RecoverCommand(
	context.Context,
	*backgroundshell.RecoverCommandRequest,
) (backgroundtool.Run, error) {
	return commandRun{}, nil
}

type commandRun struct{}

func (commandRun) Wait(context.Context) (*backgroundtool.Outcome, error) {
	return &backgroundtool.Outcome{
		Status: backgroundtask.StatusCompleted, Data: []byte("ok"),
	}, nil
}
func (commandRun) Stop(context.Context) error { return nil }

func main() {
	registration, _ := backgroundshell.NewRegistration(&backgroundshell.RegistrationConfig{
		Info: &schema.ToolInfo{
			Name: "execute", Desc: "Run a recoverable remote command",
			ParamsOneOf: schema.NewParamsOneOfByParams(map[string]*schema.ParameterInfo{
				"command": {Type: schema.String, Required: true},
			}),
		},
		Shell: remoteShell{},
	})
	fmt.Println(registration.Info.Name)
}
Output:
execute

Types

type RecoverCommandRequest

type RecoverCommandRequest struct {
	TaskID  string
	Command string
	Attempt int64
}

RecoverCommandRequest describes reconstruction of a logical command.

type RecoverableShell

type RecoverableShell interface {
	StartCommand(context.Context, *StartCommandRequest) (backgroundtool.Run, error)
	RecoverCommand(context.Context, *RecoverCommandRequest) (backgroundtool.Run, error)
}

RecoverableShell starts and recovers logical commands keyed by Eino task ID. It is intentionally separate from filesystem.Shell and StreamingShell, which make no cross-Worker recovery claim.

type RegistrationConfig

type RegistrationConfig struct {
	Info         *schema.ToolInfo
	Shell        RecoverableShell
	Materializer backgroundtool.OutputMaterializer
}

RegistrationConfig configures a recoverable shell registration.

type StartCommandRequest

type StartCommandRequest struct {
	TaskID  string
	Command string
	Attempt int64
}

StartCommandRequest describes the first attempt of a logical command.

Jump to

Keyboard shortcuts

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