@ank1015/agents-core 0.1.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.
- package/CHANGELOG.md +16 -0
- package/README.md +116 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +2 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/registry.d.ts +30 -0
- package/dist/models/registry.d.ts.map +1 -0
- package/dist/models/registry.js +52 -0
- package/dist/models/registry.js.map +1 -0
- package/dist/stream/event-stream.d.ts +2 -0
- package/dist/stream/event-stream.d.ts.map +1 -0
- package/dist/stream/event-stream.js +2 -0
- package/dist/stream/event-stream.js.map +1 -0
- package/dist/stream/index.d.ts +2 -0
- package/dist/stream/index.d.ts.map +1 -0
- package/dist/stream/index.js +2 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/transport/adapter-transport.d.ts +4 -0
- package/dist/transport/adapter-transport.d.ts.map +1 -0
- package/dist/transport/adapter-transport.js +22 -0
- package/dist/transport/adapter-transport.js.map +1 -0
- package/dist/transport/gateway-transport.d.ts +17 -0
- package/dist/transport/gateway-transport.d.ts.map +1 -0
- package/dist/transport/gateway-transport.js +228 -0
- package/dist/transport/gateway-transport.js.map +1 -0
- package/dist/transport/index.d.ts +3 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +3 -0
- package/dist/transport/index.js.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@ank1015/agents-core` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## 0.1.1
|
|
6
|
+
|
|
7
|
+
- Republished the initial release with a registry-safe dependency on `@ank1015/agents-contracts`.
|
|
8
|
+
|
|
9
|
+
## 0.1.0 - Initial Release
|
|
10
|
+
|
|
11
|
+
- Added an isolated and process-wide model registry for provider catalog lookup.
|
|
12
|
+
- Added adapter transport routing for provider-specific `LLMProviderAdapter` implementations.
|
|
13
|
+
- Added gateway transport for streaming LLM events over HTTP server-sent events.
|
|
14
|
+
- Re-exported the shared queue-backed `createEventStream` primitive from `@ank1015/agents-contracts`.
|
|
15
|
+
- Added grouped package exports for `models`, `stream`, and `transport`.
|
|
16
|
+
- Added unit coverage for registries, streams, adapter routing, and gateway transport behavior.
|
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# @ank1015/agents-core
|
|
2
|
+
|
|
3
|
+
Core runtime primitives for the `@ank1015/agents` packages.
|
|
4
|
+
|
|
5
|
+
This package sits above `@ank1015/agents-contracts` and below applications. It provides small, provider-neutral runtime pieces: model catalog lookup, stream creation, provider-adapter routing, and an HTTP gateway transport.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @ank1015/agents-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What This Package Provides
|
|
14
|
+
|
|
15
|
+
- `ModelRegistry` helpers for static provider model catalogs.
|
|
16
|
+
- A process-wide model registry for app startup wiring.
|
|
17
|
+
- `createAdapterTransport` for routing requests to provider adapters.
|
|
18
|
+
- `GatewayTransport` for streaming assistant events from a remote gateway.
|
|
19
|
+
- `createEventStream` re-exported from `@ank1015/agents-contracts`.
|
|
20
|
+
|
|
21
|
+
## Import Paths
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import {
|
|
25
|
+
createGatewayTransport,
|
|
26
|
+
createModelRegistry,
|
|
27
|
+
} from '@ank1015/agents-core';
|
|
28
|
+
|
|
29
|
+
import { registerModels } from '@ank1015/agents-core/models';
|
|
30
|
+
import { createEventStream } from '@ank1015/agents-core/stream';
|
|
31
|
+
import { createAdapterTransport } from '@ank1015/agents-core/transport';
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Model Registry
|
|
35
|
+
|
|
36
|
+
Use `createModelRegistry` for isolated registries, such as tests or per-runtime containers:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { createModelRegistry } from '@ank1015/agents-core/models';
|
|
40
|
+
import { ANTHROPIC_MODELS } from '@ank1015/agents-provider-anthropic-spec';
|
|
41
|
+
|
|
42
|
+
const registry = createModelRegistry([ANTHROPIC_MODELS]);
|
|
43
|
+
const model = registry.get('anthropic', 'claude-sonnet-4-6');
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Use the process-wide helpers when an app wants to register provider catalogs once at startup:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { getModel, registerModels } from '@ank1015/agents-core/models';
|
|
50
|
+
import { ANTHROPIC_MODELS } from '@ank1015/agents-provider-anthropic-spec';
|
|
51
|
+
|
|
52
|
+
registerModels(ANTHROPIC_MODELS);
|
|
53
|
+
|
|
54
|
+
const model = getModel('anthropic', 'claude-sonnet-4-6');
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Adapter Transport
|
|
58
|
+
|
|
59
|
+
`createAdapterTransport` multiplexes `LLMRequest`s to provider adapters by `request.provider`:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { createAdapterTransport } from '@ank1015/agents-core/transport';
|
|
63
|
+
import { createAnthropicProviderAdapter } from '@ank1015/agents-provider-anthropic';
|
|
64
|
+
|
|
65
|
+
const transport = createAdapterTransport([
|
|
66
|
+
createAnthropicProviderAdapter({
|
|
67
|
+
provider: 'anthropic',
|
|
68
|
+
apiKey: { type: 'env', name: 'ANTHROPIC_API_KEY' },
|
|
69
|
+
}),
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
const stream = transport.stream({
|
|
73
|
+
provider: 'anthropic',
|
|
74
|
+
modelId: 'claude-sonnet-4-6',
|
|
75
|
+
messages: [],
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Gateway Transport
|
|
80
|
+
|
|
81
|
+
`createGatewayTransport` sends normalized LLM requests to a remote gateway endpoint and consumes assistant events from an SSE response.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { createGatewayTransport } from '@ank1015/agents-core/transport';
|
|
85
|
+
|
|
86
|
+
const transport = createGatewayTransport({
|
|
87
|
+
baseUrl: 'https://gateway.example.com',
|
|
88
|
+
apiKey: process.env.AGENTS_GATEWAY_API_KEY ?? '',
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The gateway transport posts to:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
POST /v1/llm/stream
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
It expects server-sent event frames whose `data:` payloads are serialized `AssistantEvent` objects. The stream completes when it receives a `done`, `error`, or `aborted` event.
|
|
99
|
+
|
|
100
|
+
## Streams
|
|
101
|
+
|
|
102
|
+
`createEventStream` is re-exported from `@ank1015/agents-contracts` for convenience:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { createEventStream } from '@ank1015/agents-core/stream';
|
|
106
|
+
|
|
107
|
+
const stream = createEventStream<string, number>();
|
|
108
|
+
stream.push('started');
|
|
109
|
+
stream.end(1);
|
|
110
|
+
|
|
111
|
+
const result = await stream.result();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Versioning
|
|
115
|
+
|
|
116
|
+
This package is currently `0.1.0`. Until `1.0.0`, public runtime APIs may still evolve as the provider packages and gateway contract settle.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Model, ModelIdForProvider, Provider } from '@ank1015/agents-contracts';
|
|
2
|
+
/**
|
|
3
|
+
* A transport-free lookup of model descriptors composed from provider-spec
|
|
4
|
+
* catalogs (e.g. `ANTHROPIC_MODELS`). Model descriptions are static SDK
|
|
5
|
+
* knowledge, so this never touches the network — it answers "what is model X"
|
|
6
|
+
* from whatever catalogs were registered. The app declares the providers it
|
|
7
|
+
* supports by registering their catalogs (the runtime echo of "the app chooses
|
|
8
|
+
* the provider").
|
|
9
|
+
*/
|
|
10
|
+
export interface ModelRegistry {
|
|
11
|
+
/** Adds a provider catalog. Later entries win on an id clash within a provider. */
|
|
12
|
+
register(models: readonly Model[]): void;
|
|
13
|
+
/** Resolves a model descriptor, narrowed to the provider. Undefined if unregistered. */
|
|
14
|
+
get<TProvider extends Provider>(provider: TProvider, modelId: ModelIdForProvider<TProvider>): Model<TProvider> | undefined;
|
|
15
|
+
/** All registered models, optionally filtered to one provider. */
|
|
16
|
+
list(provider?: Provider): Model[];
|
|
17
|
+
/** Drops everything (useful for test isolation). */
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
/** Builds an isolated {@link ModelRegistry} from zero or more provider catalogs. */
|
|
21
|
+
export declare function createModelRegistry(catalogs?: readonly (readonly Model[])[]): ModelRegistry;
|
|
22
|
+
/** Registers a provider catalog into the process-wide registry. */
|
|
23
|
+
export declare function registerModels(models: readonly Model[]): void;
|
|
24
|
+
/** Resolves a model descriptor from the process-wide registry. Undefined if unregistered. */
|
|
25
|
+
export declare function getModel<TProvider extends Provider>(provider: TProvider, modelId: ModelIdForProvider<TProvider>): Model<TProvider> | undefined;
|
|
26
|
+
/** All models in the process-wide registry, optionally filtered to one provider. */
|
|
27
|
+
export declare function listModels(provider?: Provider): Model[];
|
|
28
|
+
/** Clears the process-wide registry (useful for test isolation). */
|
|
29
|
+
export declare function clearModelRegistry(): void;
|
|
30
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/models/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErF;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,CAAC;IACzC,wFAAwF;IACxF,GAAG,CAAC,SAAS,SAAS,QAAQ,EAC5B,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,GACrC,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAChC,kEAAkE;IAClE,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,EAAE,CAAC;IACnC,oDAAoD;IACpD,KAAK,IAAI,IAAI,CAAC;CACf;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,CACjC,QAAQ,GAAE,SAAS,CAAC,SAAS,KAAK,EAAE,CAAC,EAAO,GAC3C,aAAa,CAiCf;AASD,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,CAE7D;AAED,6FAA6F;AAC7F,wBAAgB,QAAQ,CAAC,SAAS,SAAS,QAAQ,EACjD,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC,GACrC,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS,CAE9B;AAED,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,EAAE,CAEvD;AAED,oEAAoE;AACpE,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Builds an isolated {@link ModelRegistry} from zero or more provider catalogs. */
|
|
2
|
+
export function createModelRegistry(catalogs = []) {
|
|
3
|
+
const byProvider = new Map();
|
|
4
|
+
const register = (models) => {
|
|
5
|
+
for (const model of models) {
|
|
6
|
+
const forProvider = byProvider.get(model.provider) ?? new Map();
|
|
7
|
+
forProvider.set(model.id, model);
|
|
8
|
+
byProvider.set(model.provider, forProvider);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
for (const catalog of catalogs) {
|
|
12
|
+
register(catalog);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
register,
|
|
16
|
+
get(provider, modelId) {
|
|
17
|
+
return byProvider.get(provider)?.get(modelId);
|
|
18
|
+
},
|
|
19
|
+
list(provider) {
|
|
20
|
+
if (provider !== undefined) {
|
|
21
|
+
return [...(byProvider.get(provider)?.values() ?? [])];
|
|
22
|
+
}
|
|
23
|
+
return [...byProvider.values()].flatMap((forProvider) => [...forProvider.values()]);
|
|
24
|
+
},
|
|
25
|
+
clear() {
|
|
26
|
+
byProvider.clear();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The process-wide default registry backing {@link registerModels} / {@link getModel}.
|
|
32
|
+
* Apps register the catalogs of the provider-spec packages they install, once at
|
|
33
|
+
* startup; {@link getModel} can then be imported anywhere without threading a registry.
|
|
34
|
+
*/
|
|
35
|
+
const globalRegistry = createModelRegistry();
|
|
36
|
+
/** Registers a provider catalog into the process-wide registry. */
|
|
37
|
+
export function registerModels(models) {
|
|
38
|
+
globalRegistry.register(models);
|
|
39
|
+
}
|
|
40
|
+
/** Resolves a model descriptor from the process-wide registry. Undefined if unregistered. */
|
|
41
|
+
export function getModel(provider, modelId) {
|
|
42
|
+
return globalRegistry.get(provider, modelId);
|
|
43
|
+
}
|
|
44
|
+
/** All models in the process-wide registry, optionally filtered to one provider. */
|
|
45
|
+
export function listModels(provider) {
|
|
46
|
+
return globalRegistry.list(provider);
|
|
47
|
+
}
|
|
48
|
+
/** Clears the process-wide registry (useful for test isolation). */
|
|
49
|
+
export function clearModelRegistry() {
|
|
50
|
+
globalRegistry.clear();
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/models/registry.ts"],"names":[],"mappings":"AAwBA,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CACjC,WAA0C,EAAE;IAE5C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAgC,CAAC;IAE3D,MAAM,QAAQ,GAAG,CAAC,MAAwB,EAAQ,EAAE;QAClD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,IAAI,GAAG,EAAiB,CAAC;YAC/E,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACjC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;IAED,OAAO;QACL,QAAQ;QACR,GAAG,CACD,QAAmB,EACnB,OAA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2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-stream.js","sourceRoot":"","sources":["../../src/stream/event-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LLMProviderAdapter, LLMTransport } from '@ank1015/agents-contracts';
|
|
2
|
+
export type TransportAdapter = LLMProviderAdapter<any>;
|
|
3
|
+
export declare function createAdapterTransport(adapters: readonly TransportAdapter[]): LLMTransport;
|
|
4
|
+
//# sourceMappingURL=adapter-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-transport.d.ts","sourceRoot":"","sources":["../../src/transport/adapter-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAElB,YAAY,EAEb,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAEvD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,GAAG,YAAY,CAE1F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function createAdapterTransport(adapters) {
|
|
2
|
+
return new AdapterTransport(adapters);
|
|
3
|
+
}
|
|
4
|
+
class AdapterTransport {
|
|
5
|
+
#adapters = new Map();
|
|
6
|
+
constructor(adapters) {
|
|
7
|
+
for (const adapter of adapters) {
|
|
8
|
+
if (this.#adapters.has(adapter.provider)) {
|
|
9
|
+
throw new Error(`Duplicate LLM adapter registered for provider "${adapter.provider}".`);
|
|
10
|
+
}
|
|
11
|
+
this.#adapters.set(adapter.provider, adapter);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
stream(request) {
|
|
15
|
+
const adapter = this.#adapters.get(request.provider);
|
|
16
|
+
if (!adapter) {
|
|
17
|
+
throw new Error(`No LLM adapter registered for provider "${request.provider}".`);
|
|
18
|
+
}
|
|
19
|
+
return adapter.stream(request);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=adapter-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-transport.js","sourceRoot":"","sources":["../../src/transport/adapter-transport.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,sBAAsB,CAAC,QAAqC;IAC1E,OAAO,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,gBAAgB;IACX,SAAS,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE3D,YAAY,QAAqC;QAC/C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACzC,MAAM,IAAI,KAAK,CAAC,kDAAkD,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;YAC1F,CAAC;YAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,MAAM,CACJ,OAA8B;QAE9B,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,2CAA2C,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;QACnF,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAA2C,CAAC;IAC3E,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AssistantMessageEventStream, type LLMRequest, type LLMTransport, type Provider } from '@ank1015/agents-contracts';
|
|
2
|
+
export interface GatewayTransportOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
appName?: string;
|
|
6
|
+
fetch?: typeof fetch;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
createMessageId?: () => string;
|
|
9
|
+
now?: () => number;
|
|
10
|
+
}
|
|
11
|
+
export declare class GatewayTransport implements LLMTransport {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(options: GatewayTransportOptions);
|
|
14
|
+
stream<TProvider extends Provider>(request: LLMRequest<TProvider>): AssistantMessageEventStream<TProvider>;
|
|
15
|
+
}
|
|
16
|
+
export declare function createGatewayTransport(options: GatewayTransportOptions): GatewayTransport;
|
|
17
|
+
//# sourceMappingURL=gateway-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-transport.d.ts","sourceRoot":"","sources":["../../src/transport/gateway-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,2BAA2B,EAChC,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEd,MAAM,2BAA2B,CAAC;AAGnC,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,MAAM,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAqBD,qBAAa,gBAAiB,YAAW,YAAY;;gBAQvC,OAAO,EAAE,uBAAuB;IAS5C,MAAM,CAAC,SAAS,SAAS,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,2BAA2B,CAAC,SAAS,CAAC;CAuF3G;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CAEzF"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { toolParametersToJsonSchema } from '@ank1015/agents-contracts';
|
|
2
|
+
import { createEventStream } from '../stream/index.js';
|
|
3
|
+
export class GatewayTransport {
|
|
4
|
+
#baseUrl;
|
|
5
|
+
#apiKey;
|
|
6
|
+
#fetch;
|
|
7
|
+
#headers;
|
|
8
|
+
#createMessageId;
|
|
9
|
+
#now;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.#baseUrl = options.baseUrl.replace(/\/+$/, '');
|
|
12
|
+
this.#apiKey = options.apiKey;
|
|
13
|
+
this.#fetch = options.fetch ?? fetch;
|
|
14
|
+
this.#headers = options.headers ?? {};
|
|
15
|
+
this.#createMessageId = options.createMessageId ?? createDefaultMessageId;
|
|
16
|
+
this.#now = options.now ?? Date.now;
|
|
17
|
+
}
|
|
18
|
+
stream(request) {
|
|
19
|
+
const source = createEventStream();
|
|
20
|
+
void this.#produce(request, source);
|
|
21
|
+
return source;
|
|
22
|
+
}
|
|
23
|
+
async #produce(request, source) {
|
|
24
|
+
try {
|
|
25
|
+
const response = await this.#fetch(`${this.#baseUrl}/v1/llm/stream`, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: {
|
|
28
|
+
...this.#headers,
|
|
29
|
+
authorization: `Bearer ${this.#apiKey}`,
|
|
30
|
+
accept: 'text/event-stream',
|
|
31
|
+
'content-type': 'application/json',
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify(serializeRequest(request)),
|
|
34
|
+
signal: request.signal,
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const message = await this.#failedMessageFromResponse(request, response);
|
|
38
|
+
source.push({ type: 'error', reason: 'error', message });
|
|
39
|
+
source.end(message);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!response.body) {
|
|
43
|
+
const message = failedMessage(request, this.#createMessageId(), this.#now(), 'Gateway response did not include a body.');
|
|
44
|
+
source.push({ type: 'error', reason: 'error', message });
|
|
45
|
+
source.end(message);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
let receivedTerminal = false;
|
|
49
|
+
await consumeSse(response.body, (event) => {
|
|
50
|
+
source.push(event);
|
|
51
|
+
if (isTerminalEvent(event)) {
|
|
52
|
+
receivedTerminal = true;
|
|
53
|
+
source.end(event.message);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
if (!receivedTerminal) {
|
|
59
|
+
const message = failedMessage(request, this.#createMessageId(), this.#now(), 'Gateway stream ended without a terminal event.');
|
|
60
|
+
source.push({ type: 'error', reason: 'error', message });
|
|
61
|
+
source.end(message);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const message = request.signal?.aborted || isAbortError(error)
|
|
66
|
+
? abortedMessage(request, this.#createMessageId(), this.#now())
|
|
67
|
+
: failedMessage(request, this.#createMessageId(), this.#now(), error instanceof Error ? error.message : 'Gateway request failed.');
|
|
68
|
+
const event = message.stopReason === 'aborted'
|
|
69
|
+
? { type: 'aborted', reason: 'aborted', message }
|
|
70
|
+
: { type: 'error', reason: 'error', message };
|
|
71
|
+
source.push(event);
|
|
72
|
+
source.end(message);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async #failedMessageFromResponse(request, response) {
|
|
76
|
+
const payload = await readErrorPayload(response);
|
|
77
|
+
const publicMessage = typeof payload?.error?.message === 'string'
|
|
78
|
+
? payload.error.message
|
|
79
|
+
: `Gateway request failed with HTTP ${response.status}.`;
|
|
80
|
+
return failedMessage(request, this.#createMessageId(), this.#now(), publicMessage);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function createGatewayTransport(options) {
|
|
84
|
+
return new GatewayTransport(options);
|
|
85
|
+
}
|
|
86
|
+
function serializeRequest(request) {
|
|
87
|
+
return {
|
|
88
|
+
provider: request.provider,
|
|
89
|
+
modelId: request.modelId,
|
|
90
|
+
...(request.instructions === undefined ? {} : { instructions: request.instructions }),
|
|
91
|
+
messages: request.messages,
|
|
92
|
+
...(request.tools === undefined ? {} : { tools: serializeTools(request.tools) }),
|
|
93
|
+
...(request.providerOptions === undefined ? {} : { providerOptions: request.providerOptions }),
|
|
94
|
+
...(request.metadata === undefined ? {} : { metadata: request.metadata })
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function serializeTools(tools) {
|
|
98
|
+
return tools.map((tool) => {
|
|
99
|
+
if (tool.type === 'custom') {
|
|
100
|
+
return tool;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
...tool,
|
|
104
|
+
parameters: toolParametersToJsonSchema(tool.parameters)
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async function consumeSse(body, onEvent) {
|
|
109
|
+
const reader = body.getReader();
|
|
110
|
+
const decoder = new TextDecoder();
|
|
111
|
+
let buffer = '';
|
|
112
|
+
try {
|
|
113
|
+
for (;;) {
|
|
114
|
+
const { value, done } = await reader.read();
|
|
115
|
+
if (done) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
buffer += decoder.decode(value, { stream: true });
|
|
119
|
+
const shouldContinue = drainFrames(buffer, onEvent);
|
|
120
|
+
buffer = shouldContinue.buffer;
|
|
121
|
+
if (!shouldContinue.keepReading) {
|
|
122
|
+
await reader.cancel();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
buffer += decoder.decode();
|
|
127
|
+
drainFrames(buffer, onEvent);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
reader.releaseLock();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function drainFrames(buffer, onEvent) {
|
|
134
|
+
let cursor = 0;
|
|
135
|
+
for (;;) {
|
|
136
|
+
const boundary = findSseFrameBoundary(buffer, cursor);
|
|
137
|
+
if (!boundary) {
|
|
138
|
+
return {
|
|
139
|
+
buffer: buffer.slice(cursor),
|
|
140
|
+
keepReading: true
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const frame = buffer.slice(cursor, boundary.index);
|
|
144
|
+
cursor = boundary.index + boundary.length;
|
|
145
|
+
const event = parseSseFrame(frame);
|
|
146
|
+
if (event && !onEvent(event)) {
|
|
147
|
+
return {
|
|
148
|
+
buffer: '',
|
|
149
|
+
keepReading: false
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function findSseFrameBoundary(buffer, cursor) {
|
|
155
|
+
const match = /(?:\r\n|\r|\n){2}/u.exec(buffer.slice(cursor));
|
|
156
|
+
if (!match) {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
index: cursor + match.index,
|
|
161
|
+
length: match[0].length,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function parseSseFrame(frame) {
|
|
165
|
+
const dataLines = [];
|
|
166
|
+
for (const line of frame.split(/\r\n|\r|\n/u)) {
|
|
167
|
+
if (!line || line.startsWith(':')) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (line.startsWith('data:')) {
|
|
171
|
+
dataLines.push(line.slice(5).trimStart());
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (dataLines.length === 0) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
return JSON.parse(dataLines.join('\n'));
|
|
178
|
+
}
|
|
179
|
+
function isTerminalEvent(event) {
|
|
180
|
+
return event.type === 'done' || event.type === 'error' || event.type === 'aborted';
|
|
181
|
+
}
|
|
182
|
+
async function readErrorPayload(response) {
|
|
183
|
+
try {
|
|
184
|
+
return (await response.json());
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function failedMessage(request, id, now, message) {
|
|
191
|
+
return {
|
|
192
|
+
role: 'assistant',
|
|
193
|
+
id,
|
|
194
|
+
model: {
|
|
195
|
+
provider: request.provider,
|
|
196
|
+
id: request.modelId
|
|
197
|
+
},
|
|
198
|
+
duration: 0,
|
|
199
|
+
content: [],
|
|
200
|
+
timestamp: now,
|
|
201
|
+
stopReason: 'error',
|
|
202
|
+
error: {
|
|
203
|
+
message,
|
|
204
|
+
canRetry: true
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function abortedMessage(request, id, now) {
|
|
209
|
+
return {
|
|
210
|
+
role: 'assistant',
|
|
211
|
+
id,
|
|
212
|
+
model: {
|
|
213
|
+
provider: request.provider,
|
|
214
|
+
id: request.modelId
|
|
215
|
+
},
|
|
216
|
+
duration: 0,
|
|
217
|
+
content: [],
|
|
218
|
+
timestamp: now,
|
|
219
|
+
stopReason: 'aborted'
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function isAbortError(error) {
|
|
223
|
+
return typeof DOMException !== 'undefined' && error instanceof DOMException && error.name === 'AbortError';
|
|
224
|
+
}
|
|
225
|
+
function createDefaultMessageId() {
|
|
226
|
+
return `msg_${Math.random().toString(36).slice(2)}`;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=gateway-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-transport.js","sourceRoot":"","sources":["../../src/transport/gateway-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAU3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AA+BvD,MAAM,OAAO,gBAAgB;IACl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KACtB,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,OAAO,YAAY,KAAK,WAAW,IAAI,KAAK,YAAY,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC;AAC7G,CAAC;AAED,SAAS,sBAAsB;IAC7B,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ank1015/agents-core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Core agent runtime primitives for @ank1015/agents.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agents",
|
|
7
|
+
"llm",
|
|
8
|
+
"runtime",
|
|
9
|
+
"transport",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"license": "UNLICENSED",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/ank1015/agent.git",
|
|
20
|
+
"directory": "packages/core"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/ank1015/agent/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/ank1015/agent#readme",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./models": {
|
|
32
|
+
"types": "./dist/models/index.d.ts",
|
|
33
|
+
"import": "./dist/models/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./stream": {
|
|
36
|
+
"types": "./dist/stream/index.d.ts",
|
|
37
|
+
"import": "./dist/stream/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./transport": {
|
|
40
|
+
"types": "./dist/transport/index.d.ts",
|
|
41
|
+
"import": "./dist/transport/index.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"README.md",
|
|
50
|
+
"CHANGELOG.md"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"prepack": "tsc -b",
|
|
54
|
+
"build": "tsc -b",
|
|
55
|
+
"check": "tsc -b --pretty false",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"clean": "rm -rf dist ../../.tsbuildinfo/core.tsbuildinfo"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@ank1015/agents-contracts": "^0.1.1",
|
|
61
|
+
"zod": "^4.4.3"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"vitest": "^4.1.9"
|
|
65
|
+
}
|
|
66
|
+
}
|