mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 09:29:38 +02:00
refactor(ts): make client gateway effect native
This commit is contained in:
parent
174d636178
commit
a7bdbb9257
16 changed files with 1168 additions and 1262 deletions
|
|
@ -1,42 +1,43 @@
|
|||
|
||||
import { Schema as S } from "effect";
|
||||
|
||||
// Term type discriminators matching the wire format
|
||||
// i = IRI, b = BLANK node, l = LITERAL, t = TRIPLE (reified)
|
||||
export type TermType = "i" | "b" | "l" | "t";
|
||||
|
||||
export interface IriTerm {
|
||||
t: "i";
|
||||
i: string;
|
||||
}
|
||||
export class IriTerm extends S.Class<IriTerm>("IriTerm")({
|
||||
t: S.Literal("i"),
|
||||
i: S.String,
|
||||
}, { description: "IRI term in TrustGraph wire triples." }) {}
|
||||
|
||||
export interface BlankTerm {
|
||||
t: "b";
|
||||
d: string;
|
||||
}
|
||||
export class BlankTerm extends S.Class<BlankTerm>("BlankTerm")({
|
||||
t: S.Literal("b"),
|
||||
d: S.String,
|
||||
}, { description: "Blank-node term in TrustGraph wire triples." }) {}
|
||||
|
||||
export interface LiteralTerm {
|
||||
t: "l";
|
||||
v: string;
|
||||
dt?: string; // datatype
|
||||
ln?: string; // language
|
||||
}
|
||||
export class LiteralTerm extends S.Class<LiteralTerm>("LiteralTerm")({
|
||||
t: S.Literal("l"),
|
||||
v: S.String,
|
||||
dt: S.optionalKey(S.String),
|
||||
ln: S.optionalKey(S.String),
|
||||
}, { description: "Literal term in TrustGraph wire triples." }) {}
|
||||
|
||||
export interface TripleTerm {
|
||||
t: "t";
|
||||
tr?: Triple;
|
||||
}
|
||||
export class TripleTerm extends S.Class<TripleTerm>("TripleTerm")({
|
||||
t: S.Literal("t"),
|
||||
tr: S.optionalKey(S.suspend((): S.Codec<Triple, Triple> => Triple)),
|
||||
}, { description: "Reified triple term in TrustGraph wire triples." }) {}
|
||||
|
||||
export type Term = IriTerm | BlankTerm | LiteralTerm | TripleTerm;
|
||||
export const Term = S.Union([IriTerm, BlankTerm, LiteralTerm, TripleTerm]);
|
||||
export type Term = typeof Term.Type;
|
||||
|
||||
export interface PartialTriple {
|
||||
s?: Term;
|
||||
p?: Term;
|
||||
o?: Term;
|
||||
}
|
||||
export class PartialTriple extends S.Class<PartialTriple>("PartialTriple")({
|
||||
s: S.optionalKey(Term),
|
||||
p: S.optionalKey(Term),
|
||||
o: S.optionalKey(Term),
|
||||
}, { description: "Partial triple pattern for query wildcards." }) {}
|
||||
|
||||
export interface Triple {
|
||||
s: Term;
|
||||
p: Term;
|
||||
o: Term;
|
||||
g?: string; // graph (renamed from direc to match backend)
|
||||
}
|
||||
export class Triple extends S.Class<Triple>("Triple")({
|
||||
s: Term,
|
||||
p: Term,
|
||||
o: Term,
|
||||
g: S.optionalKey(S.String),
|
||||
}, { description: "TrustGraph wire triple, optionally scoped to a named graph." }) {}
|
||||
|
|
|
|||
|
|
@ -1,521 +1,505 @@
|
|||
import type { Term, Triple } from "./Triple.js";
|
||||
import { Schema as S } from "effect";
|
||||
import { Term, Triple } from "./Triple.js";
|
||||
|
||||
export type Request = object;
|
||||
export type Response = object;
|
||||
|
||||
export interface ResponseError {
|
||||
type?: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export type WireError = object | string;
|
||||
|
||||
export interface RequestMessage {
|
||||
id: string;
|
||||
service: string;
|
||||
request: Request;
|
||||
flow?: string;
|
||||
}
|
||||
const UnknownRecord = S.Record(S.String, S.Unknown);
|
||||
const WireErrorValue = S.Union([S.String, UnknownRecord]);
|
||||
const TypedMessageError = S.Struct({
|
||||
message: S.String,
|
||||
type: S.optionalKey(S.String),
|
||||
});
|
||||
const OptionalMessageError = S.Struct({
|
||||
message: S.optionalKey(S.String),
|
||||
});
|
||||
|
||||
export interface ApiResponse {
|
||||
id: string;
|
||||
response: Response;
|
||||
}
|
||||
const NumberArray = S.Array(S.Finite).pipe(S.mutable);
|
||||
const NumberMatrix = S.Array(NumberArray).pipe(S.mutable);
|
||||
const TripleArray = S.Array(Triple).pipe(S.mutable);
|
||||
const StringArray = S.Array(S.String).pipe(S.mutable);
|
||||
|
||||
export interface Metadata {
|
||||
id?: string;
|
||||
metadata?: Triple[];
|
||||
user?: string;
|
||||
collection?: string;
|
||||
}
|
||||
export class ResponseError extends S.Class<ResponseError>("ResponseError")({
|
||||
type: S.optionalKey(S.String),
|
||||
message: S.String,
|
||||
}, { description: "TrustGraph response error payload." }) {}
|
||||
|
||||
export interface EntityEmbeddings {
|
||||
entity?: Term;
|
||||
vectors?: number[][];
|
||||
}
|
||||
export class RequestMessage extends S.Class<RequestMessage>("RequestMessage")({
|
||||
id: S.String,
|
||||
service: S.String,
|
||||
request: UnknownRecord,
|
||||
flow: S.optionalKey(S.String),
|
||||
}, { description: "Envelope sent to a TrustGraph service." }) {}
|
||||
|
||||
export interface GraphEmbeddings {
|
||||
metadata?: Metadata;
|
||||
entities?: EntityEmbeddings[];
|
||||
}
|
||||
export class ApiResponse extends S.Class<ApiResponse>("ApiResponse")({
|
||||
id: S.String,
|
||||
response: UnknownRecord,
|
||||
}, { description: "Envelope returned from a TrustGraph service." }) {}
|
||||
|
||||
export interface TextCompletionRequest {
|
||||
system: string;
|
||||
prompt: string;
|
||||
streaming?: boolean;
|
||||
}
|
||||
export class Metadata extends S.Class<Metadata>("Metadata")({
|
||||
id: S.optionalKey(S.String),
|
||||
metadata: S.optionalKey(TripleArray),
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
}, { description: "Shared request metadata for TrustGraph wire messages." }) {}
|
||||
|
||||
export interface TextCompletionResponse {
|
||||
response: string;
|
||||
// Streaming fields
|
||||
end_of_stream?: boolean;
|
||||
error?: {
|
||||
message: string;
|
||||
type?: string;
|
||||
};
|
||||
// Token usage (appears in final message)
|
||||
in_token?: number;
|
||||
out_token?: number;
|
||||
model?: string;
|
||||
}
|
||||
export class EntityEmbeddings extends S.Class<EntityEmbeddings>("EntityEmbeddings")({
|
||||
entity: S.optionalKey(Term),
|
||||
vectors: S.optionalKey(NumberMatrix),
|
||||
}, { description: "Embedding vectors associated with a graph entity." }) {}
|
||||
|
||||
export interface GraphRagRequest {
|
||||
query: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
"entity-limit"?: number; // Default: 50
|
||||
"triple-limit"?: number; // Default: 30
|
||||
"max-subgraph-size"?: number; // Default: 1000
|
||||
"max-path-length"?: number; // Default: 2
|
||||
streaming?: boolean;
|
||||
}
|
||||
export class GraphEmbeddings extends S.Class<GraphEmbeddings>("GraphEmbeddings")({
|
||||
metadata: S.optionalKey(Metadata),
|
||||
entities: S.optionalKey(S.Array(EntityEmbeddings).pipe(S.mutable)),
|
||||
}, { description: "Graph embedding payload grouped by entity." }) {}
|
||||
|
||||
export interface GraphRagResponse {
|
||||
response: string;
|
||||
// Streaming fields
|
||||
chunk?: string;
|
||||
end_of_stream?: boolean;
|
||||
endOfStream?: boolean;
|
||||
error?: {
|
||||
message: string;
|
||||
type?: string;
|
||||
};
|
||||
// Token usage (appears in final message)
|
||||
in_token?: number;
|
||||
out_token?: number;
|
||||
model?: string;
|
||||
// Explainability fields
|
||||
message_type?: "chunk" | "explain";
|
||||
explain_id?: string;
|
||||
explain_graph?: string;
|
||||
explain_triples?: unknown[];
|
||||
end_of_session?: boolean;
|
||||
}
|
||||
export class TextCompletionRequest extends S.Class<TextCompletionRequest>("TextCompletionRequest")({
|
||||
system: S.String,
|
||||
prompt: S.String,
|
||||
streaming: S.optionalKey(S.Boolean),
|
||||
}, { description: "Text-completion request payload." }) {}
|
||||
|
||||
export interface DocumentRagRequest {
|
||||
query: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
"doc-limit"?: number; // Default: 20
|
||||
streaming?: boolean;
|
||||
}
|
||||
export class TextCompletionResponse extends S.Class<TextCompletionResponse>("TextCompletionResponse")({
|
||||
response: S.String,
|
||||
end_of_stream: S.optionalKey(S.Boolean),
|
||||
error: S.optionalKey(TypedMessageError),
|
||||
in_token: S.optionalKey(S.Finite),
|
||||
out_token: S.optionalKey(S.Finite),
|
||||
model: S.optionalKey(S.String),
|
||||
}, { description: "Text-completion response payload." }) {}
|
||||
|
||||
export interface DocumentRagResponse {
|
||||
response: string;
|
||||
// Streaming fields
|
||||
chunk?: string;
|
||||
end_of_stream?: boolean;
|
||||
endOfStream?: boolean;
|
||||
error?: {
|
||||
message: string;
|
||||
type?: string;
|
||||
};
|
||||
// Token usage (appears in final message)
|
||||
in_token?: number;
|
||||
out_token?: number;
|
||||
model?: string;
|
||||
// Explainability fields
|
||||
message_type?: "chunk" | "explain";
|
||||
explain_id?: string;
|
||||
explain_graph?: string;
|
||||
end_of_session?: boolean;
|
||||
}
|
||||
export class GraphRagRequest extends S.Class<GraphRagRequest>("GraphRagRequest")({
|
||||
query: S.String,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
"entity-limit": S.optionalKey(S.Finite),
|
||||
"triple-limit": S.optionalKey(S.Finite),
|
||||
"max-subgraph-size": S.optionalKey(S.Finite),
|
||||
"max-path-length": S.optionalKey(S.Finite),
|
||||
streaming: S.optionalKey(S.Boolean),
|
||||
}, { description: "Graph RAG request payload." }) {}
|
||||
|
||||
export interface AgentRequest {
|
||||
question: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
streaming?: boolean;
|
||||
}
|
||||
export class GraphRagResponse extends S.Class<GraphRagResponse>("GraphRagResponse")({
|
||||
response: S.String,
|
||||
chunk: S.optionalKey(S.String),
|
||||
end_of_stream: S.optionalKey(S.Boolean),
|
||||
endOfStream: S.optionalKey(S.Boolean),
|
||||
error: S.optionalKey(TypedMessageError),
|
||||
in_token: S.optionalKey(S.Finite),
|
||||
out_token: S.optionalKey(S.Finite),
|
||||
model: S.optionalKey(S.String),
|
||||
message_type: S.optionalKey(S.Literals(["chunk", "explain"])),
|
||||
explain_id: S.optionalKey(S.String),
|
||||
explain_graph: S.optionalKey(S.String),
|
||||
explain_triples: S.optionalKey(S.Array(S.Unknown).pipe(S.mutable)),
|
||||
end_of_session: S.optionalKey(S.Boolean),
|
||||
}, { description: "Graph RAG response payload." }) {}
|
||||
|
||||
export interface AgentResponse {
|
||||
// Streaming response format (new protocol)
|
||||
chunk_type?: "thought" | "action" | "observation" | "answer" | "final-answer" | "explain" | "error";
|
||||
content?: string;
|
||||
end_of_message?: boolean;
|
||||
end_of_dialog?: boolean;
|
||||
export class DocumentRagRequest extends S.Class<DocumentRagRequest>("DocumentRagRequest")({
|
||||
query: S.String,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
"doc-limit": S.optionalKey(S.Finite),
|
||||
streaming: S.optionalKey(S.Boolean),
|
||||
}, { description: "Document RAG request payload." }) {}
|
||||
|
||||
// Legacy fields for backward compatibility with non-streaming
|
||||
thought?: string;
|
||||
observation?: string;
|
||||
answer?: string;
|
||||
error?: ResponseError;
|
||||
export class DocumentRagResponse extends S.Class<DocumentRagResponse>("DocumentRagResponse")({
|
||||
response: S.String,
|
||||
chunk: S.optionalKey(S.String),
|
||||
end_of_stream: S.optionalKey(S.Boolean),
|
||||
endOfStream: S.optionalKey(S.Boolean),
|
||||
error: S.optionalKey(TypedMessageError),
|
||||
in_token: S.optionalKey(S.Finite),
|
||||
out_token: S.optionalKey(S.Finite),
|
||||
model: S.optionalKey(S.String),
|
||||
message_type: S.optionalKey(S.Literals(["chunk", "explain"])),
|
||||
explain_id: S.optionalKey(S.String),
|
||||
explain_graph: S.optionalKey(S.String),
|
||||
end_of_session: S.optionalKey(S.Boolean),
|
||||
}, { description: "Document RAG response payload." }) {}
|
||||
|
||||
// Token usage (appears in final message)
|
||||
in_token?: number;
|
||||
out_token?: number;
|
||||
model?: string;
|
||||
export class AgentRequest extends S.Class<AgentRequest>("AgentRequest")({
|
||||
question: S.String,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
streaming: S.optionalKey(S.Boolean),
|
||||
}, { description: "Agent request payload." }) {}
|
||||
|
||||
// Explainability fields
|
||||
message_type?: "chunk" | "explain";
|
||||
explain_id?: string;
|
||||
explain_graph?: string;
|
||||
explain_triples?: unknown[];
|
||||
}
|
||||
export class AgentResponse extends S.Class<AgentResponse>("AgentResponse")({
|
||||
chunk_type: S.optionalKey(S.Literals([
|
||||
"thought",
|
||||
"action",
|
||||
"observation",
|
||||
"answer",
|
||||
"final-answer",
|
||||
"explain",
|
||||
"error",
|
||||
])),
|
||||
content: S.optionalKey(S.String),
|
||||
end_of_message: S.optionalKey(S.Boolean),
|
||||
end_of_dialog: S.optionalKey(S.Boolean),
|
||||
thought: S.optionalKey(S.String),
|
||||
observation: S.optionalKey(S.String),
|
||||
answer: S.optionalKey(S.String),
|
||||
error: S.optionalKey(ResponseError),
|
||||
in_token: S.optionalKey(S.Finite),
|
||||
out_token: S.optionalKey(S.Finite),
|
||||
model: S.optionalKey(S.String),
|
||||
message_type: S.optionalKey(S.Literals(["chunk", "explain"])),
|
||||
explain_id: S.optionalKey(S.String),
|
||||
explain_graph: S.optionalKey(S.String),
|
||||
explain_triples: S.optionalKey(S.Array(S.Unknown).pipe(S.mutable)),
|
||||
}, { description: "Agent response payload." }) {}
|
||||
|
||||
export interface EmbeddingsRequest {
|
||||
texts: string[];
|
||||
}
|
||||
export class EmbeddingsRequest extends S.Class<EmbeddingsRequest>("EmbeddingsRequest")({
|
||||
texts: StringArray,
|
||||
}, { description: "Batch embeddings request payload." }) {}
|
||||
|
||||
export interface EmbeddingsResponse {
|
||||
vectors: number[][]; // One vector per input text
|
||||
}
|
||||
export class EmbeddingsResponse extends S.Class<EmbeddingsResponse>("EmbeddingsResponse")({
|
||||
vectors: NumberMatrix,
|
||||
}, { description: "Batch embeddings response payload." }) {}
|
||||
|
||||
export interface GraphEmbeddingsQueryRequest {
|
||||
vector: number[]; // Single query vector
|
||||
limit: number;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
}
|
||||
export class GraphEmbeddingsQueryRequest extends S.Class<GraphEmbeddingsQueryRequest>("GraphEmbeddingsQueryRequest")({
|
||||
vector: NumberArray,
|
||||
limit: S.Finite,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
}, { description: "Graph embeddings query request payload." }) {}
|
||||
|
||||
export interface EntityMatch {
|
||||
entity: Term | null;
|
||||
score: number;
|
||||
}
|
||||
export class EntityMatch extends S.Class<EntityMatch>("EntityMatch")({
|
||||
entity: S.NullOr(Term),
|
||||
score: S.Finite,
|
||||
}, { description: "Scored graph-entity match." }) {}
|
||||
|
||||
export interface GraphEmbeddingsQueryResponse {
|
||||
entities: EntityMatch[];
|
||||
}
|
||||
export class GraphEmbeddingsQueryResponse extends S.Class<GraphEmbeddingsQueryResponse>("GraphEmbeddingsQueryResponse")({
|
||||
entities: S.Array(EntityMatch).pipe(S.mutable),
|
||||
}, { description: "Graph embeddings query response payload." }) {}
|
||||
|
||||
export interface TriplesQueryRequest {
|
||||
s?: Term;
|
||||
p?: Term;
|
||||
o?: Term;
|
||||
g?: string; // Named graph URI filter (plain string, not Term)
|
||||
limit: number;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
}
|
||||
export class TriplesQueryRequest extends S.Class<TriplesQueryRequest>("TriplesQueryRequest")({
|
||||
s: S.optionalKey(Term),
|
||||
p: S.optionalKey(Term),
|
||||
o: S.optionalKey(Term),
|
||||
g: S.optionalKey(S.String),
|
||||
limit: S.Finite,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
}, { description: "Triple pattern query request payload." }) {}
|
||||
|
||||
export interface TriplesQueryResponse {
|
||||
triples: Triple[];
|
||||
/** @deprecated Use `triples` — kept for backward compatibility */
|
||||
response?: Triple[];
|
||||
}
|
||||
export class TriplesQueryResponse extends S.Class<TriplesQueryResponse>("TriplesQueryResponse")({
|
||||
triples: TripleArray,
|
||||
response: S.optionalKey(TripleArray),
|
||||
}, { description: "Triple pattern query response payload." }) {}
|
||||
|
||||
export interface RowsQueryRequest {
|
||||
query: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
variables?: Record<string, unknown>;
|
||||
operation_name?: string;
|
||||
}
|
||||
export class RowsQueryRequest extends S.Class<RowsQueryRequest>("RowsQueryRequest")({
|
||||
query: S.String,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
variables: S.optionalKey(UnknownRecord),
|
||||
operation_name: S.optionalKey(S.String),
|
||||
}, { description: "Structured rows GraphQL request payload." }) {}
|
||||
|
||||
export interface RowsQueryResponse {
|
||||
data?: Record<string, unknown>;
|
||||
errors?: Record<string, unknown>[];
|
||||
extensions?: Record<string, unknown>;
|
||||
values?: unknown[];
|
||||
}
|
||||
export class RowsQueryResponse extends S.Class<RowsQueryResponse>("RowsQueryResponse")({
|
||||
data: S.optionalKey(UnknownRecord),
|
||||
errors: S.optionalKey(S.Array(UnknownRecord).pipe(S.mutable)),
|
||||
extensions: S.optionalKey(UnknownRecord),
|
||||
values: S.optionalKey(S.Array(S.Unknown).pipe(S.mutable)),
|
||||
}, { description: "Structured rows GraphQL response payload." }) {}
|
||||
|
||||
export interface NlpQueryRequest {
|
||||
question: string;
|
||||
max_results?: number;
|
||||
}
|
||||
export class NlpQueryRequest extends S.Class<NlpQueryRequest>("NlpQueryRequest")({
|
||||
question: S.String,
|
||||
max_results: S.optionalKey(S.Finite),
|
||||
}, { description: "Natural-language-to-GraphQL request payload." }) {}
|
||||
|
||||
export interface NlpQueryResponse {
|
||||
graphql_query?: string;
|
||||
variables?: Record<string, unknown>;
|
||||
detected_schemas?: Record<string, unknown>[];
|
||||
confidence?: number;
|
||||
}
|
||||
export class NlpQueryResponse extends S.Class<NlpQueryResponse>("NlpQueryResponse")({
|
||||
graphql_query: S.optionalKey(S.String),
|
||||
variables: S.optionalKey(UnknownRecord),
|
||||
detected_schemas: S.optionalKey(S.Array(UnknownRecord).pipe(S.mutable)),
|
||||
confidence: S.optionalKey(S.Finite),
|
||||
}, { description: "Natural-language-to-GraphQL response payload." }) {}
|
||||
|
||||
export interface StructuredQueryRequest {
|
||||
question: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
}
|
||||
export class StructuredQueryRequest extends S.Class<StructuredQueryRequest>("StructuredQueryRequest")({
|
||||
question: S.String,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
}, { description: "Structured query request payload." }) {}
|
||||
|
||||
export interface StructuredQueryResponse {
|
||||
data?: Record<string, unknown>;
|
||||
errors?: Record<string, unknown>[];
|
||||
}
|
||||
export class StructuredQueryResponse extends S.Class<StructuredQueryResponse>("StructuredQueryResponse")({
|
||||
data: S.optionalKey(UnknownRecord),
|
||||
errors: S.optionalKey(S.Array(UnknownRecord).pipe(S.mutable)),
|
||||
}, { description: "Structured query response payload." }) {}
|
||||
|
||||
export interface RowEmbeddingsQueryRequest {
|
||||
vector: number[]; // Single query vector
|
||||
schema_name: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
index_name?: string;
|
||||
limit?: number;
|
||||
}
|
||||
export class RowEmbeddingsQueryRequest extends S.Class<RowEmbeddingsQueryRequest>("RowEmbeddingsQueryRequest")({
|
||||
vector: NumberArray,
|
||||
schema_name: S.String,
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
index_name: S.optionalKey(S.String),
|
||||
limit: S.optionalKey(S.Finite),
|
||||
}, { description: "Row embeddings query request payload." }) {}
|
||||
|
||||
export interface RowEmbeddingsMatch {
|
||||
index_name: string;
|
||||
index_value: string[];
|
||||
text: string;
|
||||
score: number;
|
||||
}
|
||||
export class RowEmbeddingsMatch extends S.Class<RowEmbeddingsMatch>("RowEmbeddingsMatch")({
|
||||
index_name: S.String,
|
||||
index_value: StringArray,
|
||||
text: S.String,
|
||||
score: S.Finite,
|
||||
}, { description: "Scored row embeddings match." }) {}
|
||||
|
||||
export interface RowEmbeddingsQueryResponse {
|
||||
matches?: RowEmbeddingsMatch[];
|
||||
error?: {
|
||||
message: string;
|
||||
type?: string;
|
||||
};
|
||||
}
|
||||
export class RowEmbeddingsQueryResponse extends S.Class<RowEmbeddingsQueryResponse>("RowEmbeddingsQueryResponse")({
|
||||
matches: S.optionalKey(S.Array(RowEmbeddingsMatch).pipe(S.mutable)),
|
||||
error: S.optionalKey(TypedMessageError),
|
||||
}, { description: "Row embeddings query response payload." }) {}
|
||||
|
||||
export interface LoadDocumentRequest {
|
||||
id?: string;
|
||||
data: string;
|
||||
metadata?: Triple[];
|
||||
}
|
||||
export class LoadDocumentRequest extends S.Class<LoadDocumentRequest>("LoadDocumentRequest")({
|
||||
id: S.optionalKey(S.String),
|
||||
data: S.String,
|
||||
metadata: S.optionalKey(TripleArray),
|
||||
}, { description: "Flow-scoped document load request payload." }) {}
|
||||
|
||||
export type LoadDocumentResponse = void;
|
||||
|
||||
export interface LoadTextRequest {
|
||||
id?: string;
|
||||
text: string;
|
||||
charset?: string;
|
||||
metadata?: Triple[];
|
||||
}
|
||||
export class LoadTextRequest extends S.Class<LoadTextRequest>("LoadTextRequest")({
|
||||
id: S.optionalKey(S.String),
|
||||
text: S.String,
|
||||
charset: S.optionalKey(S.String),
|
||||
metadata: S.optionalKey(TripleArray),
|
||||
}, { description: "Flow-scoped text load request payload." }) {}
|
||||
|
||||
export type LoadTextResponse = void;
|
||||
|
||||
export interface DocumentMetadata {
|
||||
id?: string;
|
||||
time?: number;
|
||||
kind?: string;
|
||||
title?: string;
|
||||
comments?: string;
|
||||
metadata?: Triple[];
|
||||
user?: string;
|
||||
tags?: string[];
|
||||
parentId?: string;
|
||||
documentType?: string;
|
||||
"parent-id"?: string;
|
||||
"document-type"?: string;
|
||||
}
|
||||
export class DocumentMetadata extends S.Class<DocumentMetadata>("DocumentMetadata")({
|
||||
id: S.optionalKey(S.String),
|
||||
time: S.optionalKey(S.Finite),
|
||||
kind: S.optionalKey(S.String),
|
||||
title: S.optionalKey(S.String),
|
||||
comments: S.optionalKey(S.String),
|
||||
metadata: S.optionalKey(TripleArray),
|
||||
user: S.optionalKey(S.String),
|
||||
tags: S.optionalKey(StringArray),
|
||||
parentId: S.optionalKey(S.String),
|
||||
documentType: S.optionalKey(S.String),
|
||||
"parent-id": S.optionalKey(S.String),
|
||||
"document-type": S.optionalKey(S.String),
|
||||
}, { description: "Library document metadata payload." }) {}
|
||||
|
||||
export interface ProcessingMetadata {
|
||||
id?: string;
|
||||
"document-id"?: string;
|
||||
documentId?: string;
|
||||
time?: number;
|
||||
flow?: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
tags?: string[];
|
||||
}
|
||||
export class ProcessingMetadata extends S.Class<ProcessingMetadata>("ProcessingMetadata")({
|
||||
id: S.optionalKey(S.String),
|
||||
"document-id": S.optionalKey(S.String),
|
||||
documentId: S.optionalKey(S.String),
|
||||
time: S.optionalKey(S.Finite),
|
||||
flow: S.optionalKey(S.String),
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
tags: S.optionalKey(StringArray),
|
||||
}, { description: "Library processing metadata payload." }) {}
|
||||
|
||||
export interface LibraryRequest {
|
||||
operation: string;
|
||||
documentId?: string;
|
||||
"document-id"?: string;
|
||||
processingId?: string;
|
||||
"processing-id"?: string;
|
||||
"document-metadata"?: DocumentMetadata;
|
||||
documentMetadata?: DocumentMetadata;
|
||||
"processing-metadata"?: ProcessingMetadata;
|
||||
content?: string;
|
||||
user?: string;
|
||||
collection?: string;
|
||||
metadata?: Triple[];
|
||||
id?: string;
|
||||
flow?: string;
|
||||
}
|
||||
export class LibraryRequest extends S.Class<LibraryRequest>("LibraryRequest")({
|
||||
operation: S.String,
|
||||
documentId: S.optionalKey(S.String),
|
||||
"document-id": S.optionalKey(S.String),
|
||||
processingId: S.optionalKey(S.String),
|
||||
"processing-id": S.optionalKey(S.String),
|
||||
"document-metadata": S.optionalKey(DocumentMetadata),
|
||||
documentMetadata: S.optionalKey(DocumentMetadata),
|
||||
"processing-metadata": S.optionalKey(ProcessingMetadata),
|
||||
content: S.optionalKey(S.String),
|
||||
user: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
metadata: S.optionalKey(TripleArray),
|
||||
id: S.optionalKey(S.String),
|
||||
flow: S.optionalKey(S.String),
|
||||
}, { description: "Library service request payload." }) {}
|
||||
|
||||
export interface LibraryResponse {
|
||||
error?: WireError;
|
||||
"document-metadata"?: DocumentMetadata;
|
||||
documentMetadata?: DocumentMetadata;
|
||||
content?: string;
|
||||
"document-metadatas"?: DocumentMetadata[];
|
||||
documents?: DocumentMetadata[];
|
||||
"processing-metadata"?: ProcessingMetadata;
|
||||
"processing-metadatas"?: ProcessingMetadata[];
|
||||
processing?: ProcessingMetadata[];
|
||||
}
|
||||
export class LibraryResponse extends S.Class<LibraryResponse>("LibraryResponse")({
|
||||
error: S.optionalKey(WireErrorValue),
|
||||
"document-metadata": S.optionalKey(DocumentMetadata),
|
||||
documentMetadata: S.optionalKey(DocumentMetadata),
|
||||
content: S.optionalKey(S.String),
|
||||
"document-metadatas": S.optionalKey(S.Array(DocumentMetadata).pipe(S.mutable)),
|
||||
documents: S.optionalKey(S.Array(DocumentMetadata).pipe(S.mutable)),
|
||||
"processing-metadata": S.optionalKey(ProcessingMetadata),
|
||||
"processing-metadatas": S.optionalKey(S.Array(ProcessingMetadata).pipe(S.mutable)),
|
||||
processing: S.optionalKey(S.Array(ProcessingMetadata).pipe(S.mutable)),
|
||||
}, { description: "Library service response payload." }) {}
|
||||
|
||||
export interface KnowledgeRequest {
|
||||
operation: string;
|
||||
user?: string;
|
||||
id?: string;
|
||||
flow?: string;
|
||||
collection?: string;
|
||||
triples?: Triple[];
|
||||
"graph-embeddings"?: GraphEmbeddings;
|
||||
graphEmbeddings?: GraphEmbeddings;
|
||||
"document-embeddings"?: unknown;
|
||||
documentEmbeddings?: unknown;
|
||||
}
|
||||
export class KnowledgeRequest extends S.Class<KnowledgeRequest>("KnowledgeRequest")({
|
||||
operation: S.String,
|
||||
user: S.optionalKey(S.String),
|
||||
id: S.optionalKey(S.String),
|
||||
flow: S.optionalKey(S.String),
|
||||
collection: S.optionalKey(S.String),
|
||||
triples: S.optionalKey(TripleArray),
|
||||
"graph-embeddings": S.optionalKey(GraphEmbeddings),
|
||||
graphEmbeddings: S.optionalKey(GraphEmbeddings),
|
||||
"document-embeddings": S.optionalKey(S.Unknown),
|
||||
documentEmbeddings: S.optionalKey(S.Unknown),
|
||||
}, { description: "Knowledge service request payload." }) {}
|
||||
|
||||
export interface KnowledgeResponse {
|
||||
error?: WireError;
|
||||
ids?: string[];
|
||||
eos?: boolean;
|
||||
triples?: Triple[];
|
||||
"graph-embeddings"?: GraphEmbeddings;
|
||||
graphEmbeddings?: GraphEmbeddings;
|
||||
"document-embeddings"?: unknown;
|
||||
documentEmbeddings?: unknown;
|
||||
}
|
||||
export class KnowledgeResponse extends S.Class<KnowledgeResponse>("KnowledgeResponse")({
|
||||
error: S.optionalKey(WireErrorValue),
|
||||
ids: S.optionalKey(StringArray),
|
||||
eos: S.optionalKey(S.Boolean),
|
||||
triples: S.optionalKey(TripleArray),
|
||||
"graph-embeddings": S.optionalKey(GraphEmbeddings),
|
||||
graphEmbeddings: S.optionalKey(GraphEmbeddings),
|
||||
"document-embeddings": S.optionalKey(S.Unknown),
|
||||
documentEmbeddings: S.optionalKey(S.Unknown),
|
||||
}, { description: "Knowledge service response payload." }) {}
|
||||
|
||||
export interface FlowRequest {
|
||||
operation: string;
|
||||
"blueprint-name"?: string;
|
||||
"blueprint-definition"?: string;
|
||||
description?: string;
|
||||
"flow-id"?: string;
|
||||
parameters?: Record<string, unknown>;
|
||||
user?: string;
|
||||
}
|
||||
export class FlowRequest extends S.Class<FlowRequest>("FlowRequest")({
|
||||
operation: S.String,
|
||||
"blueprint-name": S.optionalKey(S.String),
|
||||
"blueprint-definition": S.optionalKey(S.String),
|
||||
description: S.optionalKey(S.String),
|
||||
"flow-id": S.optionalKey(S.String),
|
||||
parameters: S.optionalKey(UnknownRecord),
|
||||
user: S.optionalKey(S.String),
|
||||
}, { description: "Flow service request payload." }) {}
|
||||
|
||||
export interface FlowResponse {
|
||||
"blueprint-names"?: string[];
|
||||
"flow-ids"?: string[];
|
||||
ids?: string[];
|
||||
flow?: string;
|
||||
"blueprint-definition"?: string;
|
||||
description?: string;
|
||||
error?:
|
||||
| {
|
||||
message?: string;
|
||||
}
|
||||
| WireError;
|
||||
}
|
||||
export class FlowResponse extends S.Class<FlowResponse>("FlowResponse")({
|
||||
"blueprint-names": S.optionalKey(StringArray),
|
||||
"flow-ids": S.optionalKey(StringArray),
|
||||
ids: S.optionalKey(StringArray),
|
||||
flow: S.optionalKey(S.String),
|
||||
"blueprint-definition": S.optionalKey(S.String),
|
||||
description: S.optionalKey(S.String),
|
||||
error: S.optionalKey(S.Union([OptionalMessageError, WireErrorValue])),
|
||||
}, { description: "Flow service response payload." }) {}
|
||||
|
||||
export interface PromptRequest {
|
||||
id: string;
|
||||
terms: Record<string, unknown>;
|
||||
streaming?: boolean;
|
||||
}
|
||||
export class PromptRequest extends S.Class<PromptRequest>("PromptRequest")({
|
||||
id: S.String,
|
||||
terms: UnknownRecord,
|
||||
streaming: S.optionalKey(S.Boolean),
|
||||
}, { description: "Prompt rendering request payload." }) {}
|
||||
|
||||
export interface PromptResponse {
|
||||
text: string;
|
||||
// Streaming fields
|
||||
end_of_stream?: boolean;
|
||||
error?: {
|
||||
message: string;
|
||||
type?: string;
|
||||
};
|
||||
// Token usage (appears in final message)
|
||||
in_token?: number;
|
||||
out_token?: number;
|
||||
model?: string;
|
||||
}
|
||||
export class PromptResponse extends S.Class<PromptResponse>("PromptResponse")({
|
||||
text: S.String,
|
||||
end_of_stream: S.optionalKey(S.Boolean),
|
||||
error: S.optionalKey(TypedMessageError),
|
||||
in_token: S.optionalKey(S.Finite),
|
||||
out_token: S.optionalKey(S.Finite),
|
||||
model: S.optionalKey(S.String),
|
||||
}, { description: "Prompt rendering response payload." }) {}
|
||||
|
||||
export type ConfigRequest = object;
|
||||
export type ConfigResponse = object;
|
||||
|
||||
// Chunked Upload Types
|
||||
export class ChunkedUploadDocumentMetadata extends S.Class<ChunkedUploadDocumentMetadata>("ChunkedUploadDocumentMetadata")({
|
||||
id: S.String,
|
||||
time: S.Finite,
|
||||
kind: S.String,
|
||||
title: S.String,
|
||||
comments: S.optionalKey(S.String),
|
||||
metadata: S.optionalKey(TripleArray),
|
||||
user: S.String,
|
||||
collection: S.optionalKey(S.String),
|
||||
tags: S.optionalKey(StringArray),
|
||||
}, { description: "Document metadata used to begin a chunked upload." }) {}
|
||||
|
||||
export interface ChunkedUploadDocumentMetadata {
|
||||
id: string;
|
||||
time: number;
|
||||
kind: string;
|
||||
title: string;
|
||||
comments?: string;
|
||||
metadata?: Triple[];
|
||||
user: string;
|
||||
collection?: string;
|
||||
tags?: string[];
|
||||
}
|
||||
export class BeginUploadRequest extends S.Class<BeginUploadRequest>("BeginUploadRequest")({
|
||||
operation: S.Literal("begin-upload"),
|
||||
"document-metadata": S.optionalKey(ChunkedUploadDocumentMetadata),
|
||||
documentMetadata: S.optionalKey(ChunkedUploadDocumentMetadata),
|
||||
"total-size": S.Finite,
|
||||
"chunk-size": S.optionalKey(S.Finite),
|
||||
}, { description: "Chunked upload begin request payload." }) {}
|
||||
|
||||
export interface BeginUploadRequest {
|
||||
operation: "begin-upload";
|
||||
"document-metadata"?: ChunkedUploadDocumentMetadata;
|
||||
documentMetadata?: ChunkedUploadDocumentMetadata;
|
||||
"total-size": number;
|
||||
"chunk-size"?: number;
|
||||
}
|
||||
export class BeginUploadResponse extends S.Class<BeginUploadResponse>("BeginUploadResponse")({
|
||||
"upload-id": S.String,
|
||||
"chunk-size": S.Finite,
|
||||
"total-chunks": S.Finite,
|
||||
error: S.optionalKey(ResponseError),
|
||||
}, { description: "Chunked upload begin response payload." }) {}
|
||||
|
||||
export interface BeginUploadResponse {
|
||||
"upload-id": string;
|
||||
"chunk-size": number;
|
||||
"total-chunks": number;
|
||||
error?: ResponseError;
|
||||
}
|
||||
export class UploadChunkRequest extends S.Class<UploadChunkRequest>("UploadChunkRequest")({
|
||||
operation: S.Literal("upload-chunk"),
|
||||
"upload-id": S.String,
|
||||
"chunk-index": S.Finite,
|
||||
content: S.String,
|
||||
user: S.String,
|
||||
}, { description: "Chunked upload chunk request payload." }) {}
|
||||
|
||||
export interface UploadChunkRequest {
|
||||
operation: "upload-chunk";
|
||||
"upload-id": string;
|
||||
"chunk-index": number;
|
||||
content: string; // base64-encoded
|
||||
user: string;
|
||||
}
|
||||
export class UploadChunkResponse extends S.Class<UploadChunkResponse>("UploadChunkResponse")({
|
||||
"upload-id": S.String,
|
||||
"chunk-index": S.Finite,
|
||||
"chunks-received": S.Finite,
|
||||
"total-chunks": S.Finite,
|
||||
"bytes-received": S.Finite,
|
||||
"total-bytes": S.Finite,
|
||||
error: S.optionalKey(ResponseError),
|
||||
}, { description: "Chunked upload chunk response payload." }) {}
|
||||
|
||||
export interface UploadChunkResponse {
|
||||
"upload-id": string;
|
||||
"chunk-index": number;
|
||||
"chunks-received": number;
|
||||
"total-chunks": number;
|
||||
"bytes-received": number;
|
||||
"total-bytes": number;
|
||||
error?: ResponseError;
|
||||
}
|
||||
export class CompleteUploadRequest extends S.Class<CompleteUploadRequest>("CompleteUploadRequest")({
|
||||
operation: S.Literal("complete-upload"),
|
||||
"upload-id": S.String,
|
||||
user: S.String,
|
||||
}, { description: "Chunked upload completion request payload." }) {}
|
||||
|
||||
export interface CompleteUploadRequest {
|
||||
operation: "complete-upload";
|
||||
"upload-id": string;
|
||||
user: string;
|
||||
}
|
||||
export class CompleteUploadResponse extends S.Class<CompleteUploadResponse>("CompleteUploadResponse")({
|
||||
"document-id": S.String,
|
||||
"object-id": S.String,
|
||||
error: S.optionalKey(ResponseError),
|
||||
}, { description: "Chunked upload completion response payload." }) {}
|
||||
|
||||
export interface CompleteUploadResponse {
|
||||
"document-id": string;
|
||||
"object-id": string;
|
||||
error?: ResponseError;
|
||||
}
|
||||
export class GetUploadStatusRequest extends S.Class<GetUploadStatusRequest>("GetUploadStatusRequest")({
|
||||
operation: S.Literal("get-upload-status"),
|
||||
"upload-id": S.String,
|
||||
user: S.String,
|
||||
}, { description: "Chunked upload status request payload." }) {}
|
||||
|
||||
export interface GetUploadStatusRequest {
|
||||
operation: "get-upload-status";
|
||||
"upload-id": string;
|
||||
user: string;
|
||||
}
|
||||
export class GetUploadStatusResponse extends S.Class<GetUploadStatusResponse>("GetUploadStatusResponse")({
|
||||
"upload-id": S.String,
|
||||
"upload-state": S.Literals(["in-progress", "completed", "expired"]),
|
||||
"chunks-received": S.Finite,
|
||||
"total-chunks": S.Finite,
|
||||
"received-chunks": S.Array(S.Finite).pipe(S.mutable),
|
||||
"missing-chunks": S.Array(S.Finite).pipe(S.mutable),
|
||||
"bytes-received": S.Finite,
|
||||
"total-bytes": S.Finite,
|
||||
error: S.optionalKey(ResponseError),
|
||||
}, { description: "Chunked upload status response payload." }) {}
|
||||
|
||||
export interface GetUploadStatusResponse {
|
||||
"upload-id": string;
|
||||
"upload-state": "in-progress" | "completed" | "expired";
|
||||
"chunks-received": number;
|
||||
"total-chunks": number;
|
||||
"received-chunks": number[];
|
||||
"missing-chunks": number[];
|
||||
"bytes-received": number;
|
||||
"total-bytes": number;
|
||||
error?: ResponseError;
|
||||
}
|
||||
export class AbortUploadRequest extends S.Class<AbortUploadRequest>("AbortUploadRequest")({
|
||||
operation: S.Literal("abort-upload"),
|
||||
"upload-id": S.String,
|
||||
user: S.String,
|
||||
}, { description: "Chunked upload abort request payload." }) {}
|
||||
|
||||
export interface AbortUploadRequest {
|
||||
operation: "abort-upload";
|
||||
"upload-id": string;
|
||||
user: string;
|
||||
}
|
||||
export class AbortUploadResponse extends S.Class<AbortUploadResponse>("AbortUploadResponse")({
|
||||
error: S.optionalKey(ResponseError),
|
||||
}, { description: "Chunked upload abort response payload." }) {}
|
||||
|
||||
export interface AbortUploadResponse {
|
||||
error?: ResponseError;
|
||||
}
|
||||
export class ListUploadsRequest extends S.Class<ListUploadsRequest>("ListUploadsRequest")({
|
||||
operation: S.Literal("list-uploads"),
|
||||
user: S.String,
|
||||
}, { description: "Pending uploads list request payload." }) {}
|
||||
|
||||
export interface ListUploadsRequest {
|
||||
operation: "list-uploads";
|
||||
user: string;
|
||||
}
|
||||
export class UploadSession extends S.Class<UploadSession>("UploadSession")({
|
||||
"upload-id": S.String,
|
||||
"document-id": S.String,
|
||||
"document-metadata-json": S.String,
|
||||
"total-size": S.Finite,
|
||||
"chunk-size": S.Finite,
|
||||
"total-chunks": S.Finite,
|
||||
"chunks-received": S.Finite,
|
||||
"created-at": S.String,
|
||||
}, { description: "Pending upload session payload." }) {}
|
||||
|
||||
export interface UploadSession {
|
||||
"upload-id": string;
|
||||
"document-id": string;
|
||||
"document-metadata-json": string;
|
||||
"total-size": number;
|
||||
"chunk-size": number;
|
||||
"total-chunks": number;
|
||||
"chunks-received": number;
|
||||
"created-at": string;
|
||||
}
|
||||
export class ListUploadsResponse extends S.Class<ListUploadsResponse>("ListUploadsResponse")({
|
||||
"upload-sessions": S.Array(UploadSession).pipe(S.mutable),
|
||||
error: S.optionalKey(ResponseError),
|
||||
}, { description: "Pending uploads list response payload." }) {}
|
||||
|
||||
export interface ListUploadsResponse {
|
||||
"upload-sessions": UploadSession[];
|
||||
error?: ResponseError;
|
||||
}
|
||||
export class StreamDocumentRequest extends S.Class<StreamDocumentRequest>("StreamDocumentRequest")({
|
||||
operation: S.Literal("stream-document"),
|
||||
"document-id": S.String,
|
||||
"chunk-size": S.optionalKey(S.Finite),
|
||||
user: S.String,
|
||||
}, { description: "Document chunk stream request payload." }) {}
|
||||
|
||||
export interface StreamDocumentRequest {
|
||||
operation: "stream-document";
|
||||
"document-id": string;
|
||||
"chunk-size"?: number;
|
||||
user: string;
|
||||
}
|
||||
|
||||
export interface StreamDocumentResponse {
|
||||
content: string; // base64-encoded chunk
|
||||
"chunk-index": number;
|
||||
"total-chunks": number;
|
||||
error?: ResponseError;
|
||||
}
|
||||
export class StreamDocumentResponse extends S.Class<StreamDocumentResponse>("StreamDocumentResponse")({
|
||||
content: S.String,
|
||||
"chunk-index": S.Finite,
|
||||
"total-chunks": S.Finite,
|
||||
error: S.optionalKey(ResponseError),
|
||||
}, { description: "Document chunk stream response payload." }) {}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Cause, Context, Effect, Exit, Fiber, Layer, Ref, Scope, Stream, SubscriptionRef } from "effect";
|
||||
import { Cause, Context, Effect, Fiber, Layer, Ref, Schema as S, Scope, Stream, SubscriptionRef } from "effect";
|
||||
import type * as RpcGroup from "effect/unstable/rpc/RpcGroup";
|
||||
import * as RpcClient from "effect/unstable/rpc/RpcClient";
|
||||
import type { RpcClientError } from "effect/unstable/rpc/RpcClientError";
|
||||
|
|
@ -19,17 +19,17 @@ class TrustGraphRpcClientService extends Context.Service<
|
|||
|
||||
export type RpcConnectionStatus = "connecting" | "connected" | "failed" | "closed";
|
||||
|
||||
export interface RpcConnectionState {
|
||||
status: RpcConnectionStatus;
|
||||
lastError?: string;
|
||||
}
|
||||
export class RpcConnectionState extends S.Class<RpcConnectionState>("RpcConnectionState")({
|
||||
status: S.Literals(["connecting", "connected", "failed", "closed"]),
|
||||
lastError: S.optionalKey(S.String),
|
||||
}, { description: "Current Effect RPC gateway connection state." }) {}
|
||||
|
||||
export interface DispatchInput {
|
||||
scope: "global" | "flow";
|
||||
service: string;
|
||||
flow?: string;
|
||||
request: Record<string, unknown>;
|
||||
}
|
||||
export class DispatchInput extends S.Class<DispatchInput>("DispatchInput")({
|
||||
scope: S.Literals(["global", "flow"]),
|
||||
service: S.String,
|
||||
flow: S.optionalKey(S.String),
|
||||
request: S.Record(S.String, S.Unknown),
|
||||
}, { description: "TrustGraph gateway dispatch target and request payload." }) {}
|
||||
|
||||
export interface DispatchOptions {
|
||||
readonly timeoutMs?: number;
|
||||
|
|
@ -74,20 +74,6 @@ export interface TrustGraphGatewayClientOptions {
|
|||
const DEFAULT_REQUEST_TIMEOUT_MS = 10_000;
|
||||
const DEFAULT_REQUEST_ATTEMPTS = 3;
|
||||
|
||||
export interface EffectRpcClient {
|
||||
readonly subscribe: (listener: (state: RpcConnectionState) => void) => () => void;
|
||||
readonly dispatch: (
|
||||
input: DispatchInput,
|
||||
options?: DispatchOptions,
|
||||
) => Promise<unknown>;
|
||||
readonly dispatchStream: (
|
||||
input: DispatchInput,
|
||||
receiver: (chunk: DispatchStreamChunk) => boolean,
|
||||
options?: DispatchOptions,
|
||||
) => Promise<DispatchStreamChunk | undefined>;
|
||||
readonly close: () => Promise<void>;
|
||||
}
|
||||
|
||||
const makeClientLayer = (
|
||||
options: TrustGraphGatewayClientOptions,
|
||||
stateRef: SubscriptionRef.SubscriptionRef<RpcConnectionState>,
|
||||
|
|
@ -234,59 +220,12 @@ export function makeEffectRpcClient(
|
|||
url: string,
|
||||
onConnect?: () => void,
|
||||
onDisconnect?: () => void,
|
||||
): EffectRpcClient {
|
||||
const stateRef = Effect.runSync(SubscriptionRef.make<RpcConnectionState>({ status: "connecting" }));
|
||||
const closedRef = Effect.runSync(Ref.make(false));
|
||||
const scope = Effect.runSync(Scope.make());
|
||||
const options: TrustGraphGatewayClientOptions = {
|
||||
): Effect.Effect<TrustGraphGatewayClient, never, Scope.Scope> {
|
||||
return makeTrustGraphGatewayClientScoped({
|
||||
url,
|
||||
stateRef,
|
||||
closedRef,
|
||||
...(onConnect === undefined ? {} : { onConnect }),
|
||||
...(onDisconnect === undefined ? {} : { onDisconnect }),
|
||||
};
|
||||
const clientPromise = Effect.runPromise(
|
||||
makeTrustGraphGatewayClientScoped(options).pipe(Scope.provide(scope)),
|
||||
);
|
||||
|
||||
return {
|
||||
subscribe: (listener) => {
|
||||
let unsubscribe: Effect.Effect<void> | undefined;
|
||||
let cancelled = false;
|
||||
listener(SubscriptionRef.getUnsafe(stateRef));
|
||||
void clientPromise.then((client) =>
|
||||
Effect.runPromise(client.subscribe(listener)).then((release) => {
|
||||
if (cancelled) {
|
||||
return Effect.runPromise(release);
|
||||
}
|
||||
unsubscribe = release;
|
||||
})
|
||||
);
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
if (unsubscribe !== undefined) {
|
||||
Effect.runFork(unsubscribe);
|
||||
}
|
||||
};
|
||||
},
|
||||
dispatch: (input, options = {}) =>
|
||||
clientPromise.then((client) =>
|
||||
Effect.runPromise(client.dispatch(input, options))
|
||||
),
|
||||
dispatchStream: (input, receiver, options = {}) =>
|
||||
clientPromise.then((client) =>
|
||||
Effect.runPromise(client.runDispatchStream(input, receiver, options))
|
||||
),
|
||||
close: () =>
|
||||
clientPromise.then((client) =>
|
||||
Effect.runPromise(
|
||||
client.close.pipe(
|
||||
Effect.andThen(Scope.close(scope, Exit.void)),
|
||||
),
|
||||
)
|
||||
),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function withDispatchRequestPolicy<A, E, R>(
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
// Import core types and classes for the TrustGraph API
|
||||
import type { Term, Triple } from "../models/Triple.js";
|
||||
import { Triple } from "../models/Triple.js";
|
||||
import type { Term } from "../models/Triple.js";
|
||||
import type {
|
||||
EffectRpcClient,
|
||||
DispatchInput,
|
||||
DispatchOptions,
|
||||
RpcConnectionState,
|
||||
} from "./effect-rpc-client.js";
|
||||
import {
|
||||
makeEffectRpcClient,
|
||||
} from "./effect-rpc-client.js";
|
||||
import { getDefaultSocketUrl, getRandomValues } from "./websocket-adapter.js";
|
||||
import { Clock, Effect, Fiber, Match, Option, Result, Schema as S, Stream, SubscriptionRef } from "effect";
|
||||
import { Match, Option, Schema as S } from "effect";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
|
||||
// Import all message types for different services
|
||||
|
|
@ -89,19 +86,32 @@ export interface GraphRagOptions {
|
|||
pathLength?: number;
|
||||
}
|
||||
|
||||
// Metadata included in final streaming message
|
||||
export interface StreamingMetadata {
|
||||
in_token?: number;
|
||||
out_token?: number;
|
||||
model?: string;
|
||||
export interface LegacyRpcClient {
|
||||
readonly subscribe: (listener: (state: RpcConnectionState) => void) => () => void;
|
||||
readonly dispatch: (
|
||||
input: DispatchInput,
|
||||
options?: DispatchOptions,
|
||||
) => Promise<unknown>;
|
||||
readonly dispatchStream: (
|
||||
input: DispatchInput,
|
||||
receiver: (chunk: { readonly response: unknown; readonly complete: boolean }) => boolean,
|
||||
options?: DispatchOptions,
|
||||
) => Promise<unknown>;
|
||||
readonly close: () => Promise<void>;
|
||||
}
|
||||
|
||||
// Explainability event data
|
||||
export interface ExplainEvent {
|
||||
explainId: string;
|
||||
explainGraph: string; // Named graph where explain data is stored (e.g., urn:graph:retrieval)
|
||||
explainTriples?: Triple[]; // Inline subgraph triples (when available)
|
||||
}
|
||||
// Metadata included in final streaming message
|
||||
export class StreamingMetadata extends S.Class<StreamingMetadata>("StreamingMetadata")({
|
||||
in_token: S.optionalKey(S.Finite),
|
||||
out_token: S.optionalKey(S.Finite),
|
||||
model: S.optionalKey(S.String),
|
||||
}, { description: "Token and model metadata attached to a final streaming chunk." }) {}
|
||||
|
||||
export class ExplainEvent extends S.Class<ExplainEvent>("ExplainEvent")({
|
||||
explainId: S.String,
|
||||
explainGraph: S.String,
|
||||
explainTriples: S.optionalKey(S.Array(Triple).pipe(S.mutable)),
|
||||
}, { description: "Explainability graph reference or inline triples for a stream." }) {}
|
||||
|
||||
// Configuration constants
|
||||
const SOCKET_URL = getDefaultSocketUrl(); // WebSocket endpoint path (isomorphic)
|
||||
|
|
@ -155,7 +165,11 @@ function dispatchOptions(
|
|||
}
|
||||
|
||||
function streamingMetadataFrom(source: unknown): StreamingMetadata | undefined {
|
||||
const metadata: StreamingMetadata = {};
|
||||
const metadata: {
|
||||
in_token?: number;
|
||||
out_token?: number;
|
||||
model?: string;
|
||||
} = {};
|
||||
let hasMetadata = false;
|
||||
|
||||
const inToken = numberProperty(source, "in_token");
|
||||
|
|
@ -185,12 +199,12 @@ function throwIfResponseError(error: ResponseError | undefined): void {
|
|||
|
||||
const decodeJsonUnknown = S.decodeUnknownOption(S.UnknownFromJsonString);
|
||||
|
||||
export interface ConfigValueEntry {
|
||||
workspace?: string;
|
||||
type?: string;
|
||||
key: string;
|
||||
value: unknown;
|
||||
}
|
||||
export class ConfigValueEntry extends S.Class<ConfigValueEntry>("ConfigValueEntry")({
|
||||
workspace: S.optionalKey(S.String),
|
||||
type: S.optionalKey(S.String),
|
||||
key: S.String,
|
||||
value: S.Unknown,
|
||||
}, { description: "Config key/value entry returned from the TrustGraph config service." }) {}
|
||||
|
||||
function asConfigValues(response: unknown): ConfigValueEntry[] {
|
||||
if (response === null || typeof response !== "object") return [];
|
||||
|
|
@ -201,9 +215,12 @@ function asConfigValues(response: unknown): ConfigValueEntry[] {
|
|||
const item = value as Record<string, unknown>;
|
||||
const key = item.key;
|
||||
if (typeof key !== "string") return [];
|
||||
const entry: ConfigValueEntry = { key, value: item.value };
|
||||
if (typeof item.workspace === "string") entry.workspace = item.workspace;
|
||||
if (typeof item.type === "string") entry.type = item.type;
|
||||
const entry: ConfigValueEntry = {
|
||||
key,
|
||||
value: item.value,
|
||||
...(typeof item.workspace === "string" ? { workspace: item.workspace } : {}),
|
||||
...(typeof item.type === "string" ? { type: item.type } : {}),
|
||||
};
|
||||
return [entry];
|
||||
});
|
||||
}
|
||||
|
|
@ -222,15 +239,11 @@ function parseResponseJson(value: string | undefined, operation: string): unknow
|
|||
}
|
||||
|
||||
const currentEpochSeconds = (): number =>
|
||||
Math.floor(Effect.runSync(Clock.currentTimeMillis) / 1000);
|
||||
Math.floor((globalThis.performance.timeOrigin + globalThis.performance.now()) / 1000);
|
||||
|
||||
const logClientInfo = (message: string): void => {
|
||||
Effect.runFork(Effect.log(message));
|
||||
};
|
||||
const logClientInfo = (_message: string): void => {};
|
||||
|
||||
const logClientError = (message: string, error: unknown): void => {
|
||||
Effect.runFork(Effect.logError(message, { error: toErrorMessage(error, message) }));
|
||||
};
|
||||
const logClientError = (_message: string, _error: unknown): void => {};
|
||||
|
||||
const runLegacyStreamingRequest = (
|
||||
operation: string,
|
||||
|
|
@ -238,18 +251,9 @@ const runLegacyStreamingRequest = (
|
|||
request: () => Promise<unknown>,
|
||||
onError: (message: string) => void,
|
||||
): Promise<unknown | void> =>
|
||||
Effect.runPromise(
|
||||
Effect.tryPromise({
|
||||
try: request,
|
||||
catch: (error) => socketError(operation, toErrorMessage(error, "Unknown error")),
|
||||
}).pipe(
|
||||
Effect.catch((error) =>
|
||||
Effect.sync(() => {
|
||||
onError(`${label} request failed: ${error.message}`);
|
||||
})
|
||||
),
|
||||
),
|
||||
);
|
||||
request().catch((error) => {
|
||||
onError(`${label} request failed: ${toErrorMessage(error, `${operation} failed`)}`);
|
||||
});
|
||||
|
||||
const StreamingEnvelopeSchema = S.Struct({
|
||||
response: S.optionalKey(S.Unknown),
|
||||
|
|
@ -453,34 +457,35 @@ function makeid(length: number) {
|
|||
* functionality
|
||||
*/
|
||||
// Connection state interface for UI consumption
|
||||
export interface ConnectionState {
|
||||
status:
|
||||
| "connecting"
|
||||
| "connected"
|
||||
| "reconnecting"
|
||||
| "failed"
|
||||
| "authenticated"
|
||||
| "unauthenticated";
|
||||
hasApiKey: boolean;
|
||||
reconnectAttempt?: number;
|
||||
maxAttempts?: number;
|
||||
nextRetryIn?: number;
|
||||
lastError?: string;
|
||||
}
|
||||
export class ConnectionState extends S.Class<ConnectionState>("ConnectionState")({
|
||||
status: S.Literals([
|
||||
"connecting",
|
||||
"connected",
|
||||
"reconnecting",
|
||||
"failed",
|
||||
"authenticated",
|
||||
"unauthenticated",
|
||||
]),
|
||||
hasApiKey: S.Boolean,
|
||||
reconnectAttempt: S.optionalKey(S.Finite),
|
||||
maxAttempts: S.optionalKey(S.Finite),
|
||||
nextRetryIn: S.optionalKey(S.Finite),
|
||||
lastError: S.optionalKey(S.String),
|
||||
}, { description: "Workbench-facing TrustGraph gateway connection state." }) {}
|
||||
|
||||
export function makeBaseApi(
|
||||
user: string,
|
||||
token?: string,
|
||||
socketUrl?: string,
|
||||
rpcFactory: (url: string) => EffectRpcClient = makeEffectRpcClient,
|
||||
token: string | undefined,
|
||||
socketUrl: string | undefined,
|
||||
rpcFactory: (url: string) => LegacyRpcClient,
|
||||
) {
|
||||
let rpc: EffectRpcClient;
|
||||
const connectionStateRef = Effect.runSync(
|
||||
SubscriptionRef.make<ConnectionState>({
|
||||
status: "connecting",
|
||||
hasApiKey: isNonEmptyString(token),
|
||||
}),
|
||||
);
|
||||
let rpc: LegacyRpcClient;
|
||||
let unsubscribeRpc: (() => void) | undefined;
|
||||
const connectionStateListeners = new Set<(state: ConnectionState) => void>();
|
||||
let connectionState: ConnectionState = {
|
||||
status: "connecting",
|
||||
hasApiKey: isNonEmptyString(token),
|
||||
};
|
||||
let lastError: string | undefined ;
|
||||
let rpcState: RpcConnectionState = { status: "connecting" };
|
||||
|
||||
|
|
@ -495,27 +500,10 @@ export function makeBaseApi(
|
|||
* Subscribe to connection state changes for UI updates
|
||||
*/
|
||||
onConnectionStateChange(listener: (state: ConnectionState) => void) {
|
||||
let latest = SubscriptionRef.getUnsafe(connectionStateRef);
|
||||
listener(latest);
|
||||
let replaySeen = false;
|
||||
const fiber = Effect.runFork(
|
||||
SubscriptionRef.changes(connectionStateRef).pipe(
|
||||
Stream.runForEach((state) =>
|
||||
Effect.sync(() => {
|
||||
if (!replaySeen) {
|
||||
replaySeen = true;
|
||||
if (state === latest) return;
|
||||
}
|
||||
latest = state;
|
||||
notifyConnectionStateListener(listener, state);
|
||||
})
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Return unsubscribe function
|
||||
connectionStateListeners.add(listener);
|
||||
notifyConnectionStateListener(listener, connectionState);
|
||||
return () => {
|
||||
Effect.runFork(Fiber.interrupt(fiber));
|
||||
connectionStateListeners.delete(listener);
|
||||
};
|
||||
},
|
||||
|
||||
|
|
@ -523,13 +511,9 @@ export function makeBaseApi(
|
|||
* Closes the WebSocket connection and cleans up
|
||||
*/
|
||||
close() {
|
||||
Effect.runFork(
|
||||
Effect.tryPromise({
|
||||
try: () => rpc.close(),
|
||||
catch: (error) => socketError("socket-close", toErrorMessage(error, "Socket close failed")),
|
||||
}).pipe(
|
||||
Effect.catch((error) => Effect.sync(() => logClientError("[socket close error]", error))),
|
||||
),
|
||||
unsubscribeRpc?.();
|
||||
void rpc.close().catch((error) =>
|
||||
logClientError("[socket close error]", socketError("socket-close", toErrorMessage(error, "Socket close failed")))
|
||||
);
|
||||
},
|
||||
|
||||
|
|
@ -643,10 +627,8 @@ export function makeBaseApi(
|
|||
const state: ConnectionState = {
|
||||
status,
|
||||
hasApiKey,
|
||||
...(lastError !== undefined ? { lastError } : {}),
|
||||
};
|
||||
if (lastError !== undefined) {
|
||||
state.lastError = lastError;
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
|
|
@ -655,21 +637,24 @@ export function makeBaseApi(
|
|||
listener: (state: ConnectionState) => void,
|
||||
state: ConnectionState,
|
||||
): void => {
|
||||
const result = Result.try({
|
||||
try: () => listener(state),
|
||||
catch: (error) =>
|
||||
try {
|
||||
listener(state);
|
||||
} catch (error) {
|
||||
logClientError(
|
||||
"Error in connection state listener",
|
||||
socketError(
|
||||
"connection-state-listener",
|
||||
toErrorMessage(error, "Error in connection state listener"),
|
||||
),
|
||||
});
|
||||
if (Result.isFailure(result)) {
|
||||
logClientError("Error in connection state listener", result.failure);
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const publishConnectionState = () => {
|
||||
Effect.runSync(SubscriptionRef.set(connectionStateRef, getConnectionState()));
|
||||
connectionState = getConnectionState();
|
||||
for (const listener of connectionStateListeners) {
|
||||
notifyConnectionStateListener(listener, connectionState);
|
||||
}
|
||||
};
|
||||
|
||||
const connectionStatusFromRpc = (hasApiKey: boolean): ConnectionState["status"] =>
|
||||
|
|
@ -712,7 +697,7 @@ export function makeBaseApi(
|
|||
};
|
||||
|
||||
rpc = rpcFactory(socketUrlWithToken());
|
||||
rpc.subscribe((state) => {
|
||||
unsubscribeRpc = rpc.subscribe((state) => {
|
||||
rpcState = state;
|
||||
lastError = state.lastError;
|
||||
publishConnectionState();
|
||||
|
|
@ -726,13 +711,12 @@ export function makeBaseApi(
|
|||
}
|
||||
|
||||
export type BaseApi = ReturnType<typeof makeBaseApi>;
|
||||
export const BaseApi = makeBaseApi;
|
||||
|
||||
export function makeBaseApiWithRpc(
|
||||
user: string,
|
||||
token: string | undefined,
|
||||
socketUrl: string | undefined,
|
||||
rpc: EffectRpcClient,
|
||||
rpc: LegacyRpcClient,
|
||||
): BaseApi {
|
||||
return makeBaseApi(user, token, socketUrl, () => rpc);
|
||||
}
|
||||
|
|
@ -833,13 +817,9 @@ export function makeLibrarianApi(api: BaseApi) {
|
|||
tags,
|
||||
"document-type": "source",
|
||||
documentType: "source",
|
||||
...(id !== undefined ? { id } : {}),
|
||||
...(metadata !== undefined ? { metadata } : {}),
|
||||
};
|
||||
if (id !== undefined) {
|
||||
documentMetadata.id = id;
|
||||
}
|
||||
if (metadata !== undefined) {
|
||||
documentMetadata.metadata = metadata;
|
||||
}
|
||||
|
||||
return this.api.makeRequest<LibraryRequest, LibraryResponse>(
|
||||
"librarian",
|
||||
|
|
@ -929,10 +909,8 @@ export function makeLibrarianApi(api: BaseApi) {
|
|||
"document-metadata": metadata,
|
||||
documentMetadata: metadata,
|
||||
"total-size": totalSize,
|
||||
...(chunkSize !== undefined ? { "chunk-size": chunkSize } : {}),
|
||||
};
|
||||
if (chunkSize !== undefined) {
|
||||
request["chunk-size"] = chunkSize;
|
||||
}
|
||||
|
||||
return this.api
|
||||
.makeRequest<BeginUploadRequest, BeginUploadResponse>(
|
||||
|
|
@ -1124,10 +1102,8 @@ export function makeLibrarianApi(api: BaseApi) {
|
|||
operation: "stream-document",
|
||||
"document-id": documentId,
|
||||
user: this.api.user,
|
||||
...(chunkSize !== undefined ? { "chunk-size": chunkSize } : {}),
|
||||
};
|
||||
if (chunkSize !== undefined) {
|
||||
request["chunk-size"] = chunkSize;
|
||||
}
|
||||
|
||||
this.api.makeRequestMulti<StreamDocumentRequest, StreamDocumentResponse>(
|
||||
"librarian",
|
||||
|
|
@ -1369,13 +1345,9 @@ export function makeFlowsApi(api: BaseApi) {
|
|||
"flow-id": id,
|
||||
"blueprint-name": blueprint_name,
|
||||
description: description,
|
||||
...(parameters !== undefined && Object.keys(parameters).length > 0 ? { parameters } : {}),
|
||||
};
|
||||
|
||||
// Only include parameters if provided and not empty
|
||||
if (parameters !== undefined && Object.keys(parameters).length > 0) {
|
||||
request.parameters = parameters;
|
||||
}
|
||||
|
||||
return this.api
|
||||
.makeRequest<FlowRequest, FlowResponse>("flow", request, 30000)
|
||||
.then((response) => {
|
||||
|
|
@ -1447,19 +1419,11 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
query: text,
|
||||
user: this.api.user,
|
||||
collection: withDefault(collection, "default"),
|
||||
...(options?.entityLimit !== undefined ? { "entity-limit": options.entityLimit } : {}),
|
||||
...(options?.tripleLimit !== undefined ? { "triple-limit": options.tripleLimit } : {}),
|
||||
...(options?.maxSubgraphSize !== undefined ? { "max-subgraph-size": options.maxSubgraphSize } : {}),
|
||||
...(options?.pathLength !== undefined ? { "max-path-length": options.pathLength } : {}),
|
||||
};
|
||||
if (options?.entityLimit !== undefined) {
|
||||
request["entity-limit"] = options.entityLimit;
|
||||
}
|
||||
if (options?.tripleLimit !== undefined) {
|
||||
request["triple-limit"] = options.tripleLimit;
|
||||
}
|
||||
if (options?.maxSubgraphSize !== undefined) {
|
||||
request["max-subgraph-size"] = options.maxSubgraphSize;
|
||||
}
|
||||
if (options?.pathLength !== undefined) {
|
||||
request["max-path-length"] = options.pathLength;
|
||||
}
|
||||
|
||||
return this.api
|
||||
.makeRequest<GraphRagRequest, GraphRagResponse>(
|
||||
|
|
@ -1539,10 +1503,8 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
const event: ExplainEvent = {
|
||||
explainId: explainId ?? "",
|
||||
explainGraph: stringProperty(resp, "explain_graph") ?? "",
|
||||
...(explainTriples !== undefined ? { explainTriples } : {}),
|
||||
};
|
||||
if (explainTriples !== undefined) {
|
||||
event.explainTriples = explainTriples;
|
||||
}
|
||||
onExplain?.(event);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1635,10 +1597,8 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
const event: ExplainEvent = {
|
||||
explainId: explainId ?? "",
|
||||
explainGraph: stringProperty(resp, "explain_graph") ?? "",
|
||||
...(explainTriples !== undefined ? { explainTriples } : {}),
|
||||
};
|
||||
if (explainTriples !== undefined) {
|
||||
event.explainTriples = explainTriples;
|
||||
}
|
||||
onExplain?.(event);
|
||||
// If this message also carries answer text, fall through to chunk handling.
|
||||
// If it's a standalone explain event (no answer text), stop here.
|
||||
|
|
@ -1668,19 +1628,11 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
user: this.api.user,
|
||||
collection: withDefault(collection, "default"),
|
||||
streaming: true,
|
||||
...(options?.entityLimit !== undefined ? { "entity-limit": options.entityLimit } : {}),
|
||||
...(options?.tripleLimit !== undefined ? { "triple-limit": options.tripleLimit } : {}),
|
||||
...(options?.maxSubgraphSize !== undefined ? { "max-subgraph-size": options.maxSubgraphSize } : {}),
|
||||
...(options?.pathLength !== undefined ? { "max-path-length": options.pathLength } : {}),
|
||||
};
|
||||
if (options?.entityLimit !== undefined) {
|
||||
request["entity-limit"] = options.entityLimit;
|
||||
}
|
||||
if (options?.tripleLimit !== undefined) {
|
||||
request["triple-limit"] = options.tripleLimit;
|
||||
}
|
||||
if (options?.maxSubgraphSize !== undefined) {
|
||||
request["max-subgraph-size"] = options.maxSubgraphSize;
|
||||
}
|
||||
if (options?.pathLength !== undefined) {
|
||||
request["max-path-length"] = options.pathLength;
|
||||
}
|
||||
|
||||
void runLegacyStreamingRequest(
|
||||
"graph-rag-stream",
|
||||
|
|
@ -1765,10 +1717,8 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
user: this.api.user,
|
||||
collection: withDefault(collection, "default"),
|
||||
streaming: true,
|
||||
...(docLimit !== undefined ? { "doc-limit": docLimit } : {}),
|
||||
};
|
||||
if (docLimit !== undefined) {
|
||||
request["doc-limit"] = docLimit;
|
||||
}
|
||||
|
||||
void runLegacyStreamingRequest(
|
||||
"document-rag-stream",
|
||||
|
|
@ -1968,19 +1918,11 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
limit: limit ?? 20,
|
||||
user: this.api.user,
|
||||
collection: withDefault(collection, "default"),
|
||||
...(s !== undefined ? { s } : {}),
|
||||
...(p !== undefined ? { p } : {}),
|
||||
...(o !== undefined ? { o } : {}),
|
||||
...(graph !== undefined ? { g: graph } : {}),
|
||||
};
|
||||
if (s !== undefined) {
|
||||
request.s = s;
|
||||
}
|
||||
if (p !== undefined) {
|
||||
request.p = p;
|
||||
}
|
||||
if (o !== undefined) {
|
||||
request.o = o;
|
||||
}
|
||||
if (graph !== undefined) {
|
||||
request.g = graph;
|
||||
}
|
||||
|
||||
return this.api
|
||||
.makeRequest<TriplesQueryRequest, TriplesQueryResponse>(
|
||||
|
|
@ -2005,13 +1947,9 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
) {
|
||||
const request: LoadDocumentRequest = {
|
||||
data: document,
|
||||
...(id !== undefined ? { id } : {}),
|
||||
...(metadata !== undefined ? { metadata } : {}),
|
||||
};
|
||||
if (id !== undefined) {
|
||||
request.id = id;
|
||||
}
|
||||
if (metadata !== undefined) {
|
||||
request.metadata = metadata;
|
||||
}
|
||||
|
||||
return this.api.makeRequest<LoadDocumentRequest, LoadDocumentResponse>(
|
||||
"document-load",
|
||||
|
|
@ -2035,16 +1973,10 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
) {
|
||||
const request: LoadTextRequest = {
|
||||
text,
|
||||
...(id !== undefined ? { id } : {}),
|
||||
...(metadata !== undefined ? { metadata } : {}),
|
||||
...(charset !== undefined ? { charset } : {}),
|
||||
};
|
||||
if (id !== undefined) {
|
||||
request.id = id;
|
||||
}
|
||||
if (metadata !== undefined) {
|
||||
request.metadata = metadata;
|
||||
}
|
||||
if (charset !== undefined) {
|
||||
request.charset = charset;
|
||||
}
|
||||
|
||||
return this.api.makeRequest<LoadTextRequest, LoadTextResponse>(
|
||||
"text-load",
|
||||
|
|
@ -2070,13 +2002,9 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
query,
|
||||
user: this.api.user,
|
||||
collection: withDefault(collection, "default"),
|
||||
...(variables !== undefined ? { variables } : {}),
|
||||
...(operationName !== undefined ? { operation_name: operationName } : {}),
|
||||
};
|
||||
if (variables !== undefined) {
|
||||
request.variables = variables;
|
||||
}
|
||||
if (operationName !== undefined) {
|
||||
request.operation_name = operationName;
|
||||
}
|
||||
|
||||
return this.api
|
||||
.makeRequest<RowsQueryRequest, RowsQueryResponse>(
|
||||
|
|
@ -2167,12 +2095,9 @@ export function makeFlowApi(api: BaseApi, flowId: string) {
|
|||
user: this.api.user,
|
||||
collection: withDefault(collection, "default"),
|
||||
limit: limit ?? 10,
|
||||
...(indexName !== undefined ? { index_name: indexName } : {}),
|
||||
};
|
||||
|
||||
if (indexName !== undefined) {
|
||||
request.index_name = indexName;
|
||||
}
|
||||
|
||||
return this.api
|
||||
.makeRequest<RowEmbeddingsQueryRequest, RowEmbeddingsQueryResponse>(
|
||||
"row-embeddings",
|
||||
|
|
@ -2664,16 +2589,3 @@ export function makeCollectionManagementApi(api: BaseApi) {
|
|||
|
||||
export type CollectionManagementApi = ReturnType<typeof makeCollectionManagementApi>;
|
||||
export const CollectionManagementApi = makeCollectionManagementApi;
|
||||
|
||||
/**
|
||||
* Factory function to create a new TrustGraph WebSocket connection
|
||||
* This is the main entry point for using the TrustGraph API
|
||||
* @param user - User identifier for API requests
|
||||
* @param token - Optional authentication token for secure connections
|
||||
* @param socketUrl - Optional WebSocket URL (defaults to /api/v1/rpc for browser, provide full URL for Node.js)
|
||||
*/
|
||||
export const createTrustGraphSocket = (
|
||||
user: string,
|
||||
token?: string,
|
||||
socketUrl?: string,
|
||||
): BaseApi => makeBaseApi(user, token, socketUrl);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue