Skip to content

Commit b0093a2

Browse files
authored
Add unified provider runtime (#3)
Release the 0.2.0 unified adapter/runtime layer with validated inputs, normalized outputs, lifecycle hooks, built-in RunningHub and OpenAI-compatible adapters, and Node 22-safe timeout enforcement.
1 parent 9965447 commit b0093a2

19 files changed

Lines changed: 828 additions & 14 deletions

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to `aigc-provider-runtime-kit` are recorded here.
44

5-
## Unreleased
5+
## 0.2.0 - 2026-07-10
66

77
### Fixed
88

@@ -19,6 +19,11 @@ All notable changes to `aigc-provider-runtime-kit` are recorded here.
1919
- Dependency-free OpenAI-compatible chat, image, and custom JSON client.
2020
- Opt-in exponential retry/backoff helper with jitter and cancellation.
2121
- Installed-tarball consumer smoke testing for published entrypoints.
22+
- Unified `ProviderAdapter` contract and `createProviderRuntime` execution entrypoint.
23+
- Standard text/image/video/audio/JSON outputs and normalized usage metadata.
24+
- Model input validation for required fields, types, options, ranges, list limits, and capabilities.
25+
- OpenAI-compatible and RunningHub runtime adapters.
26+
- Lifecycle and progress events through isolated observability hooks.
2227

2328
## 0.1.0 - 2026-07-08
2429

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Most AIGC applications eventually need the same provider infrastructure:
4343
npm install aigc-provider-runtime-kit
4444
```
4545

46-
The package is currently in the `0.1.x` foundation line. APIs are intentionally small and may evolve before `1.0`.
46+
The package is currently in the `0.2.x` runtime line. APIs may continue to evolve before `1.0`.
4747

4848
If the package has not been published to npm in your environment yet, install directly from GitHub:
4949

@@ -131,6 +131,43 @@ const response = await client.createImage({
131131

132132
Retries are opt-in. The client retries only retryable network failures, HTTP 408/409/429 responses, and 5xx responses when a retry policy is supplied.
133133

134+
Execute different providers through one runtime entrypoint:
135+
136+
```ts
137+
import {
138+
createOpenAICompatibleAdapter,
139+
createOpenAICompatibleClient,
140+
createProviderRegistry,
141+
createProviderRuntime
142+
} from "aigc-provider-runtime-kit/runtime";
143+
144+
const registry = createProviderRegistry({ providers, models });
145+
const openaiClient = createOpenAICompatibleClient({
146+
baseUrl: "https://api.example.com/v1",
147+
apiKey: process.env.PROVIDER_API_KEY
148+
});
149+
150+
const runtime = createProviderRuntime({
151+
registry,
152+
adapters: [createOpenAICompatibleAdapter({ client: openaiClient })],
153+
hooks: {
154+
onEvent(event) {
155+
console.log(event.type);
156+
}
157+
}
158+
});
159+
160+
const result = await runtime.execute({
161+
providerId: "openai-compatible",
162+
modelId: "image-primary",
163+
input: { prompt: "A cinematic tropical city" }
164+
});
165+
166+
console.log(result.outputs);
167+
```
168+
169+
`providerId` and `modelId` refer to registry IDs. The runtime validates configuration and input, selects an adapter, propagates cancellation/timeouts, and returns normalized outputs.
170+
134171
Build a RunningHub execution descriptor:
135172

136173
```ts

docs/INDEX.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This file is the first-hop router for `aigc-provider-runtime-kit`.
1010
4. Read the relevant system document:
1111
- `docs/systems/providers/README.md`
1212
- `docs/systems/runninghub/README.md`
13+
- `docs/systems/runtime/README.md`
1314
- `docs/systems/harness/README.md`
1415
5. For public API usage, read `docs/getting-started.md` and `docs/api-reference.md`.
1516
6. Check the latest daily log under `docs/logbooks/daily/`.
@@ -22,6 +23,7 @@ This file is the first-hop router for `aigc-provider-runtime-kit`.
2223
| Project overview | `README.md` |
2324
| Provider runtime architecture | `docs/systems/providers/README.md` |
2425
| RunningHub architecture | `docs/systems/runninghub/README.md` |
26+
| Unified runtime architecture | `docs/systems/runtime/README.md` |
2527
| Harness verification | `docs/systems/harness/README.md` |
2628
| Getting started | `docs/getting-started.md` |
2729
| Public API reference | `docs/api-reference.md` |

docs/api-reference.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,36 @@ Provide key-pool concurrency helpers against a Redis-like runtime interface.
9595

9696
Orders enabled keys by preferred key, default key, then other enabled keys.
9797

98+
## Unified Runtime
99+
100+
### `createProviderRuntime(options)`
101+
102+
Creates the unified execution entrypoint. It resolves enabled provider/model records, validates model input, selects the first supporting adapter, propagates cancellation and timeout signals, emits lifecycle events, and normalizes provider/model identity in the result.
103+
104+
### `ProviderAdapter`
105+
106+
Adapters implement `supports(provider, model)` and `execute(context)`. Adapter context includes provider/model definitions, validated input, cancellation signal, timeout, metadata, and a progress emitter.
107+
108+
### `createOpenAICompatibleAdapter(options)`
109+
110+
Adapts the OpenAI-compatible client to unified runtime results. Chat text, image URLs/base64 data, and token usage are normalized automatically. Video/audio endpoints can be supplied through `endpoints`.
111+
112+
### `createRunningHubAdapter(options)`
113+
114+
Adapts a RunningHub client to the unified runtime. It supports a custom `resolveRunInput` function or model `advancedConfig.runninghub` with target IDs and an input `fieldMap`.
115+
116+
### `validateProviderExecutionInput(model, input)`
117+
118+
Validates required fields, scalar/array types, allowed options, numeric ranges, list maximums, and declared input capabilities.
119+
120+
### `ProviderRuntimeError` and `isProviderRuntimeError(value)`
121+
122+
Distinguish missing/disabled configuration, provider-model mismatch, invalid input, missing adapters, adapter failures, and aborted/timed-out executions.
123+
124+
### Runtime events
125+
126+
An optional `hooks.onEvent` handler receives started, validated, adapter-selected, progress, success, and failure events. Hook failures are isolated and never change execution behavior.
127+
98128
## Stability
99129

100-
This is a `0.1.x` foundation API. Prefer wrapping package calls behind a host-app adapter if you need long-term compatibility before `1.0`.
130+
This is a `0.2.x` pre-1.0 API. The unified runtime is ready for application integration, but breaking improvements remain possible before `1.0`.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# 2026-07-10 Unified Runtime
2+
3+
## Intent
4+
5+
Deliver the 0.2.0 unified execution layer so applications can run different providers through one validated, observable contract.
6+
7+
## Changed
8+
9+
| Area | Files | Purpose |
10+
| --- | --- | --- |
11+
| Runtime contracts | `packages/runtime/src/contracts.ts` | Define adapter, request, result, output, usage, progress, and event contracts |
12+
| Unified execution | `packages/runtime/src/runtime.ts` | Resolve configuration, validate, select adapters, execute, and normalize results |
13+
| Input validation | `packages/runtime/src/input-validation.ts` | Validate required fields, types, options, ranges, lists, and capabilities |
14+
| Built-in adapters | `packages/runtime/src/adapters.ts` | Bridge OpenAI-compatible and RunningHub clients into the unified runtime |
15+
| Tests | `tests/runtime.test.mjs` | Cover execution, validation, adapter selection, timeouts, hooks, mapping, and normalization |
16+
| Release | `package.json`, `package-lock.json`, `CHANGELOG.md` | Prepare version 0.2.0 |
17+
| Documentation | `README.md`, `docs/*` | Document architecture, public API, examples, and boundaries |
18+
19+
## Verification
20+
21+
| Check | Result |
22+
| --- | --- |
23+
| `npm run harness:verify:release` | Passed |
24+
| `npm test` | Passed (26 tests) |
25+
| Installed tarball consumer | Passed |
26+
| `npm audit --audit-level=high` | Passed (0 vulnerabilities) |
27+
28+
## Decisions
29+
30+
- Registry model IDs are the public execution identifiers; upstream model IDs remain adapter concerns.
31+
- Adapter clients are injected so credentials remain owned by the host application.
32+
- Observability hooks are isolated from execution success/failure.
33+
- Raw provider responses remain optional while standard outputs are always available.
34+
35+
## Risks
36+
37+
- Vendor-specific async video providers still need dedicated adapters or endpoint/result normalization callbacks.
38+
- Version 0.2.0 remains pre-1.0 and may evolve as real host applications integrate it.
39+
40+
## Next
41+
42+
Integrate 0.2.0 into a host application, collect provider fixtures, and add provider-specific adapters based on real demand.

docs/roadmap.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Roadmap
22

3-
## Current Line: 0.1.x Foundation
3+
## Current Line: 0.2.x Unified Runtime
44

55
Goal: provide stable, framework-neutral primitives that other AIGC products can reuse without copying provider-specific glue.
66

@@ -18,21 +18,25 @@ Completed:
1818
- OpenAI-compatible chat/image/custom JSON client.
1919
- Opt-in retry/backoff policy helper.
2020
- Installed-package consumer smoke testing.
21+
- Unified provider adapter and execution contracts.
22+
- Standard execution outputs, usage, errors, timeout/cancellation, and lifecycle events.
23+
- OpenAI-compatible and RunningHub runtime adapters.
24+
- Runtime validation for model parameters and input capabilities.
2125
- Harness, CI, docs, and unit tests.
2226

23-
## 0.2.x Candidate Work
27+
## 0.3.x Candidate Work
2428

2529
- Add provider adapter examples for vendor-specific video APIs.
2630
- Add fixtures for common RunningHub App and Workflow shapes.
2731
- Add idempotency-key guidance and provider-specific retry presets.
2832
- Add optional host-app adapter examples for Express/Fastify without making them core dependencies.
2933
- Add package export compatibility tests.
3034

31-
## 0.3.x Candidate Work
35+
## Later Candidate Work
3236

3337
- Add environment/file loaders around the typed provider registry.
3438
- Add deeper validation for admin-edited model parameter schemas.
35-
- Add observability hooks for audit events, timing, provider status, and retry decisions.
39+
- Add optional OpenTelemetry/Sentry bridge examples on top of runtime events.
3640
- Add more complete key-pool strategies such as weighted dispatch and cooldown windows.
3741

3842
## Deferred Until Explicitly Needed

docs/systems/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ System docs describe runtime contracts and reusable boundaries.
77
| Harness | `docs/systems/harness/README.md` |
88
| Providers | `docs/systems/providers/README.md` |
99
| RunningHub | `docs/systems/runninghub/README.md` |
10+
| Unified runtime | `docs/systems/runtime/README.md` |
1011
| API integration | `docs/systems/api/README.md` |
1112
| Worker integration | `docs/systems/worker/README.md` |
1213
| Admin UI guidance | `docs/systems/admin/frontend-design/` |

docs/systems/runtime/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Unified Provider Runtime
2+
3+
## Purpose
4+
5+
The unified runtime lets host applications execute configured models without branching on provider-specific clients.
6+
7+
## Ownership
8+
9+
- Code: `packages/runtime/src/`
10+
- Public exports: `aigc-provider-runtime-kit` and `aigc-provider-runtime-kit/runtime`
11+
- API reference: `docs/api-reference.md`
12+
- Tests: `tests/runtime.test.mjs`
13+
14+
## Execution Flow
15+
16+
1. Resolve the requested provider and model from the validated registry.
17+
2. Reject missing, disabled, or mismatched configuration.
18+
3. Validate input against the model parameter schema and input capabilities.
19+
4. Select the first adapter whose `supports` method accepts the provider/model pair.
20+
5. Execute with propagated timeout, cancellation, metadata, and progress events.
21+
6. Return standard outputs and usage while preserving optional raw provider data.
22+
23+
## Boundaries
24+
25+
- Adapters receive already configured clients; the runtime does not store credentials.
26+
- Hooks are observational and cannot break provider execution.
27+
- The runtime does not persist tasks, enqueue jobs, or implement permissions/billing.
28+
- Retries remain an explicit client/adapter policy because generation calls may not be idempotent.
29+
30+
## Verification
31+
32+
```bash
33+
npm run harness:verify:release
34+
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "aigc-provider-runtime-kit",
3-
"version": "0.1.0",
4-
"description": "Provider and RunningHub runtime kit for AIGC applications: provider schemas, request builders, execution descriptors, clients, and key-pool dispatch.",
3+
"version": "0.2.0",
4+
"description": "Framework-neutral AIGC provider runtime with validated registries, unified adapters, standard outputs, and RunningHub/OpenAI-compatible clients.",
55
"type": "module",
66
"private": false,
77
"license": "MIT",

0 commit comments

Comments
 (0)