@forge-sdk/generate
Text generation, streaming, structured output, and multi-step generation for the Forge SDK.
Text generation, streaming, structured output, and multi-step generation for the Forge SDK.
Package contract
| Field | Value |
|---|---|
| Language | typescript |
| Source version | 0.1.0 |
| Manifest | forge-ts/packages/forge-generate/package.json |
| Source files | 6 |
| Evidence | Source reference; registry publication and runtime conformance are separate checks |
Import boundary
import * as api from '@forge-sdk/generate';Use a source checkout or your verified private registry. Manifest coordinates identify the package; they do not establish that a public registry release exists.
Source reference
Download package reference JSON. Each original source file and generated declaration artifact has its own SHA-256 digest. Function bodies and constant values are omitted from downloads. These are source declaration inventories, not compiler-resolved rustdoc, TypeDoc, DocC, or Dokka output. Private modules can contain public declarations that are not reachable through the package boundary; consult the entry point before importing.
error.ts
Read declaration text · 3 declaration entries
export const ForgeGenerateErrorCode /* type inferred in source */;
export type ForgeGenerateErrorCodeType =
(typeof ForgeGenerateErrorCode)[keyof typeof ForgeGenerateErrorCode];
export class ForgeGenerateError extends Error {
readonly code: ForgeGenerateErrorCodeType;
readonly model?: string;
static modelError(model: string, reason: string): ForgeGenerateError;
static schemaViolation(model: string, path: string, reason: string): ForgeGenerateError;
static stepLimitReached(
stepsCompleted: number,
limit: number,
totalTokens: number
): ForgeGenerateError;
static streamInterrupted(
model: string,
chunksReceived: number,
reason: string
): ForgeGenerateError;
static noResponse(model: string, messagesCount: number): ForgeGenerateError;
static deserializationFailed(
model: string,
targetType: string,
reason: string
): ForgeGenerateError;
}index.ts
Read declaration text · 5 declaration entries
export { ForgeGenerateError, ForgeGenerateErrorCode, type ForgeGenerateErrorCodeType } from './error.js';
export { GenerateTextResult, generateText } from './text.js';
export { TextStreamResult, streamText } from './stream.js';
export { type ObjectResult, generateObject, streamObject } from './object.js';
export {
type StopCondition,
type StopReason,
type StepResult,
maxSteps,
maxTokens,
textMatch,
customStop,
formatStopReason,
finalText,
stepCount,
completedNaturally,
generateSteps,
} from './step.js';object.ts
Read declaration text · 3 declaration entries
export interface ObjectResult<T> {
/** The deserialized object. */
readonly object: T;
/** The raw JSON string from the model output. */
readonly rawJson: string;
/** Token usage statistics. */
readonly usage: Usage;
/** Why generation stopped. */
readonly finishReason: FinishReason;
}
export async function generateObject<T>(
model: LanguageModel,
messages: readonly ModelMessage[],
schema: JsonSchema,
options: GenerateOptions
): Promise<ObjectResult<T>>;
export async function streamObject<T>(
model: LanguageModel,
messages: readonly ModelMessage[],
schema: JsonSchema,
options: GenerateOptions
): Promise<ObjectResult<T>>;step.ts
Read declaration text · 12 declaration entries
export type StopCondition =
| { readonly type: 'max_steps'; readonly maxSteps: number }
| { readonly type: 'max_tokens'; readonly maxTokens: number }
| { readonly type: 'text_match'; readonly pattern: string }
| { readonly type: 'custom'; readonly predicate: (result: GenerateResult) => boolean };
export function maxSteps(maxSteps: number): StopCondition;
export function maxTokens(maxTokens: number): StopCondition;
export function textMatch(pattern: string): StopCondition;
export function customStop(predicate: (result: GenerateResult) => boolean): StopCondition;
export type StopReason =
| { readonly type: 'model_stopped' }
| { readonly type: 'step_limit_reached'; readonly steps: number; readonly limit: number }
| { readonly type: 'token_limit_reached'; readonly totalTokens: number; readonly limit: number }
| { readonly type: 'text_match_found'; readonly pattern: string }
| { readonly type: 'custom_condition' };
export function formatStopReason(reason: StopReason): string;
export interface StepResult {
/** The ordered sequence of generation results, one per step. */
readonly steps: readonly GenerateResult[];
/** Cumulative token usage across all steps. */
readonly totalUsage: Usage;
/** Why multi-step generation stopped. */
readonly stopReason: StopReason;
}
export function finalText(result: StepResult): string;
export function stepCount(result: StepResult): number;
export function completedNaturally(result: StepResult): boolean;
export async function generateSteps(
model: LanguageModel,
initialMessages: readonly ModelMessage[],
tools: readonly ToolDefinition[],
options: GenerateOptions,
stop: StopCondition
): Promise<StepResult>;stream.ts
Read declaration text · 2 declaration entries
export class TextStreamResult {
constructor(chunks: readonly StreamChunk[]);
get fullText(): string;
get chunks(): readonly StreamChunk[];
get chunkCount(): number;
get usage(): Usage;
get finishReason(): FinishReason | undefined;
get isComplete(): boolean;
}
export async function streamText(
model: LanguageModel,
messages: readonly ModelMessage[],
tools: readonly ToolDefinition[],
options: GenerateOptions
): Promise<TextStreamResult>;text.ts
Read declaration text · 2 declaration entries
export class GenerateTextResult {
constructor(inner: GenerateResult);
get text(): string;
get usage(): Usage;
get finishReason(): FinishReason;
get message(): ModelMessage;
get hasToolCalls(): boolean;
get inner(): GenerateResult;
}
export async function generateText(
model: LanguageModel,
messages: readonly ModelMessage[],
tools: readonly ToolDefinition[],
options: GenerateOptions
): Promise<GenerateTextResult>;