@inkeep/agents-run-api 0.1.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.
Files changed (149) hide show
  1. package/README.md +117 -0
  2. package/dist/AgentExecutionServer.d.ts +23 -0
  3. package/dist/AgentExecutionServer.d.ts.map +1 -0
  4. package/dist/AgentExecutionServer.js +32 -0
  5. package/dist/__tests__/setup.d.ts +4 -0
  6. package/dist/__tests__/setup.d.ts.map +1 -0
  7. package/dist/__tests__/setup.js +50 -0
  8. package/dist/__tests__/utils/testProject.d.ts +18 -0
  9. package/dist/__tests__/utils/testProject.d.ts.map +1 -0
  10. package/dist/__tests__/utils/testProject.js +26 -0
  11. package/dist/__tests__/utils/testRequest.d.ts +8 -0
  12. package/dist/__tests__/utils/testRequest.d.ts.map +1 -0
  13. package/dist/__tests__/utils/testRequest.js +32 -0
  14. package/dist/__tests__/utils/testTenant.d.ts +64 -0
  15. package/dist/__tests__/utils/testTenant.d.ts.map +1 -0
  16. package/dist/__tests__/utils/testTenant.js +71 -0
  17. package/dist/a2a/client.d.ts +182 -0
  18. package/dist/a2a/client.d.ts.map +1 -0
  19. package/dist/a2a/client.js +645 -0
  20. package/dist/a2a/handlers.d.ts +4 -0
  21. package/dist/a2a/handlers.d.ts.map +1 -0
  22. package/dist/a2a/handlers.js +657 -0
  23. package/dist/a2a/transfer.d.ts +18 -0
  24. package/dist/a2a/transfer.d.ts.map +1 -0
  25. package/dist/a2a/transfer.js +22 -0
  26. package/dist/a2a/types.d.ts +63 -0
  27. package/dist/a2a/types.d.ts.map +1 -0
  28. package/dist/a2a/types.js +1 -0
  29. package/dist/agents/Agent.d.ts +154 -0
  30. package/dist/agents/Agent.d.ts.map +1 -0
  31. package/dist/agents/Agent.js +1105 -0
  32. package/dist/agents/ModelFactory.d.ts +62 -0
  33. package/dist/agents/ModelFactory.d.ts.map +1 -0
  34. package/dist/agents/ModelFactory.js +208 -0
  35. package/dist/agents/SystemPromptBuilder.d.ts +14 -0
  36. package/dist/agents/SystemPromptBuilder.d.ts.map +1 -0
  37. package/dist/agents/SystemPromptBuilder.js +62 -0
  38. package/dist/agents/ToolSessionManager.d.ts +61 -0
  39. package/dist/agents/ToolSessionManager.d.ts.map +1 -0
  40. package/dist/agents/ToolSessionManager.js +143 -0
  41. package/dist/agents/artifactTools.d.ts +30 -0
  42. package/dist/agents/artifactTools.d.ts.map +1 -0
  43. package/dist/agents/artifactTools.js +463 -0
  44. package/dist/agents/generateTaskHandler.d.ts +41 -0
  45. package/dist/agents/generateTaskHandler.d.ts.map +1 -0
  46. package/dist/agents/generateTaskHandler.js +350 -0
  47. package/dist/agents/relationTools.d.ts +33 -0
  48. package/dist/agents/relationTools.d.ts.map +1 -0
  49. package/dist/agents/relationTools.js +245 -0
  50. package/dist/agents/types.d.ts +23 -0
  51. package/dist/agents/types.d.ts.map +1 -0
  52. package/dist/agents/types.js +1 -0
  53. package/dist/agents/versions/V1Config.d.ts +21 -0
  54. package/dist/agents/versions/V1Config.d.ts.map +1 -0
  55. package/dist/agents/versions/V1Config.js +285 -0
  56. package/dist/app.d.ts +4 -0
  57. package/dist/app.d.ts.map +1 -0
  58. package/dist/app.js +194 -0
  59. package/dist/data/agentGraph.d.ts +4 -0
  60. package/dist/data/agentGraph.d.ts.map +1 -0
  61. package/dist/data/agentGraph.js +73 -0
  62. package/dist/data/agents.d.ts +4 -0
  63. package/dist/data/agents.d.ts.map +1 -0
  64. package/dist/data/agents.js +73 -0
  65. package/dist/data/conversations.d.ts +59 -0
  66. package/dist/data/conversations.d.ts.map +1 -0
  67. package/dist/data/conversations.js +216 -0
  68. package/dist/data/db/clean.d.ts +6 -0
  69. package/dist/data/db/clean.d.ts.map +1 -0
  70. package/dist/data/db/clean.js +77 -0
  71. package/dist/data/db/dbClient.d.ts +3 -0
  72. package/dist/data/db/dbClient.d.ts.map +1 -0
  73. package/dist/data/db/dbClient.js +13 -0
  74. package/dist/env.d.ts +43 -0
  75. package/dist/env.d.ts.map +1 -0
  76. package/dist/env.js +63 -0
  77. package/dist/handlers/executionHandler.d.ts +36 -0
  78. package/dist/handlers/executionHandler.d.ts.map +1 -0
  79. package/dist/handlers/executionHandler.js +402 -0
  80. package/dist/index.d.ts +5 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +43 -0
  83. package/dist/instrumentation.d.ts +13 -0
  84. package/dist/instrumentation.d.ts.map +1 -0
  85. package/dist/instrumentation.js +66 -0
  86. package/dist/logger.d.ts +4 -0
  87. package/dist/logger.d.ts.map +1 -0
  88. package/dist/logger.js +32 -0
  89. package/dist/middleware/api-key-auth.d.ts +22 -0
  90. package/dist/middleware/api-key-auth.d.ts.map +1 -0
  91. package/dist/middleware/api-key-auth.js +139 -0
  92. package/dist/middleware/index.d.ts +2 -0
  93. package/dist/middleware/index.d.ts.map +1 -0
  94. package/dist/middleware/index.js +1 -0
  95. package/dist/openapi.d.ts +2 -0
  96. package/dist/openapi.d.ts.map +1 -0
  97. package/dist/openapi.js +36 -0
  98. package/dist/routes/agents.d.ts +4 -0
  99. package/dist/routes/agents.d.ts.map +1 -0
  100. package/dist/routes/agents.js +155 -0
  101. package/dist/routes/chat.d.ts +4 -0
  102. package/dist/routes/chat.d.ts.map +1 -0
  103. package/dist/routes/chat.js +308 -0
  104. package/dist/routes/chatDataStream.d.ts +4 -0
  105. package/dist/routes/chatDataStream.d.ts.map +1 -0
  106. package/dist/routes/chatDataStream.js +179 -0
  107. package/dist/routes/mcp.d.ts +4 -0
  108. package/dist/routes/mcp.d.ts.map +1 -0
  109. package/dist/routes/mcp.js +500 -0
  110. package/dist/tracer.d.ts +24 -0
  111. package/dist/tracer.d.ts.map +1 -0
  112. package/dist/tracer.js +97 -0
  113. package/dist/types/chat.d.ts +25 -0
  114. package/dist/types/chat.d.ts.map +1 -0
  115. package/dist/types/chat.js +1 -0
  116. package/dist/types/execution-context.d.ts +14 -0
  117. package/dist/types/execution-context.d.ts.map +1 -0
  118. package/dist/types/execution-context.js +14 -0
  119. package/dist/utils/agent-operations.d.ts +79 -0
  120. package/dist/utils/agent-operations.d.ts.map +1 -0
  121. package/dist/utils/agent-operations.js +67 -0
  122. package/dist/utils/artifact-component-schema.d.ts +29 -0
  123. package/dist/utils/artifact-component-schema.d.ts.map +1 -0
  124. package/dist/utils/artifact-component-schema.js +119 -0
  125. package/dist/utils/artifact-parser.d.ts +71 -0
  126. package/dist/utils/artifact-parser.d.ts.map +1 -0
  127. package/dist/utils/artifact-parser.js +251 -0
  128. package/dist/utils/cleanup.d.ts +19 -0
  129. package/dist/utils/cleanup.d.ts.map +1 -0
  130. package/dist/utils/cleanup.js +66 -0
  131. package/dist/utils/data-component-schema.d.ts +6 -0
  132. package/dist/utils/data-component-schema.d.ts.map +1 -0
  133. package/dist/utils/data-component-schema.js +43 -0
  134. package/dist/utils/graph-session.d.ts +200 -0
  135. package/dist/utils/graph-session.d.ts.map +1 -0
  136. package/dist/utils/graph-session.js +1009 -0
  137. package/dist/utils/incremental-stream-parser.d.ts +57 -0
  138. package/dist/utils/incremental-stream-parser.d.ts.map +1 -0
  139. package/dist/utils/incremental-stream-parser.js +287 -0
  140. package/dist/utils/response-formatter.d.ts +27 -0
  141. package/dist/utils/response-formatter.d.ts.map +1 -0
  142. package/dist/utils/response-formatter.js +160 -0
  143. package/dist/utils/stream-helpers.d.ts +162 -0
  144. package/dist/utils/stream-helpers.d.ts.map +1 -0
  145. package/dist/utils/stream-helpers.js +385 -0
  146. package/dist/utils/stream-registry.d.ts +18 -0
  147. package/dist/utils/stream-registry.d.ts.map +1 -0
  148. package/dist/utils/stream-registry.js +33 -0
  149. package/package.json +88 -0
@@ -0,0 +1,24 @@
1
+ import { type Span, type Tracer } from '@opentelemetry/api';
2
+ export declare const BASE = "inkeep-chat";
3
+ export declare const SERVICE_NAME = "inkeep-chat";
4
+ export declare const SERVICE_VERSION = "1.0.0";
5
+ export declare const createSpanName: (suffix: string) => string;
6
+ /**
7
+ * Helper function to handle span errors consistently
8
+ * Records the exception, sets error status, and optionally logs
9
+ */
10
+ export declare function handleSpanError(span: Span, error: unknown, logger?: {
11
+ error: (obj: any, msg?: string) => void;
12
+ }, logMessage?: string): void;
13
+ /**
14
+ * Get the global tracer instance
15
+ * This creates a single tracer for the entire application
16
+ */
17
+ export declare function getGlobalTracer(): Tracer;
18
+ /**
19
+ * Force flush the tracer provider to ensure critical spans are sent immediately
20
+ * This is useful for critical operations where we want to ensure telemetry data
21
+ * is sent before the operation completes or fails
22
+ */
23
+ export declare function forceFlushTracer(): Promise<void>;
24
+ //# sourceMappingURL=tracer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../src/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAGT,KAAK,MAAM,EAEZ,MAAM,oBAAoB,CAAC;AAM5B,eAAO,MAAM,IAAI,gBAAgB,CAAC;AAGlC,eAAO,MAAM,YAAY,gBAAgB,CAAC;AAC1C,eAAO,MAAM,eAAe,UAAU,CAAC;AAGvC,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,WAAwB,CAAC;AAyCtE;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE;IAAE,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,EACpD,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI,CAgBN;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAUxC;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAatD"}
package/dist/tracer.js ADDED
@@ -0,0 +1,97 @@
1
+ import { SpanStatusCode, trace, } from '@opentelemetry/api';
2
+ import { getLogger } from './logger.js';
3
+ const logger = getLogger('tracer');
4
+ // Base prefix for all span names - export this to use in other files
5
+ export const BASE = 'inkeep-chat';
6
+ // Service name and version constants for consistent tracer identification
7
+ export const SERVICE_NAME = 'inkeep-chat';
8
+ export const SERVICE_VERSION = '1.0.0';
9
+ // Helper function to create prefixed span names
10
+ export const createSpanName = (suffix) => `${BASE}.${suffix}`;
11
+ // No-op span implementation for when OpenTelemetry is not available
12
+ const createNoOpSpan = () => ({
13
+ setAttributes: () => ({}),
14
+ recordException: () => ({}),
15
+ setStatus: () => ({}),
16
+ addEvent: () => ({}),
17
+ end: () => { },
18
+ isRecording: () => false,
19
+ setAttribute: () => ({}),
20
+ updateName: () => ({}),
21
+ spanContext: () => ({
22
+ traceId: '00000000000000000000000000000000',
23
+ spanId: '0000000000000000',
24
+ traceFlags: 0,
25
+ }),
26
+ addLink: () => ({}),
27
+ addLinks: () => ({}),
28
+ });
29
+ // No-op tracer implementation for when OpenTelemetry is not available
30
+ const noopTracer = {
31
+ startActiveSpan(name, arg1, arg2, arg3) {
32
+ const fn = typeof arg1 === 'function' ? arg1 : typeof arg2 === 'function' ? arg2 : arg3;
33
+ if (!fn)
34
+ throw new Error('No callback function provided');
35
+ return fn(createNoOpSpan());
36
+ },
37
+ startSpan(name, options) {
38
+ return createNoOpSpan();
39
+ },
40
+ };
41
+ // Global tracer instance - singleton pattern
42
+ let globalTracerInstance = null;
43
+ /**
44
+ * Helper function to handle span errors consistently
45
+ * Records the exception, sets error status, and optionally logs
46
+ */
47
+ export function handleSpanError(span, error, logger, logMessage) {
48
+ const errorMessage = error instanceof Error ? error.message : String(error);
49
+ // Record the exception in the span
50
+ span.recordException(error);
51
+ // Set error status
52
+ span.setStatus({
53
+ code: SpanStatusCode.ERROR,
54
+ message: errorMessage,
55
+ });
56
+ // Optionally log the error
57
+ if (logger && logMessage) {
58
+ logger.error({ error: errorMessage }, logMessage);
59
+ }
60
+ }
61
+ /**
62
+ * Get the global tracer instance
63
+ * This creates a single tracer for the entire application
64
+ */
65
+ export function getGlobalTracer() {
66
+ if (!globalTracerInstance) {
67
+ try {
68
+ globalTracerInstance = trace.getTracer(SERVICE_NAME, SERVICE_VERSION);
69
+ }
70
+ catch (error) {
71
+ logger.debug('OpenTelemetry tracer not available, using no-op tracer');
72
+ globalTracerInstance = noopTracer;
73
+ }
74
+ }
75
+ return globalTracerInstance;
76
+ }
77
+ /**
78
+ * Force flush the tracer provider to ensure critical spans are sent immediately
79
+ * This is useful for critical operations where we want to ensure telemetry data
80
+ * is sent before the operation completes or fails
81
+ */
82
+ export async function forceFlushTracer() {
83
+ try {
84
+ // Import the span processor from instrumentation
85
+ const { spanProcessor } = await import('./instrumentation.js');
86
+ if (spanProcessor && typeof spanProcessor.forceFlush === 'function') {
87
+ await spanProcessor.forceFlush();
88
+ logger.debug('Span processor force flush completed');
89
+ }
90
+ else {
91
+ logger.debug('Span processor does not support force flush or is not available');
92
+ }
93
+ }
94
+ catch (error) {
95
+ logger.warn({ error }, 'Failed to force flush tracer');
96
+ }
97
+ }
@@ -0,0 +1,25 @@
1
+ export type ContentItem = {
2
+ type: string;
3
+ text?: string;
4
+ };
5
+ export type Message = {
6
+ role: 'system' | 'user' | 'assistant' | 'function' | 'tool';
7
+ content: string | ContentItem[];
8
+ name?: string;
9
+ };
10
+ export type ChatCompletionRequest = {
11
+ model: string;
12
+ messages: Message[];
13
+ temperature?: number;
14
+ top_p?: number;
15
+ n?: number;
16
+ stream?: boolean;
17
+ max_tokens?: number;
18
+ presence_penalty?: number;
19
+ frequency_penalty?: number;
20
+ logit_bias?: Record<string, number>;
21
+ user?: string;
22
+ tools?: Record<string, unknown>;
23
+ runConfig?: Record<string, unknown>;
24
+ };
25
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/types/chat.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;IAC5D,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { ExecutionContext } from '@inkeep/agents-core';
2
+ /**
3
+ * Create execution context from middleware values
4
+ */
5
+ export declare function createExecutionContext(params: {
6
+ apiKey: string;
7
+ tenantId: string;
8
+ projectId: string;
9
+ graphId: string;
10
+ apiKeyId: string;
11
+ agentId?: string;
12
+ baseUrl?: string;
13
+ }): ExecutionContext;
14
+ //# sourceMappingURL=execution-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../../src/types/execution-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,gBAAgB,CAUnB"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Create execution context from middleware values
3
+ */
4
+ export function createExecutionContext(params) {
5
+ return {
6
+ apiKey: params.apiKey,
7
+ tenantId: params.tenantId,
8
+ projectId: params.projectId,
9
+ graphId: params.graphId,
10
+ baseUrl: params.baseUrl || process.env.API_URL || 'http://localhost:3003',
11
+ apiKeyId: params.apiKeyId,
12
+ agentId: params.agentId,
13
+ };
14
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Agent initialization operation event
3
+ */
4
+ export interface AgentInitializingEvent {
5
+ type: 'agent_initializing';
6
+ ctx: {
7
+ sessionId: string;
8
+ graphId: string;
9
+ };
10
+ }
11
+ /**
12
+ * Agent ready operation event
13
+ */
14
+ export interface AgentReadyEvent {
15
+ type: 'agent_ready';
16
+ ctx: {
17
+ sessionId: string;
18
+ graphId: string;
19
+ };
20
+ }
21
+ /**
22
+ * Completion operation event
23
+ */
24
+ export interface CompletionEvent {
25
+ type: 'completion';
26
+ ctx: {
27
+ agent: string;
28
+ iteration: number;
29
+ };
30
+ }
31
+ /**
32
+ * Error operation event
33
+ */
34
+ export interface ErrorEvent {
35
+ type: 'error';
36
+ ctx: {
37
+ error: string;
38
+ agent?: string;
39
+ };
40
+ }
41
+ /**
42
+ * Status update operation event with flexible structured/unstructured data
43
+ */
44
+ export interface StatusUpdateEvent {
45
+ type: 'status_update';
46
+ ctx: {
47
+ summary?: string;
48
+ [key: string]: any;
49
+ };
50
+ }
51
+ /**
52
+ * Discriminated union of all operation events
53
+ */
54
+ export type OperationEvent = AgentInitializingEvent | AgentReadyEvent | CompletionEvent | ErrorEvent | StatusUpdateEvent;
55
+ /**
56
+ * Creates an agent initializing operation
57
+ */
58
+ export declare function agentInitializingOp(sessionId: string, graphId: string): AgentInitializingEvent;
59
+ /**
60
+ * Creates an agent ready operation
61
+ */
62
+ export declare function agentReadyOp(sessionId: string, graphId: string): AgentReadyEvent;
63
+ /**
64
+ * Creates a completion operation
65
+ */
66
+ export declare function completionOp(agentId: string, iterations: number): CompletionEvent;
67
+ /**
68
+ * Creates an error operation
69
+ */
70
+ export declare function errorOp(error: string, agentId?: string): ErrorEvent;
71
+ /**
72
+ * Generate a unique tool execution ID for lifecycle tracking
73
+ */
74
+ export declare function generateToolId(): string;
75
+ /**
76
+ * Creates a status update operation with flexible data
77
+ */
78
+ export declare function statusUpdateOp(ctx: Record<string, any>): StatusUpdateEvent;
79
+ //# sourceMappingURL=agent-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-operations.d.ts","sourceRoot":"","sources":["../../src/utils/agent-operations.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,GAAG,EAAE;QACH,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,GAAG,EAAE;QACH,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE;QACH,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,EAAE;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,sBAAsB,GACtB,eAAe,GACf,eAAe,GACf,UAAU,GACV,iBAAiB,CAAC;AAMtB;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAQ9F;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAQhF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,eAAe,CAQjF;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAQnE;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,iBAAiB,CAK1E"}
@@ -0,0 +1,67 @@
1
+ import { nanoid } from 'nanoid';
2
+ // =============================================================================
3
+ // OPERATION FUNCTIONS
4
+ // =============================================================================
5
+ /**
6
+ * Creates an agent initializing operation
7
+ */
8
+ export function agentInitializingOp(sessionId, graphId) {
9
+ return {
10
+ type: 'agent_initializing',
11
+ ctx: {
12
+ sessionId,
13
+ graphId,
14
+ },
15
+ };
16
+ }
17
+ /**
18
+ * Creates an agent ready operation
19
+ */
20
+ export function agentReadyOp(sessionId, graphId) {
21
+ return {
22
+ type: 'agent_ready',
23
+ ctx: {
24
+ sessionId,
25
+ graphId,
26
+ },
27
+ };
28
+ }
29
+ /**
30
+ * Creates a completion operation
31
+ */
32
+ export function completionOp(agentId, iterations) {
33
+ return {
34
+ type: 'completion',
35
+ ctx: {
36
+ agent: agentId,
37
+ iteration: iterations,
38
+ },
39
+ };
40
+ }
41
+ /**
42
+ * Creates an error operation
43
+ */
44
+ export function errorOp(error, agentId) {
45
+ return {
46
+ type: 'error',
47
+ ctx: {
48
+ error,
49
+ agent: agentId,
50
+ },
51
+ };
52
+ }
53
+ /**
54
+ * Generate a unique tool execution ID for lifecycle tracking
55
+ */
56
+ export function generateToolId() {
57
+ return `tool_${nanoid(8)}`;
58
+ }
59
+ /**
60
+ * Creates a status update operation with flexible data
61
+ */
62
+ export function statusUpdateOp(ctx) {
63
+ return {
64
+ type: 'status_update',
65
+ ctx,
66
+ };
67
+ }
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import type { ArtifactComponentApiSelect, DataComponentInsert } from '@inkeep/agents-core';
3
+ /**
4
+ * Converts artifact component configurations to Zod schema for structured generation
5
+ */
6
+ export declare function createArtifactComponentsSchema(artifactComponents?: ArtifactComponentApiSelect[]): z.ZodObject<{}, z.core.$strip> | z.ZodUnion<any>;
7
+ /**
8
+ * Create schema for artifact component summary props only (for quick display)
9
+ */
10
+ export declare function createArtifactComponentsSummarySchema(artifactComponents?: ArtifactComponentApiSelect[]): z.ZodUnion<any> | z.ZodObject<{}, z.core.$strip>;
11
+ /**
12
+ * Create schema for artifact component full props only (for detailed display)
13
+ */
14
+ export declare function createArtifactComponentsFullSchema(artifactComponents?: ArtifactComponentApiSelect[]): z.ZodUnion<any> | z.ZodObject<{}, z.core.$strip>;
15
+ /**
16
+ * Standard artifact reference component schema for tool responses
17
+ */
18
+ export declare class ArtifactReferenceSchema {
19
+ private static readonly ARTIFACT_PROPS_SCHEMA;
20
+ /**
21
+ * Get the standard Zod schema for artifact reference components
22
+ */
23
+ static getSchema(): z.ZodType<any>;
24
+ /**
25
+ * Get complete DataComponent by adding missing fields to base definition
26
+ */
27
+ static getDataComponent(tenantId: string, projectId?: string): DataComponentInsert;
28
+ }
29
+ //# sourceMappingURL=artifact-component-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact-component-schema.d.ts","sourceRoot":"","sources":["../../src/utils/artifact-component-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAM3F;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,kBAAkB,CAAC,EAAE,0BAA0B,EAAE,oDA2B/F;AAED;;GAEG;AACH,wBAAgB,qCAAqC,CACnD,kBAAkB,CAAC,EAAE,0BAA0B,EAAE,oDAsBlD;AAED;;GAEG;AACH,wBAAgB,kCAAkC,CAChD,kBAAkB,CAAC,EAAE,0BAA0B,EAAE,oDAsBlD;AAED;;GAEG;AACH,qBAAa,uBAAuB;IAElC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAe3C;IAEF;;OAEG;IACH,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IAQlC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,mBAAmB;CAWvF"}
@@ -0,0 +1,119 @@
1
+ import { z } from 'zod';
2
+ import { getLogger } from '../logger.js';
3
+ import { jsonSchemaToZod } from './data-component-schema.js';
4
+ const logger = getLogger('ArtifactComponentSchema');
5
+ /**
6
+ * Converts artifact component configurations to Zod schema for structured generation
7
+ */
8
+ export function createArtifactComponentsSchema(artifactComponents) {
9
+ // Convert artifact component configs to a union schema
10
+ const componentSchemas = artifactComponents?.map((component) => {
11
+ // Convert the JSON Schema props to Zod - handle both summaryProps and fullProps
12
+ const summaryPropsSchema = jsonSchemaToZod(component.summaryProps);
13
+ const fullPropsSchema = jsonSchemaToZod(component.fullProps);
14
+ // Return schema with both summary and full props
15
+ return z
16
+ .object({
17
+ id: z.string().describe(component.id),
18
+ name: z.literal(component.name).describe(component.name),
19
+ summaryProps: summaryPropsSchema,
20
+ fullProps: fullPropsSchema,
21
+ })
22
+ .describe(`${component.name}: ${component.description}`);
23
+ }) || [];
24
+ // Return union of all component schemas - z.union requires at least 2 schemas
25
+ if (componentSchemas.length === 0) {
26
+ return z.object({}); // Empty object for no components
27
+ }
28
+ if (componentSchemas.length === 1) {
29
+ return componentSchemas[0]; // Single schema doesn't need union
30
+ }
31
+ return z.union(componentSchemas); // Safe union with 2+ schemas
32
+ }
33
+ /**
34
+ * Create schema for artifact component summary props only (for quick display)
35
+ */
36
+ export function createArtifactComponentsSummarySchema(artifactComponents) {
37
+ const componentSchemas = artifactComponents?.map((component) => {
38
+ const summaryPropsSchema = jsonSchemaToZod(component.summaryProps);
39
+ return z
40
+ .object({
41
+ id: z.string().describe(component.id),
42
+ name: z.literal(component.name).describe(component.name),
43
+ summaryProps: summaryPropsSchema,
44
+ })
45
+ .describe(`${component.name} Summary: ${component.description}`);
46
+ }) || [];
47
+ if (componentSchemas.length === 0) {
48
+ return z.object({});
49
+ }
50
+ if (componentSchemas.length === 1) {
51
+ return componentSchemas[0];
52
+ }
53
+ return z.union(componentSchemas);
54
+ }
55
+ /**
56
+ * Create schema for artifact component full props only (for detailed display)
57
+ */
58
+ export function createArtifactComponentsFullSchema(artifactComponents) {
59
+ const componentSchemas = artifactComponents?.map((component) => {
60
+ const fullPropsSchema = jsonSchemaToZod(component.fullProps);
61
+ return z
62
+ .object({
63
+ id: z.string().describe(component.id),
64
+ name: z.literal(component.name).describe(component.name),
65
+ fullProps: fullPropsSchema,
66
+ })
67
+ .describe(`${component.name} Full: ${component.description}`);
68
+ }) || [];
69
+ if (componentSchemas.length === 0) {
70
+ return z.object({});
71
+ }
72
+ if (componentSchemas.length === 1) {
73
+ return componentSchemas[0];
74
+ }
75
+ return z.union(componentSchemas);
76
+ }
77
+ /**
78
+ * Standard artifact reference component schema for tool responses
79
+ */
80
+ export class ArtifactReferenceSchema {
81
+ // Standard artifact props schema - single source of truth
82
+ static ARTIFACT_PROPS_SCHEMA = {
83
+ type: 'object',
84
+ properties: {
85
+ artifact_id: {
86
+ type: 'string',
87
+ description: 'The EXACT artifact_id from save_tool_result tool output. NEVER invent or make up IDs.',
88
+ },
89
+ task_id: {
90
+ type: 'string',
91
+ description: 'The EXACT task_id from save_tool_result tool output. NEVER invent or make up IDs.',
92
+ },
93
+ },
94
+ required: ['artifact_id', 'task_id'],
95
+ };
96
+ /**
97
+ * Get the standard Zod schema for artifact reference components
98
+ */
99
+ static getSchema() {
100
+ return z.object({
101
+ id: z.string(),
102
+ name: z.literal('Artifact'),
103
+ props: jsonSchemaToZod(this.ARTIFACT_PROPS_SCHEMA),
104
+ });
105
+ }
106
+ /**
107
+ * Get complete DataComponent by adding missing fields to base definition
108
+ */
109
+ static getDataComponent(tenantId, projectId = '') {
110
+ return {
111
+ id: 'The EXACT artifact_id from save_tool_result tool output. NEVER invent or make up IDs.',
112
+ tenantId: tenantId,
113
+ projectId: projectId,
114
+ name: 'Artifact',
115
+ description: 'Reference to saved content from tool results that grounds information in verifiable sources.',
116
+ props: this.ARTIFACT_PROPS_SCHEMA,
117
+ };
118
+ }
119
+ }
@@ -0,0 +1,71 @@
1
+ export interface StreamPart {
2
+ kind: 'text' | 'data';
3
+ text?: string;
4
+ data?: any;
5
+ }
6
+ export interface ArtifactData {
7
+ artifactId: string;
8
+ taskId: string;
9
+ name: string;
10
+ description: string;
11
+ artifactType?: string;
12
+ artifactSummary: any;
13
+ }
14
+ /**
15
+ * Unified artifact parser that handles all artifact-related parsing and formatting
16
+ * Used by both ResponseFormatter and IncrementalStreamParser to eliminate redundancy
17
+ */
18
+ export declare class ArtifactParser {
19
+ private tenantId;
20
+ private static readonly ARTIFACT_REGEX;
21
+ private static readonly ARTIFACT_CHECK_REGEX;
22
+ private static readonly INCOMPLETE_ARTIFACT_REGEX;
23
+ constructor(tenantId: string);
24
+ /**
25
+ * Check if text contains complete artifact markers
26
+ */
27
+ hasArtifactMarkers(text: string): boolean;
28
+ /**
29
+ * Check if text has incomplete artifact marker (for streaming)
30
+ * More robust detection that handles streaming fragments
31
+ */
32
+ hasIncompleteArtifact(text: string): boolean;
33
+ /**
34
+ * Find safe text boundary before incomplete artifacts (for streaming)
35
+ * Enhanced to handle streaming chunks that split in the middle of artifacts
36
+ */
37
+ findSafeTextBoundary(text: string): number;
38
+ /**
39
+ * Get all artifacts for a context (with caching opportunity)
40
+ */
41
+ getContextArtifacts(contextId: string): Promise<Map<string, any>>;
42
+ /**
43
+ * Convert raw artifact to standardized data format
44
+ */
45
+ private formatArtifactData;
46
+ /**
47
+ * Parse text with artifact markers into parts array
48
+ * Can work with or without pre-fetched artifact map
49
+ */
50
+ parseText(text: string, artifactMap?: Map<string, any>): Promise<StreamPart[]>;
51
+ /**
52
+ * Process object/dataComponents for artifact components
53
+ */
54
+ parseObject(obj: any, artifactMap?: Map<string, any>): Promise<StreamPart[]>;
55
+ /**
56
+ * Check if object is an artifact component
57
+ */
58
+ private isArtifactComponent;
59
+ /**
60
+ * Get artifact data from map or fetch directly
61
+ */
62
+ private getArtifactData;
63
+ /**
64
+ * Parse partial JSON buffer (for streaming)
65
+ */
66
+ parsePartialJSON(buffer: string): {
67
+ complete: any[];
68
+ remaining: string;
69
+ };
70
+ }
71
+ //# sourceMappingURL=artifact-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifact-parser.d.ts","sourceRoot":"","sources":["../../src/utils/artifact-parser.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,GAAG,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,cAAc;IAWb,OAAO,CAAC,QAAQ;IAT5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CACsB;IAC5D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CACmB;IAG/D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAAyB,CACQ;gBAErC,QAAQ,EAAE,MAAM;IAEpC;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIzC;;;OAGG;IACH,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAS5C;;;OAGG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAoC1C;;OAEG;IACG,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAqCvE;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAW1B;;;OAGG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IA2CpF;;OAEG;IACG,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAoClF;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;YACW,eAAe;IAwC7B;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;CA2BzE"}