Skip to content

Commit

Permalink
Merge pull request #2310 from langchain-ai/dqbd/sdk-js-types
Browse files Browse the repository at this point in the history
feat(sdk-js): improve types for drawable graph, interrupts and metadata
  • Loading branch information
dqbd authored Nov 4, 2024
2 parents 18cea39 + 8455771 commit 6eb8130
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libs/sdk-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@langchain/langgraph-sdk",
"version": "0.0.20",
"version": "0.0.21",
"description": "Client library for interacting with the LangGraph API",
"type": "module",
"packageManager": "[email protected]",
Expand Down
31 changes: 28 additions & 3 deletions libs/sdk-js/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@ export interface GraphSchema {

export type Subgraphs = Record<string, GraphSchema>;

export type Metadata = Optional<Record<string, unknown>>;
export type Metadata = Optional<{
source?: "input" | "loop" | "update" | (string & {});

step?: number;

writes?: Record<string, unknown> | null;

parents?: Record<string, string>;

[key: string]: unknown;
}>;

export interface AssistantBase {
/** The ID of the assistant. */
Expand Down Expand Up @@ -110,7 +120,22 @@ export interface Assistant extends AssistantBase {
/** The name of the assistant */
name: string;
}
export type AssistantGraph = Record<string, Array<Record<string, unknown>>>;

export interface AssistantGraph {
nodes: Array<{
id: string | number;
name?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: Record<string, any> | string;
metadata?: unknown;
}>;
edges: Array<{
source: string;
target: string;
data?: string;
conditional?: boolean;
}>;
}

export interface Thread<ValuesType = DefaultValues> {
/** The ID of the thread. */
Expand Down Expand Up @@ -184,7 +209,7 @@ export interface ThreadTask {
id: string;
name: string;
error: Optional<string>;
interrupts: Array<Record<string, unknown>>;
interrupts: Array<{ value: unknown; when: "during" }>;
checkpoint: Optional<Checkpoint>;
state: Optional<ThreadState>;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/sdk-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ interface RunsInvokePayload {
/**
* Interrupt execution before entering these nodes.
*/
interruptBefore?: string[];
interruptBefore?: "*" | string[];

/**
* Interrupt execution after leaving these nodes.
*/
interruptAfter?: string[];
interruptAfter?: "*" | string[];

/**
* Strategy to handle concurrent runs on the same thread. Only relevant if
Expand Down

0 comments on commit 6eb8130

Please sign in to comment.