@hsb3/carbon-agui-adapter 0.1.0 → 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/README.md CHANGED
@@ -1,26 +1,34 @@
1
1
  # carbon-agui-adapter
2
2
 
3
- Drives IBM **Carbon AI Chat** (`@carbon/ai-chat`) from an **AG-UI** event stream. Zero runtime deps.
3
+ Drives IBM **Carbon AI Chat** (`@carbon/ai-chat`) from an **AG-UI** event stream.
4
+
5
+ One runtime dependency (`@ag-ui/core`, for event schemas). `@carbon/ai-chat` is a
6
+ devDependency only — the consuming app owns its own Carbon version.
4
7
 
5
8
  - Carbon `customSendMessage` → AG-UI `RunAgentInput` (thread + history + tools + state)
6
9
  - AG-UI events → Carbon `addMessageChunk` (`partial_item` / `complete_item` / `final_response`)
7
- - Keeps thread history and shared state across turns; applies `STATE_DELTA` JSON Patches
10
+ - Keeps thread history and shared state across turns; applies `STATE_DELTA` as full RFC 6902 JSON Patch
8
11
  - Tool calls → Carbon **chain-of-thought** steps (`message_options.chain_of_thought`) with args/result/status
9
12
  - Cancel via Carbon's `AbortSignal`; `RUN_ERROR` throws so Carbon shows the retry UI
13
+ - LangGraph interrupts → an approve/reject/edit decision card; `respondToInterrupt` resumes the same thread
14
+ - `CUSTOM` `carbon.item`/`carbon.items` events → native Carbon items (the generative-UI seam)
15
+ - Validated at both seams at runtime: AG-UI events via `@ag-ui/core` schemas, Carbon items via an allowlist
10
16
  - `test/carbon-compat.ts` typechecks the adapter against the real `@carbon/ai-chat` (1.19) types
17
+ - `bun run coverage` prints the AG-UI x Carbon matrix and exits nonzero on any gap
11
18
 
12
19
  ## Run
13
20
 
14
21
  ```bash
15
- npm install
16
- npm run check # typecheck + tests
17
- npm run build # dist/
22
+ bun install
23
+ bun run check # typecheck + tests
24
+ bun run coverage # AG-UI x Carbon coverage matrix; must exit 0
25
+ bun run build # dist/
18
26
  ```
19
27
 
20
28
  ## Use
21
29
 
22
30
  ```ts
23
- import { createAgUiSendMessage, createSseRunner } from 'carbon-agui-adapter';
31
+ import { createAgUiSendMessage, createSseRunner } from '@hsb3/carbon-agui-adapter';
24
32
 
25
33
  const config = {
26
34
  messaging: {
@@ -46,7 +54,7 @@ Using `@ag-ui/client` instead of raw SSE:
46
54
 
47
55
  ```ts
48
56
  import { HttpAgent } from '@ag-ui/client';
49
- import { fromObservable } from 'carbon-agui-adapter';
57
+ import { fromObservable } from '@hsb3/carbon-agui-adapter';
50
58
 
51
59
  const agent = new HttpAgent({ url: 'https://my-agent/run' });
52
60
  const run = (input, { signal }) => fromObservable(agent.run(input), signal);
@@ -66,7 +74,7 @@ const run = (input, { signal }) => fromObservable(agent.run(input), signal);
66
74
  | `RUN_FINISHED` (no outcome) / stream end / abort | `final_response` (aborted text gets `stream_stopped: true`) |
67
75
  | `RUN_FINISHED` with `outcome.type === 'interrupt'` | `user_defined` decision item (`InterruptDecisionData`); interrupt retained for resume |
68
76
  | `MESSAGES_SNAPSHOT` with a new assistant message | rendered as a `text` item (covers non-streaming graphs, e.g. a resume continuation) |
69
- | `RUN_STARTED`, `STEP_*`, `RAW`, `CUSTOM` | `onEvent` only |
77
+ | `RUN_STARTED`, `STEP_*`, `SUBAGENT_*`, `RAW`, `CUSTOM` | `onEvent` only |
70
78
 
71
79
  ## HITL: interrupt → approve/reject/edit → resume
72
80
 
package/dist/adapter.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AgUiContext, AgUiEvent, AgUiMessage, AgUiRunner, AgUiTool, CarbonChatInstanceLike, CarbonCustomSendMessage, CarbonGenericItem, CarbonMessageFeedbackOptions, CarbonMessageRequest, Decision, Interrupt, JsonPatchOp, RunAgentInput, RunOutcome } from './types.js';
1
+ import type { AgUiContext, AgUiEvent, AgUiMessage, AgUiRunner, AgUiTool, CarbonChatInstanceLike, CarbonCustomSendMessage, CarbonGenericItem, CarbonMessageFeedbackOptions, CarbonMessageRequest, CarbonSendMessageOptions, Decision, Interrupt, JsonPatchOp, RunAgentInput, RunOutcome } from './types.js';
2
2
  export interface ToolCallInfo {
3
3
  id: string;
4
4
  name: string;
@@ -88,8 +88,10 @@ export declare class CarbonAgUiAdapter {
88
88
  *
89
89
  * @param instance The Carbon instance to stream into. Defaults to the one
90
90
  * from the most recent run (e.g. the interrupted turn).
91
+ * @param options Forwarded to the runner — pass `signal` so the host's stop
92
+ * control can abort the resumed continuation like a normal send.
91
93
  */
92
- respondToInterrupt(decision: Decision, instance?: CarbonChatInstanceLike): Promise<void>;
94
+ respondToInterrupt(decision: Decision, instance?: CarbonChatInstanceLike, options?: CarbonSendMessageOptions): Promise<void>;
93
95
  private upsertMessage;
94
96
  private handle;
95
97
  /**
package/dist/adapter.js CHANGED
@@ -58,8 +58,10 @@ export class CarbonAgUiAdapter {
58
58
  *
59
59
  * @param instance The Carbon instance to stream into. Defaults to the one
60
60
  * from the most recent run (e.g. the interrupted turn).
61
+ * @param options Forwarded to the runner — pass `signal` so the host's stop
62
+ * control can abort the resumed continuation like a normal send.
61
63
  */
62
- async respondToInterrupt(decision, instance) {
64
+ async respondToInterrupt(decision, instance, options = {}) {
63
65
  const interrupt = this.pendingInterrupt;
64
66
  if (!interrupt)
65
67
  throw new Error('respondToInterrupt: no pending interrupt');
@@ -77,7 +79,7 @@ export class CarbonAgUiAdapter {
77
79
  forwardedProps: this.opts.forwardedProps ?? {},
78
80
  resume: [decisionToResumeEntry(decision, interrupt.id)],
79
81
  };
80
- await this.runAndStream(input, {}, target);
82
+ await this.runAndStream(input, options, target);
81
83
  }
82
84
  upsertMessage(msg) {
83
85
  const i = this.messages.findIndex((m) => m.id === msg.id);
@@ -372,7 +374,7 @@ export class CarbonAgUiAdapter {
372
374
  }
373
375
  break;
374
376
  default:
375
- // RUN_STARTED / STEP_* / RAW / other CUSTOM: surfaced via onEvent only.
377
+ // RUN_STARTED / STEP_* / SUBAGENT_* / RAW / other CUSTOM: surfaced via onEvent only.
376
378
  break;
377
379
  }
378
380
  }
package/dist/coverage.js CHANGED
@@ -23,6 +23,9 @@ export const AG_UI_COVERAGE = {
23
23
  RUN_ERROR: { status: 'handled', note: 'Thrown as AgUiRunError.' },
24
24
  STEP_STARTED: { status: 'observed', note: 'Lifecycle; onEvent only.' },
25
25
  STEP_FINISHED: { status: 'observed', note: 'Lifecycle; onEvent only.' },
26
+ SUBAGENT_STARTED: { status: 'observed', note: 'Lifecycle; onEvent only.' },
27
+ SUBAGENT_FINISHED: { status: 'observed', note: 'Lifecycle; onEvent only.' },
28
+ SUBAGENT_ERROR: { status: 'observed', note: 'Lifecycle; onEvent only (distinct from top-level RUN_ERROR, which throws).' },
26
29
  TEXT_MESSAGE_START: { status: 'handled', note: 'Opens a streamed text item.' },
27
30
  TEXT_MESSAGE_CONTENT: { status: 'handled', note: 'Partial text chunk.' },
28
31
  TEXT_MESSAGE_END: { status: 'handled', note: 'Completes the text item.' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hsb3/carbon-agui-adapter",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Adapter that drives IBM Carbon AI Chat from an AG-UI event stream",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "build": "tsc -p tsconfig.build.json"
31
31
  },
32
32
  "dependencies": {
33
- "@ag-ui/core": "0.0.58"
33
+ "@ag-ui/core": "0.0.59"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@carbon/ai-chat": "1.19.0",