graphlit-client 1.0.20250531005 → 1.0.20250610001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +441 -53
- package/dist/client.d.ts +126 -1
- package/dist/client.js +1616 -1569
- package/dist/generated/graphql-documents.d.ts +1 -0
- package/dist/generated/graphql-documents.js +372 -310
- package/dist/generated/graphql-types.d.ts +207 -23
- package/dist/generated/graphql-types.js +299 -246
- package/dist/model-mapping.d.ts +18 -0
- package/dist/model-mapping.js +95 -0
- package/dist/stream-helpers.d.ts +106 -0
- package/dist/stream-helpers.js +237 -0
- package/dist/streaming/chunk-buffer.d.ts +25 -0
- package/dist/streaming/chunk-buffer.js +170 -0
- package/dist/streaming/llm-formatters.d.ts +64 -0
- package/dist/streaming/llm-formatters.js +187 -0
- package/dist/streaming/providers.d.ts +18 -0
- package/dist/streaming/providers.js +353 -0
- package/dist/streaming/ui-event-adapter.d.ts +52 -0
- package/dist/streaming/ui-event-adapter.js +288 -0
- package/dist/types/agent.d.ts +39 -0
- package/dist/types/agent.js +1 -0
- package/dist/types/streaming.d.ts +58 -0
- package/dist/types/streaming.js +7 -0
- package/dist/types/ui-events.d.ts +38 -0
- package/dist/types/ui-events.js +1 -0
- package/package.json +32 -5
package/dist/client.d.ts
CHANGED
@@ -1,5 +1,43 @@
|
|
1
1
|
import { ApolloClient, NormalizedCacheObject } from "@apollo/client/core";
|
2
2
|
import * as Types from "./generated/graphql-types.js";
|
3
|
+
import { AgentOptions, AgentResult, StreamAgentOptions, ToolHandler } from "./types/agent.js";
|
4
|
+
import { AgentStreamEvent } from "./types/ui-events.js";
|
5
|
+
export type StreamEvent = {
|
6
|
+
type: "start";
|
7
|
+
conversationId: string;
|
8
|
+
} | {
|
9
|
+
type: "token";
|
10
|
+
token: string;
|
11
|
+
} | {
|
12
|
+
type: "message";
|
13
|
+
message: string;
|
14
|
+
} | {
|
15
|
+
type: "tool_call_start";
|
16
|
+
toolCall: {
|
17
|
+
id: string;
|
18
|
+
name: string;
|
19
|
+
};
|
20
|
+
} | {
|
21
|
+
type: "tool_call_delta";
|
22
|
+
toolCallId: string;
|
23
|
+
argumentDelta: string;
|
24
|
+
} | {
|
25
|
+
type: "tool_call_complete";
|
26
|
+
toolCall: {
|
27
|
+
id: string;
|
28
|
+
name: string;
|
29
|
+
arguments: string;
|
30
|
+
};
|
31
|
+
} | {
|
32
|
+
type: "complete";
|
33
|
+
messageId?: string;
|
34
|
+
conversationId?: string;
|
35
|
+
} | {
|
36
|
+
type: "error";
|
37
|
+
error: string;
|
38
|
+
};
|
39
|
+
export type { AgentOptions, AgentResult, StreamAgentOptions, ToolCallResult, UsageInfo, AgentError, } from "./types/agent.js";
|
40
|
+
export type { AgentStreamEvent } from "./types/ui-events.js";
|
3
41
|
declare class Graphlit {
|
4
42
|
client: ApolloClient<NormalizedCacheObject> | undefined;
|
5
43
|
token: string | undefined;
|
@@ -9,8 +47,26 @@ declare class Graphlit {
|
|
9
47
|
private ownerId;
|
10
48
|
private userId;
|
11
49
|
private jwtSecret;
|
50
|
+
private openaiClient?;
|
51
|
+
private anthropicClient?;
|
52
|
+
private googleClient?;
|
12
53
|
constructor(organizationId?: string, environmentId?: string, jwtSecret?: string, ownerId?: string, userId?: string, apiUri?: string);
|
13
54
|
refreshClient(): void;
|
55
|
+
/**
|
56
|
+
* Set a custom OpenAI client instance for streaming
|
57
|
+
* @param client - OpenAI client instance (e.g., new OpenAI({ apiKey: "..." }))
|
58
|
+
*/
|
59
|
+
setOpenAIClient(client: any): void;
|
60
|
+
/**
|
61
|
+
* Set a custom Anthropic client instance for streaming
|
62
|
+
* @param client - Anthropic client instance (e.g., new Anthropic({ apiKey: "..." }))
|
63
|
+
*/
|
64
|
+
setAnthropicClient(client: any): void;
|
65
|
+
/**
|
66
|
+
* Set a custom Google Generative AI client instance for streaming
|
67
|
+
* @param client - Google GenerativeAI client instance (e.g., new GoogleGenerativeAI(apiKey))
|
68
|
+
*/
|
69
|
+
setGoogleClient(client: any): void;
|
14
70
|
private generateToken;
|
15
71
|
getProject(): Promise<Types.GetProjectQuery>;
|
16
72
|
updateProject(project: Types.ProjectUpdateInput): Promise<Types.UpdateProjectMutation>;
|
@@ -84,7 +140,7 @@ declare class Graphlit {
|
|
84
140
|
reviseContent(prompt: string, content: Types.EntityReferenceInput, id?: string, specification?: Types.EntityReferenceInput, correlationId?: string): Promise<Types.ReviseContentMutation>;
|
85
141
|
prompt(prompt?: string, mimeType?: string, data?: string, specification?: Types.EntityReferenceInput, messages?: Types.ConversationMessageInput[], correlationId?: string): Promise<Types.PromptMutation>;
|
86
142
|
retrieveSources(prompt: string, filter?: Types.ContentFilter, augmentedFilter?: Types.ContentFilter, retrievalStrategy?: Types.RetrievalStrategyInput, rerankingStrategy?: Types.RerankingStrategyInput, correlationId?: string): Promise<Types.RetrieveSourcesMutation>;
|
87
|
-
formatConversation(prompt: string, id?: string, specification?: Types.EntityReferenceInput, includeDetails?: boolean, correlationId?: string): Promise<Types.FormatConversationMutation>;
|
143
|
+
formatConversation(prompt: string, id?: string, specification?: Types.EntityReferenceInput, tools?: Types.ToolDefinitionInput[], includeDetails?: boolean, correlationId?: string): Promise<Types.FormatConversationMutation>;
|
88
144
|
completeConversation(completion: string, id: string, correlationId?: string): Promise<Types.CompleteConversationMutation>;
|
89
145
|
askGraphlit(prompt: string, type?: Types.SdkTypes, id?: string, specification?: Types.EntityReferenceInput, correlationId?: string): Promise<Types.AskGraphlitMutation>;
|
90
146
|
promptConversation(prompt: string, id?: string, specification?: Types.EntityReferenceInput, mimeType?: string, data?: string, tools?: Types.ToolDefinitionInput[], requireTool?: boolean, includeDetails?: boolean, correlationId?: string): Promise<Types.PromptConversationMutation>;
|
@@ -287,9 +343,78 @@ declare class Graphlit {
|
|
287
343
|
createObservation(observation: Types.ObservationInput): Promise<Types.CreateObservationMutation>;
|
288
344
|
updateObservation(observation: Types.ObservationUpdateInput): Promise<Types.UpdateObservationMutation>;
|
289
345
|
deleteObservation(id: string): Promise<Types.DeleteObservationMutation>;
|
346
|
+
/**
|
347
|
+
* Creates an event handler that supports UI streaming mode
|
348
|
+
* @internal
|
349
|
+
*/
|
350
|
+
/**
|
351
|
+
* Check if streaming is supported with the current configuration
|
352
|
+
* @param specification - Optional specification to check compatibility
|
353
|
+
* @returns true if streaming is available, false otherwise
|
354
|
+
*/
|
355
|
+
supportsStreaming(specification?: Types.Specification | Types.EntityReferenceInput): boolean;
|
356
|
+
/**
|
357
|
+
* Execute an agent with non-streaming response
|
358
|
+
* @param prompt - The user prompt
|
359
|
+
* @param conversationId - Optional conversation ID to continue
|
360
|
+
* @param specification - Optional specification for the LLM
|
361
|
+
* @param tools - Optional tool definitions
|
362
|
+
* @param toolHandlers - Optional tool handler functions
|
363
|
+
* @param options - Agent options
|
364
|
+
* @returns Complete agent result with message and tool calls
|
365
|
+
*/
|
366
|
+
promptAgent(prompt: string, conversationId?: string, specification?: Types.EntityReferenceInput, tools?: Types.ToolDefinitionInput[], toolHandlers?: Record<string, ToolHandler>, options?: AgentOptions, mimeType?: string, data?: string, // base64 encoded
|
367
|
+
correlationId?: string): Promise<AgentResult>;
|
368
|
+
/**
|
369
|
+
* Execute an agent with streaming response
|
370
|
+
* @param prompt - The user prompt
|
371
|
+
* @param onEvent - Event handler for streaming events
|
372
|
+
* @param conversationId - Optional conversation ID to continue
|
373
|
+
* @param specification - Optional specification for the LLM
|
374
|
+
* @param tools - Optional tool definitions
|
375
|
+
* @param toolHandlers - Optional tool handler functions
|
376
|
+
* @param options - Stream agent options
|
377
|
+
* @throws Error if streaming is not supported
|
378
|
+
*/
|
379
|
+
streamAgent(prompt: string, onEvent: (event: StreamEvent | AgentStreamEvent) => void, conversationId?: string, specification?: Types.EntityReferenceInput, tools?: Types.ToolDefinitionInput[], toolHandlers?: Record<string, ToolHandler>, options?: StreamAgentOptions, mimeType?: string, data?: string, // base64 encoded
|
380
|
+
correlationId?: string): Promise<void>;
|
381
|
+
/**
|
382
|
+
* Execute the streaming agent workflow with tool calling loop
|
383
|
+
*/
|
384
|
+
private executeStreamingAgent;
|
385
|
+
/**
|
386
|
+
* Build message array for LLM from conversation history
|
387
|
+
*/
|
388
|
+
private buildMessageArray;
|
389
|
+
/**
|
390
|
+
* Execute tools during streaming with proper event emission
|
391
|
+
*/
|
392
|
+
private executeToolsInStream;
|
393
|
+
/**
|
394
|
+
* Format tool results for API
|
395
|
+
*/
|
396
|
+
private formatToolResults;
|
397
|
+
/**
|
398
|
+
* Fallback to non-streaming when streaming is not available
|
399
|
+
*/
|
400
|
+
private fallbackToNonStreaming;
|
401
|
+
/**
|
402
|
+
* Stream with OpenAI client
|
403
|
+
*/
|
404
|
+
private streamWithOpenAI;
|
405
|
+
/**
|
406
|
+
* Stream with Anthropic client
|
407
|
+
*/
|
408
|
+
private streamWithAnthropic;
|
409
|
+
/**
|
410
|
+
* Stream with Google client
|
411
|
+
*/
|
412
|
+
private streamWithGoogle;
|
413
|
+
private executeToolsForPromptAgent;
|
290
414
|
private prettyPrintGraphQLError;
|
291
415
|
private mutateAndCheckError;
|
292
416
|
private queryAndCheckError;
|
293
417
|
}
|
294
418
|
export { Graphlit };
|
295
419
|
export * as Types from "./generated/graphql-types.js";
|
420
|
+
export { StreamEventAggregator, AggregatedEvent, formatSSEEvent, createSSEStream, wrapToolHandlers, enhanceToolCalls, ConversationMetrics, ToolResultEmitter, ServerMapping, } from "./stream-helpers.js";
|