@intx/inference 0.1.2 → 0.2.2

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 (97) hide show
  1. package/LICENSE +176 -0
  2. package/dist/actions.d.ts +16 -0
  3. package/dist/actions.js +200 -0
  4. package/dist/adapter.d.ts +38 -0
  5. package/dist/adapter.js +31 -0
  6. package/dist/assembly.d.ts +68 -0
  7. package/dist/assembly.js +132 -0
  8. package/dist/audit-collector.d.ts +10 -0
  9. package/dist/audit-collector.js +139 -0
  10. package/dist/auth.d.ts +24 -0
  11. package/{src/auth.ts → dist/auth.js} +13 -19
  12. package/dist/authz-extension.d.ts +32 -0
  13. package/dist/authz-extension.js +100 -0
  14. package/dist/correlation.d.ts +25 -0
  15. package/dist/correlation.js +32 -0
  16. package/dist/default-director.d.ts +111 -0
  17. package/dist/default-director.js +199 -0
  18. package/dist/director.d.ts +6 -0
  19. package/dist/director.js +56 -0
  20. package/dist/errors.d.ts +18 -0
  21. package/dist/errors.js +83 -0
  22. package/dist/gates.d.ts +27 -0
  23. package/dist/gates.js +80 -0
  24. package/dist/harness.d.ts +147 -0
  25. package/dist/harness.js +1319 -0
  26. package/dist/index.d.ts +37 -0
  27. package/dist/index.js +21 -0
  28. package/dist/manifest.d.ts +31 -0
  29. package/dist/manifest.js +44 -0
  30. package/dist/providers/anthropic.d.ts +33 -0
  31. package/dist/providers/anthropic.js +670 -0
  32. package/dist/providers/google-genai-files.d.ts +48 -0
  33. package/dist/providers/google-genai-files.js +205 -0
  34. package/dist/providers/google-genai.d.ts +3 -0
  35. package/dist/providers/google-genai.js +1196 -0
  36. package/dist/providers/index.d.ts +38 -0
  37. package/dist/providers/index.js +56 -0
  38. package/dist/providers/openai.d.ts +3 -0
  39. package/dist/providers/openai.js +609 -0
  40. package/dist/reactor.d.ts +50 -0
  41. package/dist/reactor.js +920 -0
  42. package/dist/retry-policy.d.ts +31 -0
  43. package/{src/retry-policy.ts → dist/retry-policy.js} +41 -53
  44. package/dist/sse.d.ts +1 -0
  45. package/dist/sse.js +63 -0
  46. package/dist/state.d.ts +23 -0
  47. package/dist/state.js +100 -0
  48. package/dist/tool-name.d.ts +6 -0
  49. package/dist/tool-name.js +110 -0
  50. package/dist/transform.d.ts +11 -0
  51. package/dist/transform.js +117 -0
  52. package/dist/transforms/index.d.ts +2 -0
  53. package/dist/transforms/index.js +1 -0
  54. package/dist/transforms/size-cap.d.ts +12 -0
  55. package/dist/transforms/size-cap.js +80 -0
  56. package/dist/turns.d.ts +21 -0
  57. package/dist/turns.js +135 -0
  58. package/package.json +21 -6
  59. package/src/actions.ts +0 -245
  60. package/src/adapter.ts +0 -57
  61. package/src/assembly.test.ts +0 -728
  62. package/src/assembly.ts +0 -250
  63. package/src/audit-collector.test.ts +0 -332
  64. package/src/audit-collector.ts +0 -172
  65. package/src/auth.test.ts +0 -117
  66. package/src/authz-extension.test.ts +0 -269
  67. package/src/authz-extension.ts +0 -145
  68. package/src/correlation.ts +0 -61
  69. package/src/default-director.test.ts +0 -314
  70. package/src/default-director.ts +0 -344
  71. package/src/director.ts +0 -87
  72. package/src/errors.test.ts +0 -133
  73. package/src/errors.ts +0 -115
  74. package/src/gates.ts +0 -128
  75. package/src/harness.test.ts +0 -655
  76. package/src/harness.ts +0 -1571
  77. package/src/index.ts +0 -76
  78. package/src/providers/anthropic.test.ts +0 -771
  79. package/src/providers/anthropic.ts +0 -810
  80. package/src/providers/google-genai-files.ts +0 -289
  81. package/src/providers/google-genai.ts +0 -1518
  82. package/src/providers/openai.ts +0 -719
  83. package/src/providers/registry.ts +0 -33
  84. package/src/reactor.test.ts +0 -3660
  85. package/src/reactor.ts +0 -1058
  86. package/src/scheduler.test.ts +0 -41
  87. package/src/sse.test.ts +0 -133
  88. package/src/sse.ts +0 -76
  89. package/src/state.ts +0 -135
  90. package/src/transform.test.ts +0 -207
  91. package/src/transform.ts +0 -159
  92. package/src/transforms/index.ts +0 -2
  93. package/src/transforms/size-cap.test.ts +0 -172
  94. package/src/transforms/size-cap.ts +0 -110
  95. package/src/turns.ts +0 -54
  96. package/tsconfig.json +0 -4
  97. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,37 @@
1
+ export { parseSSE } from "./sse.js";
2
+ export { encodeToolName, decodeToolName } from "./tool-name.js";
3
+ export type { ToolNameLimit } from "./tool-name.js";
4
+ export { runInference, createDependencies, createDefaultScheduler, HarnessId, } from "./harness.js";
5
+ export type { Dependencies, InferenceHarnessOptions, Scheduler, } from "./harness.js";
6
+ export type { ProviderAdapter, RequestBuilder, ResponseParser, BuiltRequest, AdapterRegistry, AdapterFactory, } from "./adapter.js";
7
+ export { AdapterManifest, AdapterManifestEntry } from "./manifest.js";
8
+ export { CREDENTIAL_SENTINEL, BEARER_CREDENTIAL_SENTINEL } from "./auth.js";
9
+ export { classifyHTTPError, classifyNetworkError, classifyAbortError, classifyStreamError, classifyProtocolMismatch, ProtocolMismatchError, } from "./errors.js";
10
+ export { transformMessages, createIDNormalizer } from "./transform.js";
11
+ export type { TransformOptions, IDNormalizer } from "./transform.js";
12
+ export { createDefaultRetryPolicy } from "./retry-policy.js";
13
+ export type { RetryPolicy, RetrySituation, RetryDecision, } from "@intx/types/runtime";
14
+ export { uploadGoogleGenAIFile } from "./providers/google-genai-files.js";
15
+ export type { UploadGoogleGenAIFileOpts, UploadGoogleGenAIFileFetch, UploadedGoogleGenAIFile, } from "./providers/google-genai-files.js";
16
+ export { createInboundTurn } from "./turns.js";
17
+ export { createReactor } from "./reactor.js";
18
+ export type { Reactor, ReactorConfig, ReactorEmittedEvent } from "./reactor.js";
19
+ export { validateActions } from "./actions.js";
20
+ export type { ValidationResult } from "./actions.js";
21
+ export { createGateManager } from "./gates.js";
22
+ export type { GateManager, GateRecord, GateSnapshot } from "./gates.js";
23
+ export { createCorrelationRegistry } from "./correlation.js";
24
+ export type { CorrelationRegistry, CorrelationValidator } from "./correlation.js";
25
+ export { createStateManager } from "./state.js";
26
+ export type { ReactorStateManager } from "./state.js";
27
+ export { createCapabilities } from "./director.js";
28
+ export { DefaultDirector, createDefaultDirector } from "./default-director.js";
29
+ export type { DefaultDirectorPolicy } from "./default-director.js";
30
+ export { createAuthzExtension } from "./authz-extension.js";
31
+ export type { AuthzCallResult, AuthzDecision, AuthzExtensionOptions, AuthzMatchedGrant, } from "./authz-extension.js";
32
+ export { createAuditCollector } from "./audit-collector.js";
33
+ export type { AuditCollector } from "./audit-collector.js";
34
+ export { createSizeCapTransform } from "./transforms/index.js";
35
+ export type { SizeCapTransformOptions } from "./transforms/index.js";
36
+ export { createReactorAssembly } from "./assembly.js";
37
+ export type { ReactorAssembly, ReactorAssemblyConfig } from "./assembly.js";
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ export { parseSSE } from "./sse.js";
2
+ export { encodeToolName, decodeToolName } from "./tool-name.js";
3
+ export { runInference, createDependencies, createDefaultScheduler, HarnessId, } from "./harness.js";
4
+ export { AdapterManifest, AdapterManifestEntry } from "./manifest.js";
5
+ export { CREDENTIAL_SENTINEL, BEARER_CREDENTIAL_SENTINEL } from "./auth.js";
6
+ export { classifyHTTPError, classifyNetworkError, classifyAbortError, classifyStreamError, classifyProtocolMismatch, ProtocolMismatchError, } from "./errors.js";
7
+ export { transformMessages, createIDNormalizer } from "./transform.js";
8
+ export { createDefaultRetryPolicy } from "./retry-policy.js";
9
+ export { uploadGoogleGenAIFile } from "./providers/google-genai-files.js";
10
+ export { createInboundTurn } from "./turns.js";
11
+ export { createReactor } from "./reactor.js";
12
+ export { validateActions } from "./actions.js";
13
+ export { createGateManager } from "./gates.js";
14
+ export { createCorrelationRegistry } from "./correlation.js";
15
+ export { createStateManager } from "./state.js";
16
+ export { createCapabilities } from "./director.js";
17
+ export { DefaultDirector, createDefaultDirector } from "./default-director.js";
18
+ export { createAuthzExtension } from "./authz-extension.js";
19
+ export { createAuditCollector } from "./audit-collector.js";
20
+ export { createSizeCapTransform } from "./transforms/index.js";
21
+ export { createReactorAssembly } from "./assembly.js";
@@ -0,0 +1,31 @@
1
+ import type { AdapterFactory } from "./adapter.js";
2
+ export declare const AdapterManifestEntry: import("arktype/internal/variants/object.ts").ObjectType<{
3
+ provider: string;
4
+ specifier: string;
5
+ export: string;
6
+ }, {}>;
7
+ export type AdapterManifestEntry = typeof AdapterManifestEntry.infer;
8
+ export declare const AdapterManifest: import("arktype/internal/variants/array.ts").ArrayType<{
9
+ provider: string;
10
+ specifier: string;
11
+ export: string;
12
+ }[], {}>;
13
+ export type AdapterManifest = typeof AdapterManifest.infer;
14
+ export type ModuleImporter = (specifier: string) => Promise<unknown>;
15
+ /**
16
+ * Imports each manifest entry's module and narrows its named export to an
17
+ * {@link AdapterFactory}, returning a record keyed by provider identifier.
18
+ * Later entries override earlier ones sharing a provider key.
19
+ *
20
+ * Fails loud (naming the specifier, and the export where relevant) when a
21
+ * module does not resolve to an object, the named export is missing, or the
22
+ * named export is not a function. The importer seam defaults to `import()` and
23
+ * is injectable for testing.
24
+ *
25
+ * @param manifest - Validated manifest entries to load
26
+ * @param opts - Optional injected module importer
27
+ * @returns A record of provider identifier to adapter factory
28
+ */
29
+ export declare function loadAdapterFactories(manifest: AdapterManifest, opts?: {
30
+ import?: ModuleImporter;
31
+ }): Promise<Record<string, AdapterFactory>>;
@@ -0,0 +1,44 @@
1
+ import { type } from "arktype";
2
+ // Describes one custom adapter: the provider identifier it serves, the module
3
+ // specifier to import, and the named export within that module to use as its
4
+ // factory. Specifiers are operator-config-only and resolve to arbitrary code
5
+ // via `import()`, so they must originate solely from trusted operator
6
+ // configuration, never from tenant or deploy data. The shape is validated at
7
+ // every deserialization boundary; the value is trusted operator input.
8
+ export const AdapterManifestEntry = type({
9
+ provider: "string",
10
+ specifier: "string",
11
+ export: "string",
12
+ });
13
+ export const AdapterManifest = AdapterManifestEntry.array();
14
+ /**
15
+ * Imports each manifest entry's module and narrows its named export to an
16
+ * {@link AdapterFactory}, returning a record keyed by provider identifier.
17
+ * Later entries override earlier ones sharing a provider key.
18
+ *
19
+ * Fails loud (naming the specifier, and the export where relevant) when a
20
+ * module does not resolve to an object, the named export is missing, or the
21
+ * named export is not a function. The importer seam defaults to `import()` and
22
+ * is injectable for testing.
23
+ *
24
+ * @param manifest - Validated manifest entries to load
25
+ * @param opts - Optional injected module importer
26
+ * @returns A record of provider identifier to adapter factory
27
+ */
28
+ export async function loadAdapterFactories(manifest, opts) {
29
+ const importer = opts?.import ?? ((specifier) => import(specifier));
30
+ const factories = {};
31
+ for (const entry of manifest) {
32
+ const mod = await importer(entry.specifier);
33
+ if (typeof mod !== "object" || mod === null) {
34
+ throw new Error(`Adapter module did not resolve to an object: ${entry.specifier}`);
35
+ }
36
+ const exported = Reflect.get(mod, entry.export);
37
+ if (typeof exported !== "function") {
38
+ throw new Error(`Adapter export is not a function: ${entry.export} from ${entry.specifier}`);
39
+ }
40
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- dynamically imported factory; the call signature cannot be verified at runtime, enforced by the AdapterFactory contract
41
+ factories[entry.provider] = exported;
42
+ }
43
+ return factories;
44
+ }
@@ -0,0 +1,33 @@
1
+ import type { LastCycleSource } from "@intx/types/runtime";
2
+ import type { ProviderAdapter } from "../adapter.js";
3
+ export type AnthropicRawEvent = {
4
+ kind: "text_delta";
5
+ token: string;
6
+ } | {
7
+ kind: "thinking_delta";
8
+ token: string;
9
+ } | {
10
+ kind: "tool_call_start";
11
+ index: number;
12
+ callId: string;
13
+ name: string;
14
+ } | {
15
+ kind: "tool_call_delta";
16
+ index: number;
17
+ argumentFragment: string;
18
+ } | {
19
+ kind: "tool_call_end";
20
+ index: number;
21
+ } | {
22
+ kind: "usage";
23
+ inputTokens: number;
24
+ outputTokens: number;
25
+ cacheReadTokens: number;
26
+ cacheWriteTokens: number;
27
+ thinkingTokens: number;
28
+ } | {
29
+ kind: "message_stop";
30
+ } | {
31
+ kind: "skip";
32
+ };
33
+ export declare function createAnthropicAdapter(source: LastCycleSource): ProviderAdapter;