@namzu/zen 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,61 @@
1
+ # @namzu/zen
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - c635b5a: Use `namzu --output-schema /absolute/path/schema.json` for native schema-constrained TUI answers. Unsupported or lossy schema conversion fails at launch; normal conversations remain unchanged. Supply the flag again on resume.
8
+
9
+ Enable native query admission for Codex, OpenRouter, DeepSeek, HTTP and Zen wire mappings. Codex forwards Responses text.format; HTTP maps schemas for both dialects. Zen messages requests use native format instead of hidden tool fallback, and Google requests preserve JSON Schema constraints. Endpoint/model support is still required and vendor errors remain errors.
10
+
11
+ Breaking for direct HTTP/Zen callers: an Anthropic-dialect response format can no longer be silently ignored or fall back to an output tool. Schema-free JSON and explicit strict:false are rejected. Use strict native JSON Schema on a capable model, or choose SDK structuredOutput.mode="tool" when native schema output is unavailable.
12
+
13
+ Anthropic transport retries now default to zero instead of the vendor SDK default of two. The host immediately receives classified HTTP 429 responses with Retry-After metadata instead of waiting invisibly inside the vendor client. Set AnthropicConfig.maxRetries to 2 to retain the former transport retry behavior.
14
+
15
+ Rate-limit guidance no longer claims automatic retries were exhausted when retry policy may have disabled them or refused the requested delay.
16
+
17
+ ### Minor Changes
18
+
19
+ - 0795da3: Add optional Zen and Zen Go providers for OpenCode's services using Namzu's
20
+ existing model contract. Exact service/model catalogue entries select Chat Completions,
21
+ Responses, Anthropic Messages or Google streaming transport. Tool
22
+ continuations, native reasoning metadata, conversation attribution,
23
+ cancellation and classified provider errors remain part of the normal
24
+ Namzu kernel lifecycle.
25
+
26
+ The CLI exposes Zen (`zen`) and Zen Go (`zen-go`) in provider selection and
27
+ headless runs. Zen supports anonymous public models and optional credentials;
28
+ Go requires its own key. The actual Namzu
29
+ conversation is retained for service attribution across turns and resume.
30
+ The driver requires Node.js 20+ and a supported public model, or a real key
31
+ with a known model or explicit protocol. Bundled prices are estimates;
32
+ unsupported controls and content combinations are refused.
33
+
34
+ - 4cac9ca: Enable Zen's current public models without requiring an account key or an
35
+ OpenCode installation. Anonymous SDK calls and the CLI's Zen default use
36
+ `muse-spark-1.3-contributor-free`. Omitted, blank or `public` Zen keys select
37
+ anonymous access, restricted to six explicitly supported free model IDs;
38
+ paid or unknown models still require a real key. The SDK keeps
39
+ `glm-5.3-flash` as the default for credentialed Zen and Go calls, and Go
40
+ continues to require its own API key.
41
+
42
+ The CLI uses environment keys first, then reuses separate `opencode` and
43
+ `opencode-go` API-key entries from `OPENCODE_AUTH_CONTENT` or OpenCode's
44
+ data-directory `auth.json`, including the paired Windows home on WSL when
45
+ no absolute XDG override is supplied.
46
+ It leaves that file unchanged and does not reinterpret OAuth records as
47
+ API keys. Explicit `OPENCODE_API_KEY=public` selects anonymous access and
48
+ suppresses secondary Zen key aliases and stored account keys. With no
49
+ credential, Zen appears as public access without a login
50
+ or key prompt. Public model availability and service limits remain under
51
+ the upstream service's control.
52
+
53
+ Expose `@namzu/zen/models` for catalogue functions and model types without
54
+ loading the four native transport adapters during provider selection.
55
+
56
+ Send `strict: false` for all Responses function tools so optional parameters,
57
+ including nested read/edit fields, remain optional. This fixes HTTP 400
58
+ schema rejection when a backend defaults omitted strictness to true.
59
+ Responses also declines the capability-dependent `enforceToolInputSchema`
60
+ hint for these general schemas; Namzu continues to validate inputs before
61
+ tool execution. Other protocols retain their existing enforcement behavior.
package/LICENSE.md ADDED
@@ -0,0 +1,110 @@
1
+ # Functional Source License, Version 1.1, MIT Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-MIT
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Cogitave
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the MIT license that is effective on the second anniversary of the date we make
91
+ the Software available. On or after that date, you may use the Software under
92
+ the MIT license, in which case the following will apply:
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
95
+ this software and associated documentation files (the "Software"), to deal in
96
+ the Software without restriction, including without limitation the rights to
97
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98
+ of the Software, and to permit persons to whom the Software is furnished to do
99
+ so, subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all
102
+ copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ <!-- okf
2
+ type: Reference
3
+ title: "@namzu/zen"
4
+ description: Zen and Zen Go model drivers for the Namzu kernel, with native protocol routing and conversation attribution.
5
+ tags: [readme, package, provider, opencode]
6
+ status: stable
7
+ -->
8
+
9
+ # @namzu/zen
10
+
11
+ Zen and Zen Go model drivers for [Namzu](https://github.com/cogitave/namzu),
12
+ connecting to OpenCode's Zen and Go services.
13
+ Both implement the SDK's existing `LLMProvider` interface. Namzu continues to
14
+ own the agent loop, tools, permissions, budgets, retries, persistence and
15
+ delegation.
16
+
17
+ Zen includes public models that work without an account key or an OpenCode
18
+ installation. Namzu defaults anonymous Zen calls to Muse Spark 1.3 Contributor
19
+ Free (`muse-spark-1.3-contributor-free`). Zen Go still requires its own API key.
20
+
21
+ ```bash
22
+ pnpm add @namzu/sdk @namzu/zen zod@^3
23
+ ```
24
+
25
+ Requires Node.js 20+ and `@namzu/sdk >=36.0.0`. The optional package uses the
26
+ official AI SDK provider adapters directly through `LanguageModelV3.doStream`;
27
+ it does not depend on the `ai` orchestration package or another Namzu provider.
28
+
29
+ ```ts
30
+ import { generateSessionId, runAgent } from '@namzu/sdk'
31
+ import { ZenProvider } from '@namzu/zen'
32
+
33
+ const sessionId = generateSessionId()
34
+ const provider = new ZenProvider({ sessionId })
35
+ const { output, run, identity } = await runAgent({
36
+ provider,
37
+ model: 'muse-spark-1.3-contributor-free',
38
+ sessionId,
39
+ prompt: 'Explain what an agent kernel does.',
40
+ maxIterations: 4,
41
+ })
42
+
43
+ console.log(output)
44
+ console.log(run.stopReason)
45
+ console.log(identity)
46
+ ```
47
+
48
+ This example makes a public model request without an account key. For paid
49
+ Zen models, pass `apiKey`. For Go, use `ZenGoProvider` with its API key.
50
+ SDK constructors do not read environment variables or credential files;
51
+ that lookup belongs to the application or CLI.
52
+ Keep one provider instance per conversation, and reuse its `sessionId`
53
+ after restart. The CLI passes the actual Namzu conversation ID, including
54
+ across resume and compaction.
55
+
56
+ ## Service and protocol selection
57
+
58
+ | Service | Registry type | Default base URL | CLI environment |
59
+ | --- | --- | --- | --- |
60
+ | Zen | `zen` | `https://opencode.ai/zen/v1` | `OPENCODE_API_KEY`, then `OPENCODE_ZEN_API_KEY` |
61
+ | Zen Go (Go service) | `zen-go` | `https://opencode.ai/zen/go/v1` | `OPENCODE_GO_API_KEY` |
62
+
63
+ The SDK defaults anonymous Zen calls to `muse-spark-1.3-contributor-free`;
64
+ Zen with a real key and Go default to `glm-5.3-flash`. The CLI's default Zen
65
+ model is the free Muse model. Routes are selected from the exact service
66
+ and model ID: `chat` uses Chat Completions, `responses` uses Responses,
67
+ `messages` uses Anthropic Messages, and `google` uses streaming
68
+ `generateContent`. The same model family can use different wires on Zen
69
+ and Go. Unknown IDs require an explicit `protocol` configuration; model
70
+ names are never used to guess a wire format. Anonymous access is restricted
71
+ to six explicitly supported public model IDs; a protocol override does not
72
+ grant access to paid or unknown models.
73
+
74
+ A missing, blank or `public` Zen `apiKey` selects anonymous access. Public
75
+ availability and service limits can change. For credentialed access, the CLI
76
+ uses the environment variables above first, then reads OpenCode API-key
77
+ entries from `OPENCODE_AUTH_CONTENT` when set, otherwise from
78
+ `$XDG_DATA_HOME/opencode/auth.json` for an absolute XDG path or
79
+ `~/.local/share/opencode/auth.json`. Without an absolute XDG override, WSL
80
+ can also reuse the paired Windows home's file. It maps `opencode` to Zen and
81
+ `opencode-go` to Go separately, ignores OAuth entries, and never changes the
82
+ owner's file. With no key, Zen remains available as a public provider and
83
+ does not require a login or key prompt.
84
+
85
+ `ZenConfig` accepts `apiKey`, `sessionId`, `model`, `baseURL`, `timeout`
86
+ and `protocol`, all optional. `ZenGoConfig` requires `apiKey` for Go.
87
+ Timeout defaults to 120,000 milliseconds. A missing
88
+ `sessionId` generates an ID once per instance. Every request carries
89
+ `x-opencode-session` plus Namzu's current attribution headers.
90
+
91
+ Registry-based applications call `registerZen()` and/or
92
+ `registerZenGo()` once, then use `ProviderRegistry.create()` with the
93
+ corresponding discriminated config. The package also exports
94
+ `getZenModels(service)`, `findZenModel(service, id)`,
95
+ `ZEN_BASE_URL`, `ZEN_GO_BASE_URL`, and `ZEN_CAPABILITIES`.
96
+ The `@namzu/zen/models` subpath exposes the catalogue functions and model
97
+ types without loading the native transport adapters.
98
+
99
+ ## History, controls and limits
100
+
101
+ Text, ordinary tools, inline images and documents use the SDK message
102
+ contract. Signed reasoning, encrypted Responses items and Gemini thought
103
+ signatures retain native ordering in versioned replay state. Replay requires
104
+ the original configured route, service, protocol, model, history prefix,
105
+ and unchanged durable assistant text, calls and reasoning. A changed route
106
+ or compacted history uses portable text/tool history without foreign native
107
+ reasoning.
108
+
109
+ Unsupported controls and histories are refused. In particular, unresolved
110
+ stored attachments must be materialized first, document citation requests
111
+ are unsupported, Chat Completions cannot carry rich tool results, and a
112
+ failed rich tool result cannot preserve both visual content and failure
113
+ status through this adapter API. Messages tool documents must be PDFs.
114
+ Images explicitly marked with a valid durable `modelOmission` are omitted.
115
+ Failed text results retain a native error flag on Messages and an explicit
116
+ failure marker on the other wires.
117
+ Provider-executed tools and generated-file output are unsupported.
118
+
119
+ Reasoning effort levels come from the selected model's catalogue entry;
120
+ an empty list means no selectable effort control. Thinking and sampling
121
+ controls also depend on the wire. See the [SDK guide](../../../docs/sdk/zen.md)
122
+ for configuration and refusal details.
123
+
124
+ `listModels(signal?)` intersects the live service catalogue with supported
125
+ bundled models and restricts anonymous results to the explicit public set.
126
+ Static limits and USD-per-million-token prices are a pinned
127
+ snapshot, not an invoice: context tiers, caches, Go peak/off-peak rates,
128
+ subscription allowances and promotions can change the effective charge.
129
+
130
+ Tests use the real provider adapters with local HTTP/SSE fixtures, including
131
+ tool continuations, signatures, cancellation and error classification.
132
+ An SDK kernel test executes a registered tool and feeds its result into the
133
+ next model request before completing the run.
134
+ On 2026-09-08, live text inference on `muse-spark-1.3-contributor-free`
135
+ succeeded without an account key through installed OpenCode and Namzu's
136
+ driver. A live Namzu `run-stream` call with low effort and production tools
137
+ also read `verification.txt`, then returned its exact nonce, absent from
138
+ the prompt, after two model requests. The read succeeded and the run ended
139
+ with `end_turn`. This validates that model's public text and file-tool path;
140
+ it does not establish every public or paid model, Go access, or billing.
141
+
142
+ FSL-1.1-MIT, converting to MIT two years after each release.
@@ -0,0 +1,30 @@
1
+ import { type ChatCompletionParams, type LLMProvider, type ModelInfo, type ProviderCapabilities, type ReasoningEffort, type StreamChunk, type ThinkingConfig } from '@namzu/sdk';
2
+ import { type ZenService } from './models.js';
3
+ import type { ZenConfig, ZenGoConfig } from './types.js';
4
+ export declare const ZEN_CAPABILITIES: ProviderCapabilities;
5
+ export declare const ZEN_BASE_URL = "https://opencode.ai/zen/v1";
6
+ export declare const ZEN_GO_BASE_URL = "https://opencode.ai/zen/go/v1";
7
+ /** A provider instance belongs to one conversation; it never owns an agent loop. */
8
+ export declare class ZenProvider implements LLMProvider {
9
+ private readonly config;
10
+ readonly service: ZenService;
11
+ readonly id: 'zen' | 'zen-go';
12
+ readonly name: string;
13
+ readonly capabilities: ProviderCapabilities;
14
+ readonly sessionId: string;
15
+ private readonly baseURL;
16
+ private readonly timeout;
17
+ private readonly requestFetch;
18
+ private readonly apiKey;
19
+ private readonly anonymous;
20
+ constructor(config?: ZenConfig, service?: ZenService);
21
+ chatStream(params: ChatCompletionParams): AsyncIterable<StreamChunk>;
22
+ listModels(signal?: AbortSignal): Promise<ModelInfo[]>;
23
+ reasoningEffortLevelsFor(model: string, _thinking?: ThinkingConfig): readonly ReasoningEffort[] | undefined;
24
+ resolveContextWindow(model: string, signal?: AbortSignal): Promise<number | undefined>;
25
+ private failure;
26
+ }
27
+ export declare class ZenGoProvider extends ZenProvider {
28
+ constructor(config: ZenGoConfig);
29
+ }
30
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAaA,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,oBAAoB,EAEzB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,cAAc,EAMnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,aAAa,CAAA;AAG3D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAA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