@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.
- package/LICENSE +176 -0
- package/dist/actions.d.ts +16 -0
- package/dist/actions.js +200 -0
- package/dist/adapter.d.ts +38 -0
- package/dist/adapter.js +31 -0
- package/dist/assembly.d.ts +68 -0
- package/dist/assembly.js +132 -0
- package/dist/audit-collector.d.ts +10 -0
- package/dist/audit-collector.js +139 -0
- package/dist/auth.d.ts +24 -0
- package/{src/auth.ts → dist/auth.js} +13 -19
- package/dist/authz-extension.d.ts +32 -0
- package/dist/authz-extension.js +100 -0
- package/dist/correlation.d.ts +25 -0
- package/dist/correlation.js +32 -0
- package/dist/default-director.d.ts +111 -0
- package/dist/default-director.js +199 -0
- package/dist/director.d.ts +6 -0
- package/dist/director.js +56 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +83 -0
- package/dist/gates.d.ts +27 -0
- package/dist/gates.js +80 -0
- package/dist/harness.d.ts +147 -0
- package/dist/harness.js +1319 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +21 -0
- package/dist/manifest.d.ts +31 -0
- package/dist/manifest.js +44 -0
- package/dist/providers/anthropic.d.ts +33 -0
- package/dist/providers/anthropic.js +670 -0
- package/dist/providers/google-genai-files.d.ts +48 -0
- package/dist/providers/google-genai-files.js +205 -0
- package/dist/providers/google-genai.d.ts +3 -0
- package/dist/providers/google-genai.js +1196 -0
- package/dist/providers/index.d.ts +38 -0
- package/dist/providers/index.js +56 -0
- package/dist/providers/openai.d.ts +3 -0
- package/dist/providers/openai.js +609 -0
- package/dist/reactor.d.ts +50 -0
- package/dist/reactor.js +920 -0
- package/dist/retry-policy.d.ts +31 -0
- package/{src/retry-policy.ts → dist/retry-policy.js} +41 -53
- package/dist/sse.d.ts +1 -0
- package/dist/sse.js +63 -0
- package/dist/state.d.ts +23 -0
- package/dist/state.js +100 -0
- package/dist/tool-name.d.ts +6 -0
- package/dist/tool-name.js +110 -0
- package/dist/transform.d.ts +11 -0
- package/dist/transform.js +117 -0
- package/dist/transforms/index.d.ts +2 -0
- package/dist/transforms/index.js +1 -0
- package/dist/transforms/size-cap.d.ts +12 -0
- package/dist/transforms/size-cap.js +80 -0
- package/dist/turns.d.ts +21 -0
- package/dist/turns.js +135 -0
- package/package.json +21 -6
- package/src/actions.ts +0 -245
- package/src/adapter.ts +0 -57
- package/src/assembly.test.ts +0 -728
- package/src/assembly.ts +0 -250
- package/src/audit-collector.test.ts +0 -332
- package/src/audit-collector.ts +0 -172
- package/src/auth.test.ts +0 -117
- package/src/authz-extension.test.ts +0 -269
- package/src/authz-extension.ts +0 -145
- package/src/correlation.ts +0 -61
- package/src/default-director.test.ts +0 -314
- package/src/default-director.ts +0 -344
- package/src/director.ts +0 -87
- package/src/errors.test.ts +0 -133
- package/src/errors.ts +0 -115
- package/src/gates.ts +0 -128
- package/src/harness.test.ts +0 -655
- package/src/harness.ts +0 -1571
- package/src/index.ts +0 -76
- package/src/providers/anthropic.test.ts +0 -771
- package/src/providers/anthropic.ts +0 -810
- package/src/providers/google-genai-files.ts +0 -289
- package/src/providers/google-genai.ts +0 -1518
- package/src/providers/openai.ts +0 -719
- package/src/providers/registry.ts +0 -33
- package/src/reactor.test.ts +0 -3660
- package/src/reactor.ts +0 -1058
- package/src/scheduler.test.ts +0 -41
- package/src/sse.test.ts +0 -133
- package/src/sse.ts +0 -76
- package/src/state.ts +0 -135
- package/src/transform.test.ts +0 -207
- package/src/transform.ts +0 -159
- package/src/transforms/index.ts +0 -2
- package/src/transforms/size-cap.test.ts +0 -172
- package/src/transforms/size-cap.ts +0 -110
- package/src/turns.ts +0 -54
- package/tsconfig.json +0 -4
- package/tsconfig.tsbuildinfo +0 -1
package/dist/index.d.ts
ADDED
|
@@ -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>>;
|
package/dist/manifest.js
ADDED
|
@@ -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;
|