@silverprotocol/claude-agent-sdk 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Loqu, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @silverprotocol/claude-agent-sdk
2
+
3
+ AgJSON normalizer for the Claude Agent SDK (`SDKMessage` → `AgEvent[]`) — the
4
+ live path.
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ npm install @silverprotocol/claude-agent-sdk
10
+ ```
11
+
12
+ `@silverprotocol/core` is a required peer (installed automatically as a
13
+ dependency). `@anthropic-ai/claude-agent-sdk` is an optional peer — only
14
+ needed if you want its types alongside this package's own `SDKMessage`
15
+ guards; it is not required at import time.
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { createClaudeNormalizer } from "@silverprotocol/claude-agent-sdk";
21
+
22
+ const n = createClaudeNormalizer();
23
+ const events = [];
24
+ for (const native of stream) events.push(...n.push(native));
25
+ events.push(...n.flush());
26
+ ```
27
+
28
+ `stream` is whatever async/sync iterable of `SDKMessage` your Claude Agent
29
+ SDK run yields. `push()` returns the `AgEvent[]` synthesized from that native
30
+ message; `flush()` drains any buffered end-of-stream state. Malformed input
31
+ never throws — it routes through the lossless `ext.anthropic.unparsed`
32
+ channel instead.
33
+
34
+ Spec: `SPEC.md` at the repo root of [silverprotocol/typescript-sdk](https://github.com/silverprotocol/typescript-sdk) (published with the first
35
+ release); wire version `1.0.0-draft.1`.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * `@silverprotocol/claude-agent-sdk` — the LIVE-path normalizer (stateful facet).
3
+ *
4
+ * Translates the public Claude Agent SDK `SDKMessage` union (the run-seam yields
5
+ * these; see guuey `backend/services/nocode-runtime/src/code-worker.ts`) into
6
+ * AgJSON events (`AgEvent[]`, spec §4) by driving a shared {@link StreamAssembler}
7
+ * via primitive calls. Claude's assistant turn is a COMPLETE-message structure —
8
+ * `message.content[]` is the whole turn's content, not a stream of deltas — so the
9
+ * per-block fan-out is a TS function (clearer than pure JSONata).
10
+ *
11
+ * The engine owns sequencing and turn assembly: it synthesizes a `turn.start` at
12
+ * the head of each unseen TOP-LEVEL turn (`openMessage` → `#ensureTurn`), backfills
13
+ * `turnId` onto content/tool events from the owning message, and allocates a
14
+ * turn-scoped monotonic `seq`. A NESTED (`parent_tool_use_id`) assistant message is
15
+ * seeded by `subagentStart`, so the engine does NOT synthesize a `turn.start` for it.
16
+ *
17
+ * `push(native)` structurally guards `native` → `SDKMessage`; on a guard failure it
18
+ * routes the raw payload through the lossless `ext.anthropic.unparsed` channel and
19
+ * returns — graceful, never throws (Tenet 6). Stable ids derive from the SDK ids
20
+ * (`message.id`, block `id`, `tool_use_id`).
21
+ */
22
+ import type { SDKMessage } from "@anthropic-ai/claude-agent-sdk";
23
+ import { type AgFinishReason, type Normalizer } from "@silverprotocol/core";
24
+ type SDKAssistant = Extract<SDKMessage, {
25
+ type: "assistant";
26
+ }>;
27
+ type BetaMessageT = SDKAssistant["message"];
28
+ type BetaStopReason = NonNullable<BetaMessageT["stop_reason"]>;
29
+ declare function mapStopReason(stop: BetaStopReason | string | null): AgFinishReason;
30
+ /**
31
+ * Build a stateful Claude-facet normalizer over a fresh {@link StreamAssembler}.
32
+ * Each `push(native)` validates `native` → `SDKMessage`, drives the engine via
33
+ * primitive calls, and drains the buffered `AgEvent[]`. `flush()` closes any
34
+ * dangling open message (none, in Claude's complete-message model) and drains.
35
+ */
36
+ export declare function createClaudeNormalizer(): Normalizer;
37
+ export default createClaudeNormalizer;
38
+ export { mapStopReason };
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAGL,KAAK,cAAc,EAQnB,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAC;AAO9B,KAAK,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AAE/D,KAAK,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;AAE5C,KAAK,cAAc,GAAG,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC;AAwB/D,iBAAS,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,GAAG,cAAc,CAwB3E;AA0aD;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,UAAU,CAqYnD;AAED,eAAe,sBAAsB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,CAAC"}