@igniter-js/agents 0.1.11 → 0.1.12
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.d.mts +16 -10
- package/dist/index.d.ts +16 -10
- package/dist/index.js +25 -174
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -174
- package/dist/index.mjs.map +1 -1
- package/dist/telemetry/index.d.mts +5 -5
- package/dist/telemetry/index.d.ts +5 -5
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,6 @@ import { experimental_createMCPClient } from '@ai-sdk/mcp';
|
|
|
3
3
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
4
4
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
5
5
|
import { ToolLoopAgent, tool } from 'ai';
|
|
6
|
-
import { IgniterTelemetryEvents } from '@igniter-js/telemetry';
|
|
7
|
-
import { z } from 'zod';
|
|
8
6
|
import { readFile, writeFile, mkdir } from 'fs/promises';
|
|
9
7
|
import { join } from 'path';
|
|
10
8
|
|
|
@@ -481,153 +479,6 @@ var IgniterAgentManagerCore = class _IgniterAgentManagerCore {
|
|
|
481
479
|
);
|
|
482
480
|
}
|
|
483
481
|
};
|
|
484
|
-
var BaseAgentAttributesSchema = z.object({
|
|
485
|
-
/**
|
|
486
|
-
* The agent name.
|
|
487
|
-
*/
|
|
488
|
-
"ctx.agent.name": z.string(),
|
|
489
|
-
/**
|
|
490
|
-
* The current scope (if scoped).
|
|
491
|
-
*/
|
|
492
|
-
"ctx.agent.scope": z.string().optional(),
|
|
493
|
-
/**
|
|
494
|
-
* The scope identifier value.
|
|
495
|
-
*/
|
|
496
|
-
"ctx.agent.scopeId": z.string().optional()
|
|
497
|
-
});
|
|
498
|
-
var LifecycleAttributesSchema = BaseAgentAttributesSchema.extend({
|
|
499
|
-
/**
|
|
500
|
-
* Number of toolsets registered.
|
|
501
|
-
*/
|
|
502
|
-
"ctx.lifecycle.toolsetCount": z.number().optional(),
|
|
503
|
-
/**
|
|
504
|
-
* Number of MCP connections configured.
|
|
505
|
-
*/
|
|
506
|
-
"ctx.lifecycle.mcpCount": z.number().optional(),
|
|
507
|
-
/**
|
|
508
|
-
* Whether memory adapter is configured.
|
|
509
|
-
*/
|
|
510
|
-
"ctx.lifecycle.hasMemory": z.boolean().optional()
|
|
511
|
-
});
|
|
512
|
-
var GenerationAttributesSchema = BaseAgentAttributesSchema.extend({
|
|
513
|
-
/**
|
|
514
|
-
* The model used for generation.
|
|
515
|
-
*/
|
|
516
|
-
"ctx.generation.model": z.string().optional(),
|
|
517
|
-
/**
|
|
518
|
-
* Number of input messages.
|
|
519
|
-
*/
|
|
520
|
-
"ctx.generation.inputMessages": z.number().optional(),
|
|
521
|
-
/**
|
|
522
|
-
* Number of input tokens (if available).
|
|
523
|
-
*/
|
|
524
|
-
"ctx.generation.inputTokens": z.number().optional(),
|
|
525
|
-
/**
|
|
526
|
-
* Number of output tokens (if available).
|
|
527
|
-
*/
|
|
528
|
-
"ctx.generation.outputTokens": z.number().optional(),
|
|
529
|
-
/**
|
|
530
|
-
* Total tokens used (if available).
|
|
531
|
-
*/
|
|
532
|
-
"ctx.generation.totalTokens": z.number().optional(),
|
|
533
|
-
/**
|
|
534
|
-
* Generation duration in milliseconds.
|
|
535
|
-
*/
|
|
536
|
-
"ctx.generation.durationMs": z.number().optional(),
|
|
537
|
-
/**
|
|
538
|
-
* Number of tool calls made during generation.
|
|
539
|
-
*/
|
|
540
|
-
"ctx.generation.toolCalls": z.number().optional(),
|
|
541
|
-
/**
|
|
542
|
-
* Whether the response was streamed.
|
|
543
|
-
*/
|
|
544
|
-
"ctx.generation.streamed": z.boolean().optional()
|
|
545
|
-
});
|
|
546
|
-
var ToolAttributesSchema = BaseAgentAttributesSchema.extend({
|
|
547
|
-
/**
|
|
548
|
-
* The toolset name.
|
|
549
|
-
*/
|
|
550
|
-
"ctx.tool.toolset": z.string(),
|
|
551
|
-
/**
|
|
552
|
-
* The tool name (within the toolset).
|
|
553
|
-
*/
|
|
554
|
-
"ctx.tool.name": z.string(),
|
|
555
|
-
/**
|
|
556
|
-
* The full tool identifier (toolset_name).
|
|
557
|
-
*/
|
|
558
|
-
"ctx.tool.fullName": z.string(),
|
|
559
|
-
/**
|
|
560
|
-
* Tool execution duration in milliseconds.
|
|
561
|
-
*/
|
|
562
|
-
"ctx.tool.durationMs": z.number().optional()
|
|
563
|
-
});
|
|
564
|
-
var MCPAttributesSchema = BaseAgentAttributesSchema.extend({
|
|
565
|
-
/**
|
|
566
|
-
* The MCP configuration name.
|
|
567
|
-
*/
|
|
568
|
-
"ctx.mcp.name": z.string(),
|
|
569
|
-
/**
|
|
570
|
-
* The MCP transport type (stdio, http).
|
|
571
|
-
*/
|
|
572
|
-
"ctx.mcp.type": z.enum(["stdio", "http"]),
|
|
573
|
-
/**
|
|
574
|
-
* Number of tools provided by this MCP.
|
|
575
|
-
*/
|
|
576
|
-
"ctx.mcp.toolCount": z.number().optional(),
|
|
577
|
-
/**
|
|
578
|
-
* Connection duration in milliseconds.
|
|
579
|
-
*/
|
|
580
|
-
"ctx.mcp.durationMs": z.number().optional()
|
|
581
|
-
});
|
|
582
|
-
var MemoryAttributesSchema = BaseAgentAttributesSchema.extend({
|
|
583
|
-
/**
|
|
584
|
-
* The memory operation type.
|
|
585
|
-
*/
|
|
586
|
-
"ctx.memory.operation": z.enum([
|
|
587
|
-
"getWorkingMemory",
|
|
588
|
-
"updateWorkingMemory",
|
|
589
|
-
"getMessages",
|
|
590
|
-
"saveMessage",
|
|
591
|
-
"getChats",
|
|
592
|
-
"saveChat",
|
|
593
|
-
"getChat",
|
|
594
|
-
"updateChatTitle",
|
|
595
|
-
"deleteChat"
|
|
596
|
-
]),
|
|
597
|
-
/**
|
|
598
|
-
* The memory scope (user, chat, global).
|
|
599
|
-
*/
|
|
600
|
-
"ctx.memory.scope": z.string().optional(),
|
|
601
|
-
/**
|
|
602
|
-
* Number of items affected.
|
|
603
|
-
*/
|
|
604
|
-
"ctx.memory.count": z.number().optional(),
|
|
605
|
-
/**
|
|
606
|
-
* Operation duration in milliseconds.
|
|
607
|
-
*/
|
|
608
|
-
"ctx.memory.durationMs": z.number().optional()
|
|
609
|
-
});
|
|
610
|
-
var ErrorAttributesSchema = BaseAgentAttributesSchema.extend({
|
|
611
|
-
/**
|
|
612
|
-
* The error code.
|
|
613
|
-
*/
|
|
614
|
-
"ctx.error.code": z.string(),
|
|
615
|
-
/**
|
|
616
|
-
* The sanitized error message (no sensitive data).
|
|
617
|
-
*/
|
|
618
|
-
"ctx.error.message": z.string().optional(),
|
|
619
|
-
/**
|
|
620
|
-
* The operation that failed.
|
|
621
|
-
*/
|
|
622
|
-
"ctx.error.operation": z.string().optional(),
|
|
623
|
-
/**
|
|
624
|
-
* The component that threw the error.
|
|
625
|
-
*/
|
|
626
|
-
"ctx.error.component": z.string().optional()
|
|
627
|
-
});
|
|
628
|
-
var IgniterAgentTelemetryEvents = IgniterTelemetryEvents.namespace(
|
|
629
|
-
"igniter.agent"
|
|
630
|
-
).event("lifecycle.start.started", LifecycleAttributesSchema).event("lifecycle.start.success", LifecycleAttributesSchema).event("lifecycle.start.error", ErrorAttributesSchema).event("lifecycle.stop.started", LifecycleAttributesSchema).event("lifecycle.stop.success", LifecycleAttributesSchema).event("lifecycle.stop.error", ErrorAttributesSchema).event("generation.generate.started", GenerationAttributesSchema).event("generation.generate.success", GenerationAttributesSchema).event("generation.generate.error", ErrorAttributesSchema).event("generation.stream.started", GenerationAttributesSchema).event("generation.stream.chunk", GenerationAttributesSchema).event("generation.stream.success", GenerationAttributesSchema).event("generation.stream.error", ErrorAttributesSchema).event("tool.execute.started", ToolAttributesSchema).event("tool.execute.success", ToolAttributesSchema).event("tool.execute.error", ErrorAttributesSchema).event("mcp.connect.started", MCPAttributesSchema).event("mcp.connect.success", MCPAttributesSchema).event("mcp.connect.error", ErrorAttributesSchema).event("mcp.disconnect.started", MCPAttributesSchema).event("mcp.disconnect.success", MCPAttributesSchema).event("mcp.disconnect.error", ErrorAttributesSchema).event("memory.operation.started", MemoryAttributesSchema).event("memory.operation.success", MemoryAttributesSchema).event("memory.operation.error", ErrorAttributesSchema).build();
|
|
631
482
|
|
|
632
483
|
// src/core/memory.ts
|
|
633
484
|
var MEMORY_ERROR_CODE = "IGNITER_AGENT_MEMORY_PROVIDER_ERROR" /* MEMORY_PROVIDER_ERROR */;
|
|
@@ -649,7 +500,7 @@ var IgniterAgentMemoryCore = class {
|
|
|
649
500
|
return attributes;
|
|
650
501
|
}
|
|
651
502
|
emitStart(operation, scope) {
|
|
652
|
-
this.telemetry?.emit(
|
|
503
|
+
this.telemetry?.emit("igniter.agent.memory.operation.started", {
|
|
653
504
|
level: "debug",
|
|
654
505
|
attributes: this.getBaseAttributes(operation, scope)
|
|
655
506
|
});
|
|
@@ -662,7 +513,7 @@ var IgniterAgentMemoryCore = class {
|
|
|
662
513
|
if (count !== void 0) {
|
|
663
514
|
attributes["ctx.memory.count"] = count;
|
|
664
515
|
}
|
|
665
|
-
this.telemetry?.emit(
|
|
516
|
+
this.telemetry?.emit("igniter.agent.memory.operation.success", {
|
|
666
517
|
level: "debug",
|
|
667
518
|
attributes
|
|
668
519
|
});
|
|
@@ -675,7 +526,7 @@ var IgniterAgentMemoryCore = class {
|
|
|
675
526
|
"ctx.error.operation": operation,
|
|
676
527
|
"ctx.error.component": "memory"
|
|
677
528
|
};
|
|
678
|
-
this.telemetry?.emit(
|
|
529
|
+
this.telemetry?.emit("igniter.agent.memory.operation.error", {
|
|
679
530
|
level: "error",
|
|
680
531
|
attributes
|
|
681
532
|
});
|
|
@@ -898,7 +749,7 @@ var IgniterAgentCore = class {
|
|
|
898
749
|
"ctx.lifecycle.hasMemory": Boolean(this.memory)
|
|
899
750
|
};
|
|
900
751
|
this.logger?.debug("IgniterAgent.start started", lifecycleAttributes);
|
|
901
|
-
this.telemetry?.emit(
|
|
752
|
+
this.telemetry?.emit("igniter.agent.lifecycle.start.started", {
|
|
902
753
|
level: "debug",
|
|
903
754
|
attributes: lifecycleAttributes
|
|
904
755
|
});
|
|
@@ -906,7 +757,7 @@ var IgniterAgentCore = class {
|
|
|
906
757
|
for (const mcpConfig of mcpConfigs) {
|
|
907
758
|
const mcpStart = Date.now();
|
|
908
759
|
this.hooks.onMCPStart?.(this.getName(), mcpConfig.name);
|
|
909
|
-
this.telemetry?.emit(
|
|
760
|
+
this.telemetry?.emit("igniter.agent.mcp.connect.started", {
|
|
910
761
|
level: "debug",
|
|
911
762
|
attributes: {
|
|
912
763
|
"ctx.agent.name": this.getName(),
|
|
@@ -917,7 +768,7 @@ var IgniterAgentCore = class {
|
|
|
917
768
|
try {
|
|
918
769
|
const mcpToolset = await this.initializeMCPClient(mcpConfig);
|
|
919
770
|
toolsets[mcpConfig.name] = mcpToolset;
|
|
920
|
-
this.telemetry?.emit(
|
|
771
|
+
this.telemetry?.emit("igniter.agent.mcp.connect.success", {
|
|
921
772
|
level: "debug",
|
|
922
773
|
attributes: {
|
|
923
774
|
"ctx.agent.name": this.getName(),
|
|
@@ -929,7 +780,7 @@ var IgniterAgentCore = class {
|
|
|
929
780
|
});
|
|
930
781
|
} catch (error) {
|
|
931
782
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
932
|
-
this.telemetry?.emit(
|
|
783
|
+
this.telemetry?.emit("igniter.agent.mcp.connect.error", {
|
|
933
784
|
level: "error",
|
|
934
785
|
attributes: {
|
|
935
786
|
"ctx.agent.name": this.getName(),
|
|
@@ -944,7 +795,7 @@ var IgniterAgentCore = class {
|
|
|
944
795
|
}
|
|
945
796
|
}
|
|
946
797
|
const durationMs = Date.now() - startTime;
|
|
947
|
-
this.telemetry?.emit(
|
|
798
|
+
this.telemetry?.emit("igniter.agent.lifecycle.start.success", {
|
|
948
799
|
level: "debug",
|
|
949
800
|
attributes: {
|
|
950
801
|
...lifecycleAttributes,
|
|
@@ -959,7 +810,7 @@ var IgniterAgentCore = class {
|
|
|
959
810
|
this.hooks.onAgentStart?.(this.getName());
|
|
960
811
|
} catch (error) {
|
|
961
812
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
962
|
-
this.telemetry?.emit(
|
|
813
|
+
this.telemetry?.emit("igniter.agent.lifecycle.start.error", {
|
|
963
814
|
level: "error",
|
|
964
815
|
attributes: {
|
|
965
816
|
...lifecycleAttributes,
|
|
@@ -984,14 +835,14 @@ var IgniterAgentCore = class {
|
|
|
984
835
|
"ctx.lifecycle.hasMemory": Boolean(this.memory)
|
|
985
836
|
};
|
|
986
837
|
this.logger?.debug("IgniterAgent.stop started", lifecycleAttributes);
|
|
987
|
-
this.telemetry?.emit(
|
|
838
|
+
this.telemetry?.emit("igniter.agent.lifecycle.stop.started", {
|
|
988
839
|
level: "debug",
|
|
989
840
|
attributes: lifecycleAttributes
|
|
990
841
|
});
|
|
991
842
|
try {
|
|
992
843
|
for (const mcpConfig of mcpConfigs) {
|
|
993
844
|
const mcpStart = Date.now();
|
|
994
|
-
this.telemetry?.emit(
|
|
845
|
+
this.telemetry?.emit("igniter.agent.mcp.disconnect.started", {
|
|
995
846
|
level: "debug",
|
|
996
847
|
attributes: {
|
|
997
848
|
"ctx.agent.name": this.getName(),
|
|
@@ -1011,7 +862,7 @@ var IgniterAgentCore = class {
|
|
|
1011
862
|
tools: {}
|
|
1012
863
|
};
|
|
1013
864
|
}
|
|
1014
|
-
this.telemetry?.emit(
|
|
865
|
+
this.telemetry?.emit("igniter.agent.mcp.disconnect.success", {
|
|
1015
866
|
level: "debug",
|
|
1016
867
|
attributes: {
|
|
1017
868
|
"ctx.agent.name": this.getName(),
|
|
@@ -1022,7 +873,7 @@ var IgniterAgentCore = class {
|
|
|
1022
873
|
});
|
|
1023
874
|
} catch (error) {
|
|
1024
875
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
1025
|
-
this.telemetry?.emit(
|
|
876
|
+
this.telemetry?.emit("igniter.agent.mcp.disconnect.error", {
|
|
1026
877
|
level: "error",
|
|
1027
878
|
attributes: {
|
|
1028
879
|
"ctx.agent.name": this.getName(),
|
|
@@ -1037,7 +888,7 @@ var IgniterAgentCore = class {
|
|
|
1037
888
|
}
|
|
1038
889
|
}
|
|
1039
890
|
const durationMs = Date.now() - startTime;
|
|
1040
|
-
this.telemetry?.emit(
|
|
891
|
+
this.telemetry?.emit("igniter.agent.lifecycle.stop.success", {
|
|
1041
892
|
level: "debug",
|
|
1042
893
|
attributes: {
|
|
1043
894
|
...lifecycleAttributes,
|
|
@@ -1051,7 +902,7 @@ var IgniterAgentCore = class {
|
|
|
1051
902
|
});
|
|
1052
903
|
} catch (error) {
|
|
1053
904
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
1054
|
-
this.telemetry?.emit(
|
|
905
|
+
this.telemetry?.emit("igniter.agent.lifecycle.stop.error", {
|
|
1055
906
|
level: "error",
|
|
1056
907
|
attributes: {
|
|
1057
908
|
...lifecycleAttributes,
|
|
@@ -1073,7 +924,7 @@ var IgniterAgentCore = class {
|
|
|
1073
924
|
"ctx.generation.streamed": false
|
|
1074
925
|
};
|
|
1075
926
|
this.logger?.debug("IgniterAgent.generate started", attributes);
|
|
1076
|
-
this.telemetry?.emit(
|
|
927
|
+
this.telemetry?.emit("igniter.agent.generation.generate.started", {
|
|
1077
928
|
level: "debug",
|
|
1078
929
|
attributes
|
|
1079
930
|
});
|
|
@@ -1083,7 +934,7 @@ var IgniterAgentCore = class {
|
|
|
1083
934
|
);
|
|
1084
935
|
const result = await agent.generate(input);
|
|
1085
936
|
const durationMs = Date.now() - startTime;
|
|
1086
|
-
this.telemetry?.emit(
|
|
937
|
+
this.telemetry?.emit("igniter.agent.generation.generate.success", {
|
|
1087
938
|
level: "debug",
|
|
1088
939
|
attributes: {
|
|
1089
940
|
...attributes,
|
|
@@ -1097,7 +948,7 @@ var IgniterAgentCore = class {
|
|
|
1097
948
|
return result;
|
|
1098
949
|
} catch (error) {
|
|
1099
950
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
1100
|
-
this.telemetry?.emit(
|
|
951
|
+
this.telemetry?.emit("igniter.agent.generation.generate.error", {
|
|
1101
952
|
level: "error",
|
|
1102
953
|
attributes: {
|
|
1103
954
|
...attributes,
|
|
@@ -1119,7 +970,7 @@ var IgniterAgentCore = class {
|
|
|
1119
970
|
"ctx.generation.streamed": true
|
|
1120
971
|
};
|
|
1121
972
|
this.logger?.debug("IgniterAgent.stream started", attributes);
|
|
1122
|
-
this.telemetry?.emit(
|
|
973
|
+
this.telemetry?.emit("igniter.agent.generation.stream.started", {
|
|
1123
974
|
level: "debug",
|
|
1124
975
|
attributes
|
|
1125
976
|
});
|
|
@@ -1130,13 +981,13 @@ var IgniterAgentCore = class {
|
|
|
1130
981
|
const result = await agent.stream(input);
|
|
1131
982
|
const durationMs = Date.now() - startTime;
|
|
1132
983
|
const emitChunk = () => {
|
|
1133
|
-
this.telemetry?.emit(
|
|
984
|
+
this.telemetry?.emit("igniter.agent.generation.stream.chunk", {
|
|
1134
985
|
level: "debug",
|
|
1135
986
|
attributes
|
|
1136
987
|
});
|
|
1137
988
|
};
|
|
1138
989
|
const wrapped = this.wrapStreamResult(result, emitChunk);
|
|
1139
|
-
this.telemetry?.emit(
|
|
990
|
+
this.telemetry?.emit("igniter.agent.generation.stream.success", {
|
|
1140
991
|
level: "debug",
|
|
1141
992
|
attributes: {
|
|
1142
993
|
...attributes,
|
|
@@ -1150,7 +1001,7 @@ var IgniterAgentCore = class {
|
|
|
1150
1001
|
return wrapped;
|
|
1151
1002
|
} catch (error) {
|
|
1152
1003
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
1153
|
-
this.telemetry?.emit(
|
|
1004
|
+
this.telemetry?.emit("igniter.agent.generation.stream.error", {
|
|
1154
1005
|
level: "error",
|
|
1155
1006
|
attributes: {
|
|
1156
1007
|
...attributes,
|
|
@@ -1211,7 +1062,7 @@ var IgniterAgentCore = class {
|
|
|
1211
1062
|
execute: async (input, options) => {
|
|
1212
1063
|
const startTime = Date.now();
|
|
1213
1064
|
this.hooks.onToolCallStart?.(agentName, fullName, input);
|
|
1214
|
-
this.telemetry?.emit(
|
|
1065
|
+
this.telemetry?.emit("igniter.agent.tool.execute.started", {
|
|
1215
1066
|
level: "debug",
|
|
1216
1067
|
attributes: {
|
|
1217
1068
|
"ctx.agent.name": agentName,
|
|
@@ -1228,7 +1079,7 @@ var IgniterAgentCore = class {
|
|
|
1228
1079
|
const result = await execute(input, options);
|
|
1229
1080
|
const durationMs = Date.now() - startTime;
|
|
1230
1081
|
this.hooks.onToolCallEnd?.(agentName, fullName, result);
|
|
1231
|
-
this.telemetry?.emit(
|
|
1082
|
+
this.telemetry?.emit("igniter.agent.tool.execute.success", {
|
|
1232
1083
|
level: "debug",
|
|
1233
1084
|
attributes: {
|
|
1234
1085
|
"ctx.agent.name": agentName,
|
|
@@ -1247,7 +1098,7 @@ var IgniterAgentCore = class {
|
|
|
1247
1098
|
} catch (error) {
|
|
1248
1099
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
1249
1100
|
this.hooks.onToolCallError?.(agentName, fullName, err);
|
|
1250
|
-
this.telemetry?.emit(
|
|
1101
|
+
this.telemetry?.emit("igniter.agent.tool.execute.error", {
|
|
1251
1102
|
level: "error",
|
|
1252
1103
|
attributes: {
|
|
1253
1104
|
"ctx.agent.name": agentName,
|