kimi

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package kimi drives the kimi CLI as a subprocess and parses its stream-json output into a plain text reply.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFinalMessage

func ParseFinalMessage(jsonlOutput string) (string, error)

Kimi CLI persists token usage in internal session files (`wire.jsonl` StatusUpdate.payload.token_usage and `context.jsonl` `_usage` rows), but `kimi --print --output-format stream-json` does not emit those events on stdout. The installed JsonPrinter only forwards assistant messages, notifications, tool results, and plan displays, so agentbridge cannot obtain per-run token usage from the JSONL stream it parses here.

Types

type Runner

type Runner struct {
	Command      string
	Timeout      time.Duration
	Env          map[string]string
	WorkspaceDir string
}

Runner executes the kimi CLI for a single request.

func (Runner) Run

func (r Runner) Run(ctx context.Context, userText string) (string, error)

Run is a convenience wrapper that runs without thread resumption or progress callbacks.

func (Runner) RunWithThreadAndProgress

func (r Runner) RunWithThreadAndProgress(
	ctx context.Context,
	threadID string,
	userText string,
	model string,
	env map[string]string,
	onProgress func(step string),
	onRawEvent func(kind, line, detail string),
) (string, string, error)

RunWithThreadAndProgress runs the kimi CLI and returns the final reply and next session ID.

  • threadID: resume an existing session when non-empty.
  • userText: the fully assembled prompt.
  • model: overrides the CLI default when non-empty.
  • env: merged over the process environment.
  • onProgress: called with intermediate assistant messages; may be nil.
  • onRawEvent: optional callback for raw stdout events (kind, line, detail); nil disables raw event delivery.

Jump to

Keyboard shortcuts

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