@opperai/agents 0.5.0 → 0.7.0
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/dist/index.cjs +58 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +288 -235
- package/dist/index.d.ts +288 -235
- package/dist/index.js +58 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -514,7 +514,24 @@ declare const ExecutionCycleSchema: z.ZodObject<{
|
|
|
514
514
|
results?: unknown[] | undefined;
|
|
515
515
|
timestamp?: number | undefined;
|
|
516
516
|
}>;
|
|
517
|
-
|
|
517
|
+
/** Structured thought recorded during an execution cycle */
|
|
518
|
+
interface ExecutionThought {
|
|
519
|
+
reasoning: string;
|
|
520
|
+
memoryReads?: string[];
|
|
521
|
+
memoryUpdates?: Record<string, unknown>;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* A single iteration of the agent's think-act loop.
|
|
525
|
+
* The Zod schema (`ExecutionCycleSchema`) handles runtime parsing;
|
|
526
|
+
* this interface provides precise TypeScript types for `thought`.
|
|
527
|
+
*/
|
|
528
|
+
interface ExecutionCycle {
|
|
529
|
+
iteration: number;
|
|
530
|
+
thought?: ExecutionThought | null;
|
|
531
|
+
toolCalls: ToolCallRecord[];
|
|
532
|
+
results: unknown[];
|
|
533
|
+
timestamp: number;
|
|
534
|
+
}
|
|
518
535
|
interface AgentContextOptions {
|
|
519
536
|
agentName: string;
|
|
520
537
|
sessionId?: string;
|
|
@@ -544,6 +561,15 @@ interface IterationSummary {
|
|
|
544
561
|
}>;
|
|
545
562
|
results: unknown[];
|
|
546
563
|
}
|
|
564
|
+
interface PendingSpanUpdate {
|
|
565
|
+
spanId: string;
|
|
566
|
+
output?: unknown;
|
|
567
|
+
error?: string;
|
|
568
|
+
startTime?: Date;
|
|
569
|
+
endTime?: Date;
|
|
570
|
+
meta?: Record<string, unknown>;
|
|
571
|
+
name?: string;
|
|
572
|
+
}
|
|
547
573
|
declare class AgentContext {
|
|
548
574
|
readonly agentName: string;
|
|
549
575
|
readonly sessionId: string;
|
|
@@ -556,6 +582,7 @@ declare class AgentContext {
|
|
|
556
582
|
metadata: Record<string, unknown>;
|
|
557
583
|
readonly startedAt: number;
|
|
558
584
|
updatedAt: number;
|
|
585
|
+
pendingSpanUpdates: PendingSpanUpdate[];
|
|
559
586
|
constructor(options: AgentContextOptions);
|
|
560
587
|
updateUsage(delta: Usage): void;
|
|
561
588
|
/**
|
|
@@ -655,6 +682,223 @@ declare function getDefaultLogger(): AgentLogger;
|
|
|
655
682
|
*/
|
|
656
683
|
declare function setDefaultLogger(logger: AgentLogger): void;
|
|
657
684
|
|
|
685
|
+
/**
|
|
686
|
+
* Streaming chunk payload from Opper SSE responses.
|
|
687
|
+
*/
|
|
688
|
+
interface OpperStreamChunk {
|
|
689
|
+
delta?: string | number | boolean | null | undefined;
|
|
690
|
+
jsonPath?: string | null | undefined;
|
|
691
|
+
spanId?: string | null | undefined;
|
|
692
|
+
chunkType?: string | null | undefined;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Server-sent event emitted during streaming calls.
|
|
696
|
+
*/
|
|
697
|
+
interface OpperStreamEvent {
|
|
698
|
+
id?: string;
|
|
699
|
+
event?: string;
|
|
700
|
+
retry?: number;
|
|
701
|
+
data?: OpperStreamChunk;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Structured response returned by Opper stream endpoints.
|
|
705
|
+
*/
|
|
706
|
+
interface OpperStreamResponse {
|
|
707
|
+
headers: Record<string, string[]>;
|
|
708
|
+
result: AsyncIterable<OpperStreamEvent>;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Opper call response
|
|
712
|
+
*/
|
|
713
|
+
interface OpperCallResponse<TOutput = unknown> {
|
|
714
|
+
/**
|
|
715
|
+
* Parsed JSON output (if outputSchema provided)
|
|
716
|
+
*/
|
|
717
|
+
jsonPayload?: TOutput;
|
|
718
|
+
/**
|
|
719
|
+
* Text message response
|
|
720
|
+
*/
|
|
721
|
+
message?: string | null | undefined;
|
|
722
|
+
/**
|
|
723
|
+
* Span ID for this call
|
|
724
|
+
*/
|
|
725
|
+
spanId: string;
|
|
726
|
+
/**
|
|
727
|
+
* Token usage information
|
|
728
|
+
*/
|
|
729
|
+
usage: {
|
|
730
|
+
inputTokens: number;
|
|
731
|
+
outputTokens: number;
|
|
732
|
+
totalTokens: number;
|
|
733
|
+
cost: {
|
|
734
|
+
generation: number;
|
|
735
|
+
platform: number;
|
|
736
|
+
total: number;
|
|
737
|
+
};
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Options for Opper call
|
|
742
|
+
*/
|
|
743
|
+
interface OpperCallOptions<TInput = unknown, TOutput = unknown> {
|
|
744
|
+
/**
|
|
745
|
+
* Unique name for this call/task
|
|
746
|
+
*/
|
|
747
|
+
name: string;
|
|
748
|
+
/**
|
|
749
|
+
* Natural language instructions
|
|
750
|
+
*/
|
|
751
|
+
instructions: string;
|
|
752
|
+
/**
|
|
753
|
+
* Input data for the call
|
|
754
|
+
*/
|
|
755
|
+
input: TInput;
|
|
756
|
+
/**
|
|
757
|
+
* Input schema (Zod or JSON Schema)
|
|
758
|
+
*/
|
|
759
|
+
inputSchema?: z.ZodType<TInput> | Record<string, unknown>;
|
|
760
|
+
/**
|
|
761
|
+
* Output schema (Zod or JSON Schema)
|
|
762
|
+
*/
|
|
763
|
+
outputSchema?: z.ZodType<TOutput> | Record<string, unknown>;
|
|
764
|
+
/**
|
|
765
|
+
* Model to use. Accepts a single model identifier or an ordered list for fallback.
|
|
766
|
+
* Example: "anthropic/claude-3.7-sonnet" or ["openai/gpt-4o", "anthropic/claude-3.7-sonnet"].
|
|
767
|
+
*/
|
|
768
|
+
model?: string | readonly string[];
|
|
769
|
+
/**
|
|
770
|
+
* Parent span ID for tracing
|
|
771
|
+
*/
|
|
772
|
+
parentSpanId?: string;
|
|
773
|
+
/**
|
|
774
|
+
* Abort signal used to cancel the underlying HTTP request.
|
|
775
|
+
*/
|
|
776
|
+
signal?: AbortSignal;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Span information
|
|
780
|
+
*/
|
|
781
|
+
interface OpperSpan {
|
|
782
|
+
id: string;
|
|
783
|
+
name: string;
|
|
784
|
+
input?: unknown;
|
|
785
|
+
output?: unknown;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Options for creating a span
|
|
789
|
+
*/
|
|
790
|
+
interface CreateSpanOptions {
|
|
791
|
+
name: string;
|
|
792
|
+
input?: unknown;
|
|
793
|
+
parentSpanId?: string;
|
|
794
|
+
type?: string;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Retry configuration
|
|
798
|
+
*/
|
|
799
|
+
interface RetryConfig {
|
|
800
|
+
/**
|
|
801
|
+
* Maximum number of retry attempts
|
|
802
|
+
*/
|
|
803
|
+
maxRetries: number;
|
|
804
|
+
/**
|
|
805
|
+
* Initial delay in milliseconds
|
|
806
|
+
*/
|
|
807
|
+
initialDelayMs: number;
|
|
808
|
+
/**
|
|
809
|
+
* Backoff multiplier
|
|
810
|
+
*/
|
|
811
|
+
backoffMultiplier: number;
|
|
812
|
+
/**
|
|
813
|
+
* Maximum delay in milliseconds
|
|
814
|
+
*/
|
|
815
|
+
maxDelayMs: number;
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Default retry configuration
|
|
819
|
+
*/
|
|
820
|
+
declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
821
|
+
/**
|
|
822
|
+
* Opper client wrapper with retry logic and usage tracking
|
|
823
|
+
*/
|
|
824
|
+
declare class OpperClient {
|
|
825
|
+
private readonly client;
|
|
826
|
+
private readonly logger;
|
|
827
|
+
private readonly retryConfig;
|
|
828
|
+
constructor(apiKey?: string, options?: {
|
|
829
|
+
logger?: AgentLogger;
|
|
830
|
+
retryConfig?: Partial<RetryConfig>;
|
|
831
|
+
/**
|
|
832
|
+
* Override the default Opper API server URL.
|
|
833
|
+
* Useful for local development or self-hosted deployments.
|
|
834
|
+
* Example: "http://127.0.0.1:8000/v2"
|
|
835
|
+
*/
|
|
836
|
+
baseUrl?: string;
|
|
837
|
+
});
|
|
838
|
+
/**
|
|
839
|
+
* Make a call to Opper with retry logic
|
|
840
|
+
*/
|
|
841
|
+
call<TInput = unknown, TOutput = unknown>(options: OpperCallOptions<TInput, TOutput>): Promise<OpperCallResponse<TOutput>>;
|
|
842
|
+
/**
|
|
843
|
+
* Stream a call to Opper with retry logic
|
|
844
|
+
*/
|
|
845
|
+
stream<TInput = unknown, TOutput = unknown>(options: OpperCallOptions<TInput, TOutput>): Promise<OpperStreamResponse>;
|
|
846
|
+
/**
|
|
847
|
+
* Create a span for tracing
|
|
848
|
+
*/
|
|
849
|
+
createSpan(options: CreateSpanOptions): Promise<OpperSpan>;
|
|
850
|
+
/**
|
|
851
|
+
* Update a span with output or error
|
|
852
|
+
*/
|
|
853
|
+
updateSpan(spanId: string, output: unknown, options?: {
|
|
854
|
+
error?: string;
|
|
855
|
+
startTime?: Date;
|
|
856
|
+
endTime?: Date;
|
|
857
|
+
meta?: Record<string, unknown>;
|
|
858
|
+
name?: string;
|
|
859
|
+
}): Promise<void>;
|
|
860
|
+
/**
|
|
861
|
+
* Get the underlying Opper client
|
|
862
|
+
*/
|
|
863
|
+
getClient(): Opper;
|
|
864
|
+
/**
|
|
865
|
+
* Execute a function with retry logic and exponential backoff
|
|
866
|
+
*/
|
|
867
|
+
private withRetry;
|
|
868
|
+
/**
|
|
869
|
+
* Check if an error is retryable
|
|
870
|
+
*/
|
|
871
|
+
private isRetryableError;
|
|
872
|
+
/**
|
|
873
|
+
* Convert Zod schema to JSON Schema
|
|
874
|
+
*/
|
|
875
|
+
private toJsonSchema;
|
|
876
|
+
/**
|
|
877
|
+
* Sleep for specified milliseconds
|
|
878
|
+
*/
|
|
879
|
+
private sleep;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Create an Opper client with optional configuration
|
|
883
|
+
*/
|
|
884
|
+
declare function createOpperClient(apiKey?: string, options?: {
|
|
885
|
+
logger?: AgentLogger;
|
|
886
|
+
retryConfig?: Partial<RetryConfig>;
|
|
887
|
+
/**
|
|
888
|
+
* Override the default Opper API server URL.
|
|
889
|
+
* Useful for local development or self-hosted deployments.
|
|
890
|
+
* Example: "http://127.0.0.1:8000/v2"
|
|
891
|
+
*/
|
|
892
|
+
baseUrl?: string;
|
|
893
|
+
}): OpperClient;
|
|
894
|
+
|
|
895
|
+
/** The two LLM call phases in the agent loop */
|
|
896
|
+
type LlmCallType = "think" | "final_result";
|
|
897
|
+
/** Thought summary emitted by the ThinkEnd hook */
|
|
898
|
+
interface AgentThought {
|
|
899
|
+
reasoning: string;
|
|
900
|
+
userMessage: string;
|
|
901
|
+
}
|
|
658
902
|
declare const HookEvents: {
|
|
659
903
|
readonly AgentStart: "agent:start";
|
|
660
904
|
readonly AgentEnd: "agent:end";
|
|
@@ -692,17 +936,17 @@ interface HookPayloadMap {
|
|
|
692
936
|
};
|
|
693
937
|
[HookEvents.LlmCall]: {
|
|
694
938
|
context: AgentContext;
|
|
695
|
-
callType:
|
|
939
|
+
callType: LlmCallType;
|
|
696
940
|
};
|
|
697
941
|
[HookEvents.LlmResponse]: {
|
|
698
942
|
context: AgentContext;
|
|
699
|
-
callType:
|
|
700
|
-
response:
|
|
943
|
+
callType: LlmCallType;
|
|
944
|
+
response: OpperCallResponse | OpperStreamResponse;
|
|
701
945
|
parsed?: unknown;
|
|
702
946
|
};
|
|
703
947
|
[HookEvents.ThinkEnd]: {
|
|
704
948
|
context: AgentContext;
|
|
705
|
-
thought:
|
|
949
|
+
thought: AgentThought;
|
|
706
950
|
};
|
|
707
951
|
[HookEvents.BeforeTool]: {
|
|
708
952
|
context: AgentContext;
|
|
@@ -740,13 +984,13 @@ interface HookPayloadMap {
|
|
|
740
984
|
};
|
|
741
985
|
[HookEvents.StreamStart]: {
|
|
742
986
|
context: AgentContext;
|
|
743
|
-
callType:
|
|
987
|
+
callType: LlmCallType;
|
|
744
988
|
};
|
|
745
989
|
[HookEvents.StreamChunk]: {
|
|
746
990
|
context: AgentContext;
|
|
747
|
-
callType:
|
|
991
|
+
callType: LlmCallType;
|
|
748
992
|
chunkData: {
|
|
749
|
-
delta:
|
|
993
|
+
delta: string | number | boolean | null | undefined;
|
|
750
994
|
jsonPath?: string | null;
|
|
751
995
|
chunkType?: string | null;
|
|
752
996
|
};
|
|
@@ -755,16 +999,33 @@ interface HookPayloadMap {
|
|
|
755
999
|
};
|
|
756
1000
|
[HookEvents.StreamEnd]: {
|
|
757
1001
|
context: AgentContext;
|
|
758
|
-
callType:
|
|
1002
|
+
callType: LlmCallType;
|
|
759
1003
|
fieldBuffers: Record<string, string>;
|
|
760
1004
|
};
|
|
761
1005
|
[HookEvents.StreamError]: {
|
|
762
1006
|
context: AgentContext;
|
|
763
|
-
callType:
|
|
1007
|
+
callType: LlmCallType;
|
|
764
1008
|
error: unknown;
|
|
765
1009
|
};
|
|
766
1010
|
}
|
|
767
1011
|
type HookPayload<E extends HookEventName> = HookPayloadMap[E];
|
|
1012
|
+
type AgentStartPayload = HookPayloadMap[typeof HookEvents.AgentStart];
|
|
1013
|
+
type AgentEndPayload = HookPayloadMap[typeof HookEvents.AgentEnd];
|
|
1014
|
+
type LoopStartPayload = HookPayloadMap[typeof HookEvents.LoopStart];
|
|
1015
|
+
type LoopEndPayload = HookPayloadMap[typeof HookEvents.LoopEnd];
|
|
1016
|
+
type LlmCallPayload = HookPayloadMap[typeof HookEvents.LlmCall];
|
|
1017
|
+
type LlmResponsePayload = HookPayloadMap[typeof HookEvents.LlmResponse];
|
|
1018
|
+
type ThinkEndPayload = HookPayloadMap[typeof HookEvents.ThinkEnd];
|
|
1019
|
+
type BeforeToolPayload = HookPayloadMap[typeof HookEvents.BeforeTool];
|
|
1020
|
+
type AfterToolPayload = HookPayloadMap[typeof HookEvents.AfterTool];
|
|
1021
|
+
type ToolErrorPayload = HookPayloadMap[typeof HookEvents.ToolError];
|
|
1022
|
+
type MemoryReadPayload = HookPayloadMap[typeof HookEvents.MemoryRead];
|
|
1023
|
+
type MemoryWritePayload = HookPayloadMap[typeof HookEvents.MemoryWrite];
|
|
1024
|
+
type MemoryErrorPayload = HookPayloadMap[typeof HookEvents.MemoryError];
|
|
1025
|
+
type StreamStartPayload = HookPayloadMap[typeof HookEvents.StreamStart];
|
|
1026
|
+
type StreamChunkPayload = HookPayloadMap[typeof HookEvents.StreamChunk];
|
|
1027
|
+
type StreamEndPayload = HookPayloadMap[typeof HookEvents.StreamEnd];
|
|
1028
|
+
type StreamErrorPayload = HookPayloadMap[typeof HookEvents.StreamError];
|
|
768
1029
|
type HookHandler<E extends HookEventName> = (payload: HookPayload<E>) => void | Promise<void>;
|
|
769
1030
|
interface HookRegistration<E extends HookEventName> {
|
|
770
1031
|
event: E;
|
|
@@ -1415,216 +1676,6 @@ type AgentEventPayload<E extends AgentEventName> = AgentEventPayloadMap[E];
|
|
|
1415
1676
|
*/
|
|
1416
1677
|
type AgentEventListener<E extends AgentEventName> = HookHandler<E>;
|
|
1417
1678
|
|
|
1418
|
-
/**
|
|
1419
|
-
* Streaming chunk payload from Opper SSE responses.
|
|
1420
|
-
*/
|
|
1421
|
-
interface OpperStreamChunk {
|
|
1422
|
-
delta?: string | number | boolean | null | undefined;
|
|
1423
|
-
jsonPath?: string | null | undefined;
|
|
1424
|
-
spanId?: string | null | undefined;
|
|
1425
|
-
chunkType?: string | null | undefined;
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Server-sent event emitted during streaming calls.
|
|
1429
|
-
*/
|
|
1430
|
-
interface OpperStreamEvent {
|
|
1431
|
-
id?: string;
|
|
1432
|
-
event?: string;
|
|
1433
|
-
retry?: number;
|
|
1434
|
-
data?: OpperStreamChunk;
|
|
1435
|
-
}
|
|
1436
|
-
/**
|
|
1437
|
-
* Structured response returned by Opper stream endpoints.
|
|
1438
|
-
*/
|
|
1439
|
-
interface OpperStreamResponse {
|
|
1440
|
-
headers: Record<string, string[]>;
|
|
1441
|
-
result: AsyncIterable<OpperStreamEvent>;
|
|
1442
|
-
}
|
|
1443
|
-
/**
|
|
1444
|
-
* Opper call response
|
|
1445
|
-
*/
|
|
1446
|
-
interface OpperCallResponse<TOutput = unknown> {
|
|
1447
|
-
/**
|
|
1448
|
-
* Parsed JSON output (if outputSchema provided)
|
|
1449
|
-
*/
|
|
1450
|
-
jsonPayload?: TOutput;
|
|
1451
|
-
/**
|
|
1452
|
-
* Text message response
|
|
1453
|
-
*/
|
|
1454
|
-
message?: string | null | undefined;
|
|
1455
|
-
/**
|
|
1456
|
-
* Span ID for this call
|
|
1457
|
-
*/
|
|
1458
|
-
spanId: string;
|
|
1459
|
-
/**
|
|
1460
|
-
* Token usage information
|
|
1461
|
-
*/
|
|
1462
|
-
usage: {
|
|
1463
|
-
inputTokens: number;
|
|
1464
|
-
outputTokens: number;
|
|
1465
|
-
totalTokens: number;
|
|
1466
|
-
cost: {
|
|
1467
|
-
generation: number;
|
|
1468
|
-
platform: number;
|
|
1469
|
-
total: number;
|
|
1470
|
-
};
|
|
1471
|
-
};
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Options for Opper call
|
|
1475
|
-
*/
|
|
1476
|
-
interface OpperCallOptions<TInput = unknown, TOutput = unknown> {
|
|
1477
|
-
/**
|
|
1478
|
-
* Unique name for this call/task
|
|
1479
|
-
*/
|
|
1480
|
-
name: string;
|
|
1481
|
-
/**
|
|
1482
|
-
* Natural language instructions
|
|
1483
|
-
*/
|
|
1484
|
-
instructions: string;
|
|
1485
|
-
/**
|
|
1486
|
-
* Input data for the call
|
|
1487
|
-
*/
|
|
1488
|
-
input: TInput;
|
|
1489
|
-
/**
|
|
1490
|
-
* Input schema (Zod or JSON Schema)
|
|
1491
|
-
*/
|
|
1492
|
-
inputSchema?: z.ZodType<TInput> | Record<string, unknown>;
|
|
1493
|
-
/**
|
|
1494
|
-
* Output schema (Zod or JSON Schema)
|
|
1495
|
-
*/
|
|
1496
|
-
outputSchema?: z.ZodType<TOutput> | Record<string, unknown>;
|
|
1497
|
-
/**
|
|
1498
|
-
* Model to use. Accepts a single model identifier or an ordered list for fallback.
|
|
1499
|
-
* Example: "anthropic/claude-3.7-sonnet" or ["openai/gpt-4o", "anthropic/claude-3.7-sonnet"].
|
|
1500
|
-
*/
|
|
1501
|
-
model?: string | readonly string[];
|
|
1502
|
-
/**
|
|
1503
|
-
* Parent span ID for tracing
|
|
1504
|
-
*/
|
|
1505
|
-
parentSpanId?: string;
|
|
1506
|
-
/**
|
|
1507
|
-
* Abort signal used to cancel the underlying HTTP request.
|
|
1508
|
-
*/
|
|
1509
|
-
signal?: AbortSignal;
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Span information
|
|
1513
|
-
*/
|
|
1514
|
-
interface OpperSpan {
|
|
1515
|
-
id: string;
|
|
1516
|
-
name: string;
|
|
1517
|
-
input?: unknown;
|
|
1518
|
-
output?: unknown;
|
|
1519
|
-
}
|
|
1520
|
-
/**
|
|
1521
|
-
* Options for creating a span
|
|
1522
|
-
*/
|
|
1523
|
-
interface CreateSpanOptions {
|
|
1524
|
-
name: string;
|
|
1525
|
-
input?: unknown;
|
|
1526
|
-
parentSpanId?: string;
|
|
1527
|
-
type?: string;
|
|
1528
|
-
}
|
|
1529
|
-
/**
|
|
1530
|
-
* Retry configuration
|
|
1531
|
-
*/
|
|
1532
|
-
interface RetryConfig {
|
|
1533
|
-
/**
|
|
1534
|
-
* Maximum number of retry attempts
|
|
1535
|
-
*/
|
|
1536
|
-
maxRetries: number;
|
|
1537
|
-
/**
|
|
1538
|
-
* Initial delay in milliseconds
|
|
1539
|
-
*/
|
|
1540
|
-
initialDelayMs: number;
|
|
1541
|
-
/**
|
|
1542
|
-
* Backoff multiplier
|
|
1543
|
-
*/
|
|
1544
|
-
backoffMultiplier: number;
|
|
1545
|
-
/**
|
|
1546
|
-
* Maximum delay in milliseconds
|
|
1547
|
-
*/
|
|
1548
|
-
maxDelayMs: number;
|
|
1549
|
-
}
|
|
1550
|
-
/**
|
|
1551
|
-
* Default retry configuration
|
|
1552
|
-
*/
|
|
1553
|
-
declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
1554
|
-
/**
|
|
1555
|
-
* Opper client wrapper with retry logic and usage tracking
|
|
1556
|
-
*/
|
|
1557
|
-
declare class OpperClient {
|
|
1558
|
-
private readonly client;
|
|
1559
|
-
private readonly logger;
|
|
1560
|
-
private readonly retryConfig;
|
|
1561
|
-
constructor(apiKey?: string, options?: {
|
|
1562
|
-
logger?: AgentLogger;
|
|
1563
|
-
retryConfig?: Partial<RetryConfig>;
|
|
1564
|
-
/**
|
|
1565
|
-
* Override the default Opper API server URL.
|
|
1566
|
-
* Useful for local development or self-hosted deployments.
|
|
1567
|
-
* Example: "http://127.0.0.1:8000/v2"
|
|
1568
|
-
*/
|
|
1569
|
-
baseUrl?: string;
|
|
1570
|
-
});
|
|
1571
|
-
/**
|
|
1572
|
-
* Make a call to Opper with retry logic
|
|
1573
|
-
*/
|
|
1574
|
-
call<TInput = unknown, TOutput = unknown>(options: OpperCallOptions<TInput, TOutput>): Promise<OpperCallResponse<TOutput>>;
|
|
1575
|
-
/**
|
|
1576
|
-
* Stream a call to Opper with retry logic
|
|
1577
|
-
*/
|
|
1578
|
-
stream<TInput = unknown, TOutput = unknown>(options: OpperCallOptions<TInput, TOutput>): Promise<OpperStreamResponse>;
|
|
1579
|
-
/**
|
|
1580
|
-
* Create a span for tracing
|
|
1581
|
-
*/
|
|
1582
|
-
createSpan(options: CreateSpanOptions): Promise<OpperSpan>;
|
|
1583
|
-
/**
|
|
1584
|
-
* Update a span with output or error
|
|
1585
|
-
*/
|
|
1586
|
-
updateSpan(spanId: string, output: unknown, options?: {
|
|
1587
|
-
error?: string;
|
|
1588
|
-
startTime?: Date;
|
|
1589
|
-
endTime?: Date;
|
|
1590
|
-
meta?: Record<string, unknown>;
|
|
1591
|
-
name?: string;
|
|
1592
|
-
}): Promise<void>;
|
|
1593
|
-
/**
|
|
1594
|
-
* Get the underlying Opper client
|
|
1595
|
-
*/
|
|
1596
|
-
getClient(): Opper;
|
|
1597
|
-
/**
|
|
1598
|
-
* Execute a function with retry logic and exponential backoff
|
|
1599
|
-
*/
|
|
1600
|
-
private withRetry;
|
|
1601
|
-
/**
|
|
1602
|
-
* Check if an error is retryable
|
|
1603
|
-
*/
|
|
1604
|
-
private isRetryableError;
|
|
1605
|
-
/**
|
|
1606
|
-
* Convert Zod schema to JSON Schema
|
|
1607
|
-
*/
|
|
1608
|
-
private toJsonSchema;
|
|
1609
|
-
/**
|
|
1610
|
-
* Sleep for specified milliseconds
|
|
1611
|
-
*/
|
|
1612
|
-
private sleep;
|
|
1613
|
-
}
|
|
1614
|
-
/**
|
|
1615
|
-
* Create an Opper client with optional configuration
|
|
1616
|
-
*/
|
|
1617
|
-
declare function createOpperClient(apiKey?: string, options?: {
|
|
1618
|
-
logger?: AgentLogger;
|
|
1619
|
-
retryConfig?: Partial<RetryConfig>;
|
|
1620
|
-
/**
|
|
1621
|
-
* Override the default Opper API server URL.
|
|
1622
|
-
* Useful for local development or self-hosted deployments.
|
|
1623
|
-
* Example: "http://127.0.0.1:8000/v2"
|
|
1624
|
-
*/
|
|
1625
|
-
baseUrl?: string;
|
|
1626
|
-
}): OpperClient;
|
|
1627
|
-
|
|
1628
1679
|
/**
|
|
1629
1680
|
* Configuration for the core Agent.
|
|
1630
1681
|
*
|
|
@@ -1745,6 +1796,8 @@ declare class Agent<TInput = unknown, TOutput = unknown> extends BaseAgent<TInpu
|
|
|
1745
1796
|
* Serialize input for passing to LLM or spans
|
|
1746
1797
|
*/
|
|
1747
1798
|
private serializeInput;
|
|
1799
|
+
private queueSpanUpdate;
|
|
1800
|
+
private flushPendingSpanUpdates;
|
|
1748
1801
|
/**
|
|
1749
1802
|
* Main agent loop: think → tool execution → memory handling → repeat until complete
|
|
1750
1803
|
*/
|
|
@@ -1951,13 +2004,13 @@ declare const AgentDecisionSchema: z.ZodObject<{
|
|
|
1951
2004
|
arguments?: unknown;
|
|
1952
2005
|
}[];
|
|
1953
2006
|
reasoning: string;
|
|
1954
|
-
userMessage: string;
|
|
1955
2007
|
memoryReads: string[];
|
|
1956
2008
|
memoryUpdates: Record<string, {
|
|
1957
2009
|
value?: unknown;
|
|
1958
2010
|
metadata?: Record<string, unknown> | undefined;
|
|
1959
2011
|
description?: string | undefined;
|
|
1960
2012
|
}>;
|
|
2013
|
+
userMessage: string;
|
|
1961
2014
|
isComplete: boolean;
|
|
1962
2015
|
finalResult?: unknown;
|
|
1963
2016
|
}, {
|
|
@@ -1967,13 +2020,13 @@ declare const AgentDecisionSchema: z.ZodObject<{
|
|
|
1967
2020
|
toolName: string;
|
|
1968
2021
|
arguments?: unknown;
|
|
1969
2022
|
}[] | undefined;
|
|
1970
|
-
userMessage?: string | undefined;
|
|
1971
2023
|
memoryReads?: string[] | undefined;
|
|
1972
2024
|
memoryUpdates?: Record<string, {
|
|
1973
2025
|
value?: unknown;
|
|
1974
2026
|
metadata?: Record<string, unknown> | undefined;
|
|
1975
2027
|
description?: string | undefined;
|
|
1976
2028
|
}> | undefined;
|
|
2029
|
+
userMessage?: string | undefined;
|
|
1977
2030
|
isComplete?: boolean | undefined;
|
|
1978
2031
|
finalResult?: unknown;
|
|
1979
2032
|
}>;
|
|
@@ -2064,15 +2117,15 @@ declare const MCPConfigVariants: z.ZodDiscriminatedUnion<"transport", [z.ZodObje
|
|
|
2064
2117
|
method: z.ZodDefault<z.ZodEnum<["GET", "POST"]>>;
|
|
2065
2118
|
}, "strip", z.ZodTypeAny, {
|
|
2066
2119
|
metadata: Record<string, unknown>;
|
|
2067
|
-
name: string;
|
|
2068
2120
|
url: string;
|
|
2121
|
+
name: string;
|
|
2069
2122
|
method: "GET" | "POST";
|
|
2070
2123
|
headers: Record<string, string>;
|
|
2071
2124
|
timeout: number;
|
|
2072
2125
|
transport: "http-sse";
|
|
2073
2126
|
}, {
|
|
2074
|
-
name: string;
|
|
2075
2127
|
url: string;
|
|
2128
|
+
name: string;
|
|
2076
2129
|
transport: "http-sse";
|
|
2077
2130
|
metadata?: Record<string, unknown> | undefined;
|
|
2078
2131
|
method?: "GET" | "POST" | undefined;
|
|
@@ -2089,15 +2142,15 @@ declare const MCPConfigVariants: z.ZodDiscriminatedUnion<"transport", [z.ZodObje
|
|
|
2089
2142
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
2090
2143
|
}, "strip", z.ZodTypeAny, {
|
|
2091
2144
|
metadata: Record<string, unknown>;
|
|
2092
|
-
name: string;
|
|
2093
2145
|
url: string;
|
|
2146
|
+
name: string;
|
|
2094
2147
|
headers: Record<string, string>;
|
|
2095
2148
|
timeout: number;
|
|
2096
2149
|
transport: "streamable-http";
|
|
2097
2150
|
sessionId?: string | undefined;
|
|
2098
2151
|
}, {
|
|
2099
|
-
name: string;
|
|
2100
2152
|
url: string;
|
|
2153
|
+
name: string;
|
|
2101
2154
|
transport: "streamable-http";
|
|
2102
2155
|
metadata?: Record<string, unknown> | undefined;
|
|
2103
2156
|
headers?: Record<string, string> | undefined;
|
|
@@ -2148,15 +2201,15 @@ declare const MCPServerConfigSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"trans
|
|
|
2148
2201
|
method: z.ZodDefault<z.ZodEnum<["GET", "POST"]>>;
|
|
2149
2202
|
}, "strip", z.ZodTypeAny, {
|
|
2150
2203
|
metadata: Record<string, unknown>;
|
|
2151
|
-
name: string;
|
|
2152
2204
|
url: string;
|
|
2205
|
+
name: string;
|
|
2153
2206
|
method: "GET" | "POST";
|
|
2154
2207
|
headers: Record<string, string>;
|
|
2155
2208
|
timeout: number;
|
|
2156
2209
|
transport: "http-sse";
|
|
2157
2210
|
}, {
|
|
2158
|
-
name: string;
|
|
2159
2211
|
url: string;
|
|
2212
|
+
name: string;
|
|
2160
2213
|
transport: "http-sse";
|
|
2161
2214
|
metadata?: Record<string, unknown> | undefined;
|
|
2162
2215
|
method?: "GET" | "POST" | undefined;
|
|
@@ -2173,15 +2226,15 @@ declare const MCPServerConfigSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"trans
|
|
|
2173
2226
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
2174
2227
|
}, "strip", z.ZodTypeAny, {
|
|
2175
2228
|
metadata: Record<string, unknown>;
|
|
2176
|
-
name: string;
|
|
2177
2229
|
url: string;
|
|
2230
|
+
name: string;
|
|
2178
2231
|
headers: Record<string, string>;
|
|
2179
2232
|
timeout: number;
|
|
2180
2233
|
transport: "streamable-http";
|
|
2181
2234
|
sessionId?: string | undefined;
|
|
2182
2235
|
}, {
|
|
2183
|
-
name: string;
|
|
2184
2236
|
url: string;
|
|
2237
|
+
name: string;
|
|
2185
2238
|
transport: "streamable-http";
|
|
2186
2239
|
metadata?: Record<string, unknown> | undefined;
|
|
2187
2240
|
headers?: Record<string, string> | undefined;
|
|
@@ -2199,16 +2252,16 @@ declare const MCPServerConfigSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"trans
|
|
|
2199
2252
|
stderr?: "inherit" | "pipe" | "ignore" | undefined;
|
|
2200
2253
|
} | {
|
|
2201
2254
|
metadata: Record<string, unknown>;
|
|
2202
|
-
name: string;
|
|
2203
2255
|
url: string;
|
|
2256
|
+
name: string;
|
|
2204
2257
|
method: "GET" | "POST";
|
|
2205
2258
|
headers: Record<string, string>;
|
|
2206
2259
|
timeout: number;
|
|
2207
2260
|
transport: "http-sse";
|
|
2208
2261
|
} | {
|
|
2209
2262
|
metadata: Record<string, unknown>;
|
|
2210
|
-
name: string;
|
|
2211
2263
|
url: string;
|
|
2264
|
+
name: string;
|
|
2212
2265
|
headers: Record<string, string>;
|
|
2213
2266
|
timeout: number;
|
|
2214
2267
|
transport: "streamable-http";
|
|
@@ -2224,16 +2277,16 @@ declare const MCPServerConfigSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"trans
|
|
|
2224
2277
|
cwd?: string | undefined;
|
|
2225
2278
|
stderr?: "inherit" | "pipe" | "ignore" | undefined;
|
|
2226
2279
|
} | {
|
|
2227
|
-
name: string;
|
|
2228
2280
|
url: string;
|
|
2281
|
+
name: string;
|
|
2229
2282
|
transport: "http-sse";
|
|
2230
2283
|
metadata?: Record<string, unknown> | undefined;
|
|
2231
2284
|
method?: "GET" | "POST" | undefined;
|
|
2232
2285
|
headers?: Record<string, string> | undefined;
|
|
2233
2286
|
timeout?: number | undefined;
|
|
2234
2287
|
} | {
|
|
2235
|
-
name: string;
|
|
2236
2288
|
url: string;
|
|
2289
|
+
name: string;
|
|
2237
2290
|
transport: "streamable-http";
|
|
2238
2291
|
metadata?: Record<string, unknown> | undefined;
|
|
2239
2292
|
headers?: Record<string, string> | undefined;
|
|
@@ -2546,4 +2599,4 @@ declare class ToolRunner {
|
|
|
2546
2599
|
};
|
|
2547
2600
|
}
|
|
2548
2601
|
|
|
2549
|
-
export { Agent, type AgentConfig, AgentContext, type AgentContextOptions, type AgentContextSnapshot, type AgentDecision, AgentDecisionSchema, type AgentEventListener, type AgentEventName, type AgentEventPayload, type AgentEventPayloadMap, AgentEvents, type AgentLogger, BaseAgent, type BaseAgentConfig, type BaseUsage, BaseUsageSchema, ConsoleLogger, type CreateSpanOptions, DEFAULT_MODEL, DEFAULT_RETRY_CONFIG, type ExecutionCycle, ExecutionCycleSchema, type Failure, type HookEventName, HookEvents, type HookHandler, HookManager, type HookPayload, type HookPayloadMap, type HookRegistration, InMemoryStore, type IterationSummary, type JsonSchemaOptions, LogLevel, MCPClient, type MCPClientOptions, type MCPServerConfig, type MCPServerConfigInput, MCPServerConfigSchema, type MCPTool, MCPToolProvider, type MCPToolProviderOptions, MCPconfig, type MaybePromise, type Memory, type MemoryCatalogEntry, type MemoryEntry, type MemoryEntryMetadata, MemoryEntryMetadataSchema, MemoryEntrySchema, type MemoryUpdate, MemoryUpdateSchema, type OpperCallOptions, type OpperCallResponse, OpperClient, type OpperClientConfig, type OpperSpan, type OpperStreamChunk, type OpperStreamEvent, type OpperStreamResponse, Result, type RetryConfig, STREAM_ROOT_PATH, type Schema, SchemaValidationError, type SchemaValidationOptions, SilentLogger, StreamAssembler, type StreamAssemblerOptions, type StreamFeedResult, type StreamFinalizeResult, type Success, type Thought, ThoughtSchema, type Tool, type ToolCall, type ToolCallRecord, ToolCallRecordSchema, ToolCallSchema, type ToolDefinition, type ToolExample, type ToolExecutionContext, type ToolExecutionSummary, ToolExecutionSummarySchema, type ToolFailure, type ToolFunction, ToolMetadataSchema, type ToolOptions, type ToolProvider, type ToolResult, type ToolResultData, ToolResultFactory, ToolResultFailureSchema, type ToolResultInit, ToolResultSchema, ToolResultSuccessSchema, type ToolRunOptions, ToolRunner, type ToolSuccess, type UnregisterHook, type Usage, UsageSchema, type VisualizationOptions, addUsage, coerceToolDefinition, createAgentDecisionWithOutputSchema, createEmptyUsage, createFunctionTool, createHookManager, createInMemoryStore, createMCPServerConfig, createOpperClient, createStreamAssembler, createToolCallRecord, err, extractTools, generateAgentFlowDiagram, getDefaultLogger, getSchemaDefault, isSchemaValid, isToolProvider, mcp, mergeSchemaDefaults, normalizeToolEntries, ok, schemaToJson, setDefaultLogger, tool, validateSchema, validateToolInput, zodSchemaToJsonSchema };
|
|
2602
|
+
export { type AfterToolPayload, Agent, type AgentConfig, AgentContext, type AgentContextOptions, type AgentContextSnapshot, type AgentDecision, AgentDecisionSchema, type AgentEndPayload, type AgentEventListener, type AgentEventName, type AgentEventPayload, type AgentEventPayloadMap, AgentEvents, type AgentLogger, type AgentStartPayload, type AgentThought, BaseAgent, type BaseAgentConfig, type BaseUsage, BaseUsageSchema, type BeforeToolPayload, ConsoleLogger, type CreateSpanOptions, DEFAULT_MODEL, DEFAULT_RETRY_CONFIG, type ExecutionCycle, ExecutionCycleSchema, type ExecutionThought, type Failure, type HookEventName, HookEvents, type HookHandler, HookManager, type HookPayload, type HookPayloadMap, type HookRegistration, InMemoryStore, type IterationSummary, type JsonSchemaOptions, type LlmCallPayload, type LlmCallType, type LlmResponsePayload, LogLevel, type LoopEndPayload, type LoopStartPayload, MCPClient, type MCPClientOptions, type MCPServerConfig, type MCPServerConfigInput, MCPServerConfigSchema, type MCPTool, MCPToolProvider, type MCPToolProviderOptions, MCPconfig, type MaybePromise, type Memory, type MemoryCatalogEntry, type MemoryEntry, type MemoryEntryMetadata, MemoryEntryMetadataSchema, MemoryEntrySchema, type MemoryErrorPayload, type MemoryReadPayload, type MemoryUpdate, MemoryUpdateSchema, type MemoryWritePayload, type OpperCallOptions, type OpperCallResponse, OpperClient, type OpperClientConfig, type OpperSpan, type OpperStreamChunk, type OpperStreamEvent, type OpperStreamResponse, type PendingSpanUpdate, Result, type RetryConfig, STREAM_ROOT_PATH, type Schema, SchemaValidationError, type SchemaValidationOptions, SilentLogger, StreamAssembler, type StreamAssemblerOptions, type StreamChunkPayload, type StreamEndPayload, type StreamErrorPayload, type StreamFeedResult, type StreamFinalizeResult, type StreamStartPayload, type Success, type ThinkEndPayload, type Thought, ThoughtSchema, type Tool, type ToolCall, type ToolCallRecord, ToolCallRecordSchema, ToolCallSchema, type ToolDefinition, type ToolErrorPayload, type ToolExample, type ToolExecutionContext, type ToolExecutionSummary, ToolExecutionSummarySchema, type ToolFailure, type ToolFunction, ToolMetadataSchema, type ToolOptions, type ToolProvider, type ToolResult, type ToolResultData, ToolResultFactory, ToolResultFailureSchema, type ToolResultInit, ToolResultSchema, ToolResultSuccessSchema, type ToolRunOptions, ToolRunner, type ToolSuccess, type UnregisterHook, type Usage, UsageSchema, type VisualizationOptions, addUsage, coerceToolDefinition, createAgentDecisionWithOutputSchema, createEmptyUsage, createFunctionTool, createHookManager, createInMemoryStore, createMCPServerConfig, createOpperClient, createStreamAssembler, createToolCallRecord, err, extractTools, generateAgentFlowDiagram, getDefaultLogger, getSchemaDefault, isSchemaValid, isToolProvider, mcp, mergeSchemaDefaults, normalizeToolEntries, ok, schemaToJson, setDefaultLogger, tool, validateSchema, validateToolInput, zodSchemaToJsonSchema };
|