@agnt5/sdk 0.2.1

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 (126) hide show
  1. package/README.md +183 -0
  2. package/dist/__tests__/integration/helpers.d.ts +41 -0
  3. package/dist/__tests__/integration/helpers.d.ts.map +1 -0
  4. package/dist/__tests__/integration/helpers.js +78 -0
  5. package/dist/__tests__/integration/helpers.js.map +1 -0
  6. package/dist/agent.d.ts +260 -0
  7. package/dist/agent.d.ts.map +1 -0
  8. package/dist/agent.js +493 -0
  9. package/dist/agent.js.map +1 -0
  10. package/dist/async-context.d.ts +57 -0
  11. package/dist/async-context.d.ts.map +1 -0
  12. package/dist/async-context.js +52 -0
  13. package/dist/async-context.js.map +1 -0
  14. package/dist/batch.d.ts +116 -0
  15. package/dist/batch.d.ts.map +1 -0
  16. package/dist/batch.js +98 -0
  17. package/dist/batch.js.map +1 -0
  18. package/dist/chat.d.ts +137 -0
  19. package/dist/chat.d.ts.map +1 -0
  20. package/dist/chat.js +278 -0
  21. package/dist/chat.js.map +1 -0
  22. package/dist/client.d.ts +394 -0
  23. package/dist/client.d.ts.map +1 -0
  24. package/dist/client.js +757 -0
  25. package/dist/client.js.map +1 -0
  26. package/dist/context.d.ts +47 -0
  27. package/dist/context.d.ts.map +1 -0
  28. package/dist/context.js +244 -0
  29. package/dist/context.js.map +1 -0
  30. package/dist/errors.d.ts +148 -0
  31. package/dist/errors.d.ts.map +1 -0
  32. package/dist/errors.js +201 -0
  33. package/dist/errors.js.map +1 -0
  34. package/dist/eval.d.ts +242 -0
  35. package/dist/eval.d.ts.map +1 -0
  36. package/dist/eval.js +452 -0
  37. package/dist/eval.js.map +1 -0
  38. package/dist/event-emitter.d.ts +28 -0
  39. package/dist/event-emitter.d.ts.map +1 -0
  40. package/dist/event-emitter.js +79 -0
  41. package/dist/event-emitter.js.map +1 -0
  42. package/dist/events.d.ts +285 -0
  43. package/dist/events.d.ts.map +1 -0
  44. package/dist/events.js +256 -0
  45. package/dist/events.js.map +1 -0
  46. package/dist/function.d.ts +61 -0
  47. package/dist/function.d.ts.map +1 -0
  48. package/dist/function.js +78 -0
  49. package/dist/function.js.map +1 -0
  50. package/dist/index.d.ts +67 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +80 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/lm.d.ts +301 -0
  55. package/dist/lm.d.ts.map +1 -0
  56. package/dist/lm.js +283 -0
  57. package/dist/lm.js.map +1 -0
  58. package/dist/logging.d.ts +68 -0
  59. package/dist/logging.d.ts.map +1 -0
  60. package/dist/logging.js +165 -0
  61. package/dist/logging.js.map +1 -0
  62. package/dist/mcp-server.d.ts +98 -0
  63. package/dist/mcp-server.d.ts.map +1 -0
  64. package/dist/mcp-server.js +307 -0
  65. package/dist/mcp-server.js.map +1 -0
  66. package/dist/mcp.d.ts +73 -0
  67. package/dist/mcp.d.ts.map +1 -0
  68. package/dist/mcp.js +224 -0
  69. package/dist/mcp.js.map +1 -0
  70. package/dist/memory.d.ts +234 -0
  71. package/dist/memory.d.ts.map +1 -0
  72. package/dist/memory.js +609 -0
  73. package/dist/memory.js.map +1 -0
  74. package/dist/platform-adapters.d.ts +121 -0
  75. package/dist/platform-adapters.d.ts.map +1 -0
  76. package/dist/platform-adapters.js +174 -0
  77. package/dist/platform-adapters.js.map +1 -0
  78. package/dist/platform-context.d.ts +55 -0
  79. package/dist/platform-context.d.ts.map +1 -0
  80. package/dist/platform-context.js +196 -0
  81. package/dist/platform-context.js.map +1 -0
  82. package/dist/retry-utils.d.ts +169 -0
  83. package/dist/retry-utils.d.ts.map +1 -0
  84. package/dist/retry-utils.js +304 -0
  85. package/dist/retry-utils.js.map +1 -0
  86. package/dist/sandbox.d.ts +103 -0
  87. package/dist/sandbox.d.ts.map +1 -0
  88. package/dist/sandbox.js +168 -0
  89. package/dist/sandbox.js.map +1 -0
  90. package/dist/schema-utils.d.ts +250 -0
  91. package/dist/schema-utils.d.ts.map +1 -0
  92. package/dist/schema-utils.js +444 -0
  93. package/dist/schema-utils.js.map +1 -0
  94. package/dist/scorer.d.ts +130 -0
  95. package/dist/scorer.d.ts.map +1 -0
  96. package/dist/scorer.js +211 -0
  97. package/dist/scorer.js.map +1 -0
  98. package/dist/state.d.ts +92 -0
  99. package/dist/state.d.ts.map +1 -0
  100. package/dist/state.js +151 -0
  101. package/dist/state.js.map +1 -0
  102. package/dist/tool.d.ts +120 -0
  103. package/dist/tool.d.ts.map +1 -0
  104. package/dist/tool.js +215 -0
  105. package/dist/tool.js.map +1 -0
  106. package/dist/tracing.d.ts +82 -0
  107. package/dist/tracing.d.ts.map +1 -0
  108. package/dist/tracing.js +206 -0
  109. package/dist/tracing.js.map +1 -0
  110. package/dist/types.d.ts +139 -0
  111. package/dist/types.d.ts.map +1 -0
  112. package/dist/types.js +2 -0
  113. package/dist/types.js.map +1 -0
  114. package/dist/worker.d.ts +111 -0
  115. package/dist/worker.d.ts.map +1 -0
  116. package/dist/worker.js +944 -0
  117. package/dist/worker.js.map +1 -0
  118. package/dist/workflow-utils.d.ts +257 -0
  119. package/dist/workflow-utils.d.ts.map +1 -0
  120. package/dist/workflow-utils.js +370 -0
  121. package/dist/workflow-utils.js.map +1 -0
  122. package/dist/workflow.d.ts +78 -0
  123. package/dist/workflow.d.ts.map +1 -0
  124. package/dist/workflow.js +138 -0
  125. package/dist/workflow.js.map +1 -0
  126. package/package.json +86 -0
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Function builder for creating durable functions
3
+ * @template TInput - Input parameter types
4
+ * @template TOutput - Return type
5
+ */
6
+ export class FunctionBuilder {
7
+ constructor(name) {
8
+ this.name = name;
9
+ this.config = {};
10
+ }
11
+ /**
12
+ * Configure retry policy
13
+ */
14
+ retry(policy) {
15
+ this.config.retries = policy;
16
+ return this;
17
+ }
18
+ /**
19
+ * Configure backoff strategy
20
+ */
21
+ backoff(policy) {
22
+ this.config.backoff = policy;
23
+ return this;
24
+ }
25
+ /**
26
+ * Configure timeout in milliseconds
27
+ */
28
+ timeout(ms) {
29
+ this.config.timeout_ms = ms;
30
+ return this;
31
+ }
32
+ /**
33
+ * Define the function handler
34
+ */
35
+ run(handler) {
36
+ // Register function with global registry
37
+ FunctionRegistry.register(this.name, {
38
+ handler,
39
+ options: this.config,
40
+ });
41
+ return handler;
42
+ }
43
+ }
44
+ /**
45
+ * Create a new function builder
46
+ * @param name - Unique function name
47
+ * @returns Function builder instance
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const greet = fn('greet').run(async (ctx, name: string) => {
52
+ * return `Hello, ${name}!`;
53
+ * });
54
+ * ```
55
+ */
56
+ export function fn(name) {
57
+ return new FunctionBuilder(name);
58
+ }
59
+ /**
60
+ * Internal function registry
61
+ */
62
+ class FunctionRegistry {
63
+ static register(name, config) {
64
+ this.functions.set(name, config);
65
+ }
66
+ static get(name) {
67
+ return this.functions.get(name);
68
+ }
69
+ static getAll() {
70
+ return Array.from(this.functions.entries());
71
+ }
72
+ static clear() {
73
+ this.functions.clear();
74
+ }
75
+ }
76
+ FunctionRegistry.functions = new Map();
77
+ export { FunctionRegistry };
78
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAG1B,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAFxB,WAAM,GAAoB,EAAE,CAAC;IAEF,CAAC;IAEpC;;OAEG;IACH,KAAK,CAAC,MAAmB;QACvB,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,MAAqB;QAC3B,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,EAAU;QAChB,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,OAAyC;QAC3C,yCAAyC;QACzC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE;YACnC,OAAO;YACP,OAAO,EAAE,IAAI,CAAC,MAAM;SACrB,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,EAAE,CAChB,IAAY;IAEZ,OAAO,IAAI,eAAe,CAAkB,IAAI,CAAC,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,MAAM,gBAAgB;IAMpB,MAAM,CAAC,QAAQ,CACb,IAAY,EACZ,MAA8D;QAE9D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,MAAM;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,KAAK;QACV,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;;AAtBc,0BAAS,GAAG,IAAI,GAAG,EAG/B,CAAC;AAsBN,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * AGNT5 TypeScript SDK
3
+ *
4
+ * Durable AI workflows and agents for TypeScript.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export { fn, FunctionBuilder } from './function.js';
9
+ export { Worker, getRuntime, checkPlatformConnectivity } from './worker.js';
10
+ export type { PlatformWorkerOptions } from './worker.js';
11
+ export { ContextImpl } from './context.js';
12
+ export { PlatformContext } from './platform-context.js';
13
+ export { Client, RunResponse, WorkflowProxy, SessionProxy } from './client.js';
14
+ export type { ClientOptions, RunOptions, RunStatus, RunErrorDetail, SubmitResponse, ReceivedEvent, EventRecord, EventsResponse } from './client.js';
15
+ export { BatchResult, BatchStatusResult } from './batch.js';
16
+ export type { BatchConfig, BatchItemInput, BatchItemResult, BatchItemError, BatchStats, BatchStatus, CancelBatchResult } from './batch.js';
17
+ export { AGNT5Error, ConfigurationError, ExecutionError, RetryError, StateError, CheckpointError, RunError, WaitingForUserInputError, ConnectionError, TimeoutError, ValidationError, AuthorizationError, isAGNT5Error, isWaitingForUserInput, getErrorMessage, createErrorFromResponse, } from './errors.js';
18
+ export type { HITLInputType, HITLOption } from './errors.js';
19
+ export { parseRetryPolicy, parseBackoffPolicy, calculateBackoffDelay, executeWithRetry, createRetryWrapper, executeWithRetryAndTimeout, DEFAULT_RETRY_POLICY, DEFAULT_BACKOFF_POLICY, } from './retry-utils.js';
20
+ export type { RetryPredicate, ExecuteWithRetryOptions } from './retry-utils.js';
21
+ export { detectFormatType, isZodSchema, isTypeBoxSchema, isJsonSchema, zodToJsonSchema, typeBoxToJsonSchema, typeToSchema, createObjectSchema, createArraySchema, createEnumSchema, createUnionSchema, makeOptional, mergeSchemas, validateSchema, extractFunctionDescription, } from './schema-utils.js';
22
+ export type { SchemaFormat, SchemaConversionOptions } from './schema-utils.js';
23
+ export { Tool, ToolRegistry, tool, AskUserTool, RequestApprovalTool } from './tool.js';
24
+ export { MCPServer, MCPServerError, Prompt, Resource } from './mcp-server.js';
25
+ export { workflow, WorkflowRegistry } from './workflow.js';
26
+ export type { WorkflowConfig, WorkflowOptions } from './workflow.js';
27
+ export { parallel, gather, executeChildWorkflow, parallelWorkflows, gatherWorkflows, fanOut, batchExecute, race, withTimeout, saga, retryWorkflow, sleep, } from './workflow-utils.js';
28
+ export { ChatBot } from './chat.js';
29
+ export type { SlackConfig, DiscordConfig, TeamsConfig, TelegramConfig, PlatformConfig, ChatEvent, ChatMessage, ChatUser, ChatEventHandler } from './chat.js';
30
+ export { Agent, AgentRegistry, MessageRole, Message, Handoff, handoff } from './agent.js';
31
+ export type { Message as IMessage, ToolCall, TokenUsage, GenerationConfig, GenerateRequest, GenerateResponse, LanguageModel, AgentResult, AgentOptions } from './agent.js';
32
+ export type { AgentEvent, BaseEvent, AgentStarted, AgentCompleted, AgentFailed, AgentIterationStarted, AgentIterationCompleted, ToolCallStarted, ToolCallCompleted, ToolCallFailed, RunStarted, RunCompleted, RunFailed, FunctionStarted, FunctionCompleted, FunctionFailed, WorkflowStarted, WorkflowCompleted, WorkflowFailed, ToolStarted, ToolCompleted, ToolFailed, OutputStart, OutputDelta, OutputStop, LifecycleEvent, PlatformEvent, } from './events.js';
33
+ export { agentStarted, agentCompleted, agentFailed, iterationStarted, iterationCompleted, toolCallStarted, toolCallCompleted, toolCallFailed, generateCid, runStarted, runCompleted, runFailed, functionStarted, functionCompleted, functionFailed, workflowStarted, workflowCompleted, workflowFailed, toolStarted, toolCompleted, toolFailed, isCheckpointEvent, isSseOnlyEvent, toEventPayload, } from './events.js';
34
+ export { EventEmitter } from './event-emitter.js';
35
+ export { LM, systemMessage, userMessage, assistantMessage, createTool, parseToolArguments, jsonSchemaFormat } from './lm.js';
36
+ export type { Message as LMMessage, MessageRole as LMMessageRole, ToolDefinition as LMToolDefinition, ToolCall as LMToolCall, TokenUsage as LMTokenUsage, GenerateResponse as LMGenerateResponse, StreamChunk, ReasoningEffort, Modality, BuiltInTool, GenerationConfig as LMGenerationConfig, ResponseFormatOption, ToolChoiceOption, GenerateRequest as LMGenerateRequest, OpenAIConfig, AnthropicConfig, AzureOpenAIConfig, BedrockConfig, GroqConfig, OpenRouterConfig, DeepSeekConfig, GoogleConfig, MistralConfig, OllamaConfig, XaiConfig, HuggingFaceConfig, OpenAiChatConfig, } from './lm.js';
37
+ export { runWithContext, getCurrentContext, requireContext } from './async-context.js';
38
+ export type { PropagatedContext } from './async-context.js';
39
+ export { StateManager, SessionContext, UserContext, ScopedState, MemoryStateAdapter, } from './state.js';
40
+ export type { StateAdapter } from './state.js';
41
+ export { MCPClient, MCPError } from './mcp.js';
42
+ export type { McpTool, McpToolWithServer, ToolContent, CallToolResult, StdioConfig, SseConfig, TransportType, ServerConfig, ServerCapabilities, ServerInfo, } from './mcp.js';
43
+ export { Span, withSpan, spanContext, span, getCurrentSpanInfo } from './tracing.js';
44
+ export type { SpanInfo } from './tracing.js';
45
+ export { ScorerResult, ScorerRegistry, scorer, isScorer, getScorerConfig, runScorer, exactMatch, contains, jsonValid, regexMatch, levenshtein, getRequestConfig, getTraceEvents, getTotalTokens, } from './scorer.js';
46
+ export type { ScorerRequest, ScorerResultSummary, ScorerContext, ScorerHandler, ScorerConfig, TraceEvent, } from './scorer.js';
47
+ export { EvalContext, EvalResponse, BatchEvalItemResult, BatchEvalResult, LLMJudge, TraceAssertion, traceScorer, normalizeBatchEvalItems, normalizeScorerSpecs, } from './eval.js';
48
+ export type { AssertionResult, TraceScorerResult, BatchEvalItem, BatchEvalStats, LLMJudgeConfig, } from './eval.js';
49
+ export { MemoryScope, ConversationMemory, SemanticMemory, InMemorySemanticAdapter, GraphMemory, } from './memory.js';
50
+ export type { MemoryScopeType, MemoryMessage, MemoryMetadata, MemoryResult, SemanticMemoryAdapter, GraphNode, GraphRelationship, GraphTraversalResult, } from './memory.js';
51
+ export { ContextLogger, getLogger, setLogLevel, getLogLevel } from './logging.js';
52
+ export type { LogLevel } from './logging.js';
53
+ export { StubJobQueueAdapter, StubPlatformStateAdapter, StubPlatformSpanAdapter, NapiPlatformSpanAdapter, startJobQueuePolling, } from './platform-adapters.js';
54
+ export type { JobAssignment, JobCompletionResult, JobQueueAdapter, SpanAttributes, PlatformSpanAdapter, PlatformSpanHandle, JobQueueConfig, } from './platform-adapters.js';
55
+ export { Sandbox } from './sandbox.js';
56
+ export type { SandboxOptions, ExecuteCodeResult, WriteFileResult, ReadFileResult, FileInfo, ListFilesResult, HealthResult as SandboxHealthResult, SandboxCapabilities, } from './sandbox.js';
57
+ export type { Context, Logger, FunctionHandler, FunctionOptions, RetryPolicy, BackoffPolicy, WorkerOptions, JSONSchema, ToolHandler, ToolSchema, ToolOptions, WorkflowHandler } from './types.js';
58
+ /**
59
+ * SDK version
60
+ */
61
+ export declare const VERSION = "0.1.0";
62
+ /**
63
+ * Get binding type being used
64
+ * @returns 'napi' for native bindings, 'wasm' for WebAssembly
65
+ */
66
+ export declare function getBindingType(): 'napi' | 'wasm' | 'unknown';
67
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,EAAE,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC5E,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/E,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGpJ,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC5D,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG3I,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,UAAU,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EACR,eAAe,EACf,YAAY,IAAI,mBAAmB,EACnC,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,OAAO,EACP,MAAM,EACN,eAAe,EACf,eAAe,EACf,WAAW,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,MAAM,GAAG,SAAS,CAK5D"}
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * AGNT5 TypeScript SDK
3
+ *
4
+ * Durable AI workflows and agents for TypeScript.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ // Core exports
9
+ export { fn, FunctionBuilder } from './function.js';
10
+ export { Worker, getRuntime, checkPlatformConnectivity } from './worker.js';
11
+ export { ContextImpl } from './context.js';
12
+ export { PlatformContext } from './platform-context.js';
13
+ // Client exports
14
+ export { Client, RunResponse, WorkflowProxy, SessionProxy } from './client.js';
15
+ // Batch exports
16
+ export { BatchResult, BatchStatusResult } from './batch.js';
17
+ // Error exports
18
+ export { AGNT5Error, ConfigurationError, ExecutionError, RetryError, StateError, CheckpointError, RunError, WaitingForUserInputError, ConnectionError, TimeoutError, ValidationError, AuthorizationError, isAGNT5Error, isWaitingForUserInput, getErrorMessage, createErrorFromResponse, } from './errors.js';
19
+ // Retry utilities exports
20
+ export { parseRetryPolicy, parseBackoffPolicy, calculateBackoffDelay, executeWithRetry, createRetryWrapper, executeWithRetryAndTimeout, DEFAULT_RETRY_POLICY, DEFAULT_BACKOFF_POLICY, } from './retry-utils.js';
21
+ // Schema utilities exports
22
+ export { detectFormatType, isZodSchema, isTypeBoxSchema, isJsonSchema, zodToJsonSchema, typeBoxToJsonSchema, typeToSchema, createObjectSchema, createArraySchema, createEnumSchema, createUnionSchema, makeOptional, mergeSchemas, validateSchema, extractFunctionDescription, } from './schema-utils.js';
23
+ // Tool exports
24
+ export { Tool, ToolRegistry, tool, AskUserTool, RequestApprovalTool } from './tool.js';
25
+ export { MCPServer, MCPServerError, Prompt, Resource } from './mcp-server.js';
26
+ // Workflow exports
27
+ export { workflow, WorkflowRegistry } from './workflow.js';
28
+ export { parallel, gather, executeChildWorkflow, parallelWorkflows, gatherWorkflows, fanOut, batchExecute, race, withTimeout, saga, retryWorkflow, sleep, } from './workflow-utils.js';
29
+ // Chat SDK exports
30
+ export { ChatBot } from './chat.js';
31
+ // Agent exports
32
+ export { Agent, AgentRegistry, MessageRole, Message, Handoff, handoff } from './agent.js';
33
+ export { agentStarted, agentCompleted, agentFailed, iterationStarted, iterationCompleted, toolCallStarted, toolCallCompleted, toolCallFailed,
34
+ // Lifecycle factories
35
+ generateCid, runStarted, runCompleted, runFailed, functionStarted, functionCompleted, functionFailed, workflowStarted, workflowCompleted, workflowFailed, toolStarted, toolCompleted, toolFailed,
36
+ // Classification
37
+ isCheckpointEvent, isSseOnlyEvent, toEventPayload, } from './events.js';
38
+ // EventEmitter export
39
+ export { EventEmitter } from './event-emitter.js';
40
+ // Language Model exports
41
+ export { LM, systemMessage, userMessage, assistantMessage, createTool, parseToolArguments, jsonSchemaFormat } from './lm.js';
42
+ // Context propagation exports
43
+ export { runWithContext, getCurrentContext, requireContext } from './async-context.js';
44
+ // State management exports
45
+ export { StateManager, SessionContext, UserContext, ScopedState, MemoryStateAdapter, } from './state.js';
46
+ // MCP exports
47
+ export { MCPClient, MCPError } from './mcp.js';
48
+ // Tracing exports
49
+ export { Span, withSpan, spanContext, span, getCurrentSpanInfo } from './tracing.js';
50
+ // Scorer exports
51
+ export { ScorerResult, ScorerRegistry, scorer, isScorer, getScorerConfig, runScorer, exactMatch, contains, jsonValid, regexMatch, levenshtein, getRequestConfig, getTraceEvents, getTotalTokens, } from './scorer.js';
52
+ // Evaluation exports
53
+ export { EvalContext, EvalResponse, BatchEvalItemResult, BatchEvalResult, LLMJudge, TraceAssertion, traceScorer, normalizeBatchEvalItems, normalizeScorerSpecs, } from './eval.js';
54
+ // Memory exports
55
+ export { MemoryScope, ConversationMemory, SemanticMemory, InMemorySemanticAdapter, GraphMemory, } from './memory.js';
56
+ // Logging exports
57
+ export { ContextLogger, getLogger, setLogLevel, getLogLevel } from './logging.js';
58
+ // Platform adapter exports
59
+ export { StubJobQueueAdapter, StubPlatformStateAdapter, StubPlatformSpanAdapter, NapiPlatformSpanAdapter, startJobQueuePolling, } from './platform-adapters.js';
60
+ // Sandbox exports
61
+ export { Sandbox } from './sandbox.js';
62
+ /**
63
+ * SDK version
64
+ */
65
+ export const VERSION = '0.1.0';
66
+ /**
67
+ * Get binding type being used
68
+ * @returns 'napi' for native bindings, 'wasm' for WebAssembly
69
+ */
70
+ export function getBindingType() {
71
+ const runtime = getRuntime();
72
+ if (runtime === 'edge')
73
+ return 'wasm';
74
+ if (runtime === 'node' || runtime === 'bun' || runtime === 'deno')
75
+ return 'napi';
76
+ return 'unknown';
77
+ }
78
+ // Re-export getRuntime for convenience
79
+ import { getRuntime } from './worker.js';
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAe;AACf,OAAO,EAAE,EAAE,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,iBAAiB;AACjB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG/E,gBAAgB;AAChB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,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,aAAa,CAAC;AAUrB,qBAAqB;AACrB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,QAAQ,EACR,cAAc,EACd,WAAW,EACX,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AASnB,iBAAiB;AACjB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,uBAAuB,EACvB,WAAW,GACZ,MAAM,aAAa,CAAC;AAYrB,kBAAkB;AAClB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGlF,2BAA2B;AAC3B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAWhC,kBAAkB;AAClB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA4BvC;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACtC,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACjF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
package/dist/lm.d.ts ADDED
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Language Model (LLM) integration for AGNT5 TypeScript SDK
3
+ *
4
+ * Provides unified interface to multiple LLM providers:
5
+ * - OpenAI (GPT-4, o1, o3)
6
+ * - Anthropic (Claude)
7
+ * - Azure OpenAI
8
+ * - AWS Bedrock
9
+ * - Groq
10
+ * - OpenRouter
11
+ * - DeepSeek
12
+ * - Google (Gemini)
13
+ * - Mistral
14
+ * - Ollama (local LLM)
15
+ * - xAI (Grok)
16
+ * - HuggingFace
17
+ * - OpenAI Chat (custom OpenAI-compatible APIs)
18
+ */
19
+ import type { JSONSchema } from './types.js';
20
+ export type MessageRole = 'system' | 'user' | 'assistant';
21
+ export interface Message {
22
+ role: MessageRole;
23
+ content: string;
24
+ }
25
+ export interface ToolDefinition {
26
+ name: string;
27
+ description?: string;
28
+ parameters?: string;
29
+ strict?: boolean;
30
+ }
31
+ export interface ToolCall {
32
+ id: string;
33
+ name: string;
34
+ arguments: string;
35
+ }
36
+ export interface TokenUsage {
37
+ promptTokens?: number;
38
+ completionTokens?: number;
39
+ totalTokens?: number;
40
+ }
41
+ export interface GenerateResponse {
42
+ id: string;
43
+ model: string;
44
+ created?: number;
45
+ text: string;
46
+ usage?: TokenUsage;
47
+ finishReason?: string;
48
+ toolCalls?: ToolCall[];
49
+ raw?: string;
50
+ }
51
+ export interface StreamChunk {
52
+ chunkType: 'delta' | 'completed';
53
+ content?: string;
54
+ response?: GenerateResponse;
55
+ }
56
+ export type ReasoningEffort = 'minimal' | 'medium' | 'high';
57
+ export type Modality = 'text' | 'audio' | 'image';
58
+ export type BuiltInTool = 'web_search' | 'code_interpreter' | 'file_search';
59
+ export interface GenerationConfig {
60
+ temperature?: number;
61
+ topP?: number;
62
+ maxOutputTokens?: number;
63
+ responseFormat?: ResponseFormatOption;
64
+ reasoningEffort?: ReasoningEffort;
65
+ modalities?: Modality[];
66
+ builtInTools?: BuiltInTool[];
67
+ }
68
+ export interface ResponseFormatOption {
69
+ formatType: 'text' | 'json' | 'json_schema';
70
+ schemaName?: string;
71
+ schema?: string;
72
+ strict?: boolean;
73
+ }
74
+ export interface ToolChoiceOption {
75
+ choiceType: 'auto' | 'none' | 'tool';
76
+ toolName?: string;
77
+ }
78
+ export interface GenerateRequest {
79
+ model: string;
80
+ systemPrompt?: string;
81
+ messages: Message[];
82
+ tools?: ToolDefinition[];
83
+ toolChoice?: ToolChoiceOption;
84
+ userId?: string;
85
+ config?: GenerationConfig;
86
+ }
87
+ export interface OpenAIConfig {
88
+ apiKey?: string;
89
+ organizationId?: string;
90
+ baseUrl?: string;
91
+ }
92
+ export interface AnthropicConfig {
93
+ apiKey?: string;
94
+ baseUrl?: string;
95
+ }
96
+ export interface AzureOpenAIConfig {
97
+ apiKey?: string;
98
+ endpoint: string;
99
+ apiVersion?: string;
100
+ }
101
+ export interface BedrockConfig {
102
+ region?: string;
103
+ accessKeyId?: string;
104
+ secretAccessKey?: string;
105
+ sessionToken?: string;
106
+ }
107
+ export interface GroqConfig {
108
+ apiKey?: string;
109
+ baseUrl?: string;
110
+ }
111
+ export interface OpenRouterConfig {
112
+ apiKey?: string;
113
+ baseUrl?: string;
114
+ }
115
+ export interface DeepSeekConfig {
116
+ apiKey?: string;
117
+ baseUrl?: string;
118
+ }
119
+ export interface GoogleConfig {
120
+ apiKey?: string;
121
+ baseUrl?: string;
122
+ }
123
+ export interface MistralConfig {
124
+ apiKey?: string;
125
+ baseUrl?: string;
126
+ }
127
+ export interface OllamaConfig {
128
+ baseUrl?: string;
129
+ apiKey?: string;
130
+ }
131
+ export interface XaiConfig {
132
+ apiKey?: string;
133
+ baseUrl?: string;
134
+ }
135
+ export interface HuggingFaceConfig {
136
+ apiKey?: string;
137
+ baseUrl?: string;
138
+ }
139
+ export interface OpenAiChatConfig {
140
+ apiKey?: string;
141
+ baseUrl?: string;
142
+ organization?: string;
143
+ }
144
+ export declare class LM {
145
+ private model;
146
+ private constructor();
147
+ /**
148
+ * Create OpenAI provider
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const lm = LM.openai({ apiKey: process.env.OPENAI_API_KEY });
153
+ * const response = await lm.generate({
154
+ * model: 'gpt-4',
155
+ * messages: [{ role: 'user', content: 'Hello!' }]
156
+ * });
157
+ * ```
158
+ */
159
+ static openai(config?: OpenAIConfig): LM;
160
+ /**
161
+ * Create Anthropic (Claude) provider
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const lm = LM.anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
166
+ * const response = await lm.generate({
167
+ * model: 'claude-3-5-sonnet-20241022',
168
+ * messages: [{ role: 'user', content: 'Hello!' }]
169
+ * });
170
+ * ```
171
+ */
172
+ static anthropic(config?: AnthropicConfig): LM;
173
+ /**
174
+ * Create Azure OpenAI provider
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const lm = LM.azure({
179
+ * apiKey: process.env.AZURE_OPENAI_API_KEY,
180
+ * endpoint: 'https://your-resource.openai.azure.com',
181
+ * });
182
+ * ```
183
+ */
184
+ static azure(config: AzureOpenAIConfig): LM;
185
+ /**
186
+ * Create AWS Bedrock provider
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const lm = LM.bedrock({
191
+ * region: 'us-east-1',
192
+ * accessKeyId: process.env.AWS_ACCESS_KEY_ID,
193
+ * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
194
+ * });
195
+ * ```
196
+ */
197
+ static bedrock(config: BedrockConfig): LM;
198
+ /**
199
+ * Create Groq provider (fast inference)
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const lm = LM.groq({ apiKey: process.env.GROQ_API_KEY });
204
+ * const response = await lm.generate({
205
+ * model: 'mixtral-8x7b-32768',
206
+ * messages: [{ role: 'user', content: 'Hello!' }]
207
+ * });
208
+ * ```
209
+ */
210
+ static groq(config?: GroqConfig): LM;
211
+ /**
212
+ * Create OpenRouter provider (model aggregation)
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const lm = LM.openrouter({ apiKey: process.env.OPENROUTER_API_KEY });
217
+ * const response = await lm.generate({
218
+ * model: 'anthropic/claude-3-opus',
219
+ * messages: [{ role: 'user', content: 'Hello!' }]
220
+ * });
221
+ * ```
222
+ */
223
+ static openrouter(config?: OpenRouterConfig): LM;
224
+ /** Create DeepSeek provider */
225
+ static deepseek(config?: DeepSeekConfig): LM;
226
+ /** Create Google (Gemini) provider */
227
+ static google(config?: GoogleConfig): LM;
228
+ /** Create Mistral provider */
229
+ static mistral(config?: MistralConfig): LM;
230
+ /** Create Ollama provider (local LLM) */
231
+ static ollama(config?: OllamaConfig): LM;
232
+ /** Create xAI (Grok) provider */
233
+ static xai(config?: XaiConfig): LM;
234
+ /** Create HuggingFace provider */
235
+ static huggingface(config?: HuggingFaceConfig): LM;
236
+ /** Create OpenAI Chat-compatible provider (for custom OpenAI-compatible APIs) */
237
+ static openaiChat(config?: OpenAiChatConfig): LM;
238
+ /**
239
+ * Generate a completion
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const response = await lm.generate({
244
+ * model: 'gpt-4',
245
+ * messages: [
246
+ * { role: 'system', content: 'You are a helpful assistant.' },
247
+ * { role: 'user', content: 'What is 2+2?' }
248
+ * ],
249
+ * config: {
250
+ * temperature: 0.7,
251
+ * maxOutputTokens: 100
252
+ * }
253
+ * });
254
+ * console.log(response.text);
255
+ * ```
256
+ */
257
+ generate(request: GenerateRequest): Promise<GenerateResponse>;
258
+ /**
259
+ * Stream a completion
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * await lm.stream({
264
+ * model: 'gpt-4',
265
+ * messages: [{ role: 'user', content: 'Tell me a story' }]
266
+ * }, (chunk) => {
267
+ * if (chunk.chunkType === 'delta' && chunk.content) {
268
+ * process.stdout.write(chunk.content);
269
+ * } else if (chunk.chunkType === 'completed' && chunk.response) {
270
+ * console.log('\n\nTokens used:', chunk.response.usage);
271
+ * }
272
+ * });
273
+ * ```
274
+ */
275
+ stream(request: GenerateRequest, callback: (chunk: StreamChunk) => void): Promise<void>;
276
+ }
277
+ /**
278
+ * Create a system message
279
+ */
280
+ export declare function systemMessage(content: string): Message;
281
+ /**
282
+ * Create a user message
283
+ */
284
+ export declare function userMessage(content: string): Message;
285
+ /**
286
+ * Create an assistant message
287
+ */
288
+ export declare function assistantMessage(content: string): Message;
289
+ /**
290
+ * Create a tool definition from a JSON schema
291
+ */
292
+ export declare function createTool(name: string, description: string, parameters: JSONSchema): ToolDefinition;
293
+ /**
294
+ * Parse tool call arguments
295
+ */
296
+ export declare function parseToolArguments<T = any>(toolCall: ToolCall): T;
297
+ /**
298
+ * Create a JSON schema response format
299
+ */
300
+ export declare function jsonSchemaFormat(name: string, schema: JSONSchema, strict?: boolean): ResponseFormatOption;
301
+ //# sourceMappingURL=lm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lm.d.ts","sourceRoot":"","sources":["../src/lm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA0C7C,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE1D,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAA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