@huanlin/dsh-plugin-aigc-canvas 0.1.0 → 0.1.2

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.
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Serializable configuration and defaults for the AIGC canvas host half.
3
+ * The `providers` array holds one or more AIGC provider configs (name /
4
+ * endpoint / apiKey / instructions), editable at runtime through the DSH
5
+ * GUI settings page; cordis.yml `config:` is the first-boot seed only.
6
+ *
7
+ * @module @dsh-external/dsh-aigc-canvas/config
8
+ */
9
+ import z from 'schemastery';
10
+ /** Provider id pattern: lowercase letters, digits, hyphens; must start with a letter. */
11
+ export declare const PROVIDER_ID_PATTERN: RegExp;
12
+ /** How the aigc_http_request tool attaches the provider apiKey to requests. */
13
+ export interface AigcProviderAuth {
14
+ /**
15
+ * Auth scheme:
16
+ * - `bearer`: `Authorization: Bearer <apiKey>` (the default)
17
+ * - `header`: `<name>: <apiKey>` (name defaults to `x-api-key`)
18
+ * - `query`: `<name>=<apiKey>` URL query parameter (name defaults to `api_key`)
19
+ */
20
+ scheme?: 'bearer' | 'header' | 'query';
21
+ /** Header name (scheme=header) or query param name (scheme=query). Ignored for bearer. */
22
+ name?: string;
23
+ }
24
+ /** Resolved auth config (every field guaranteed). */
25
+ export interface ResolvedAigcProviderAuth {
26
+ scheme: 'bearer' | 'header' | 'query';
27
+ name: string;
28
+ }
29
+ /** One AIGC provider configuration (editable at runtime via the settings page). */
30
+ export interface AigcProvider {
31
+ /** Stable identifier (lowercase, hyphenated); used as the `provider_id` tool param. */
32
+ id: string;
33
+ /** Provider display name (e.g. "Volcano Engine", "Jimeng", "MiniMax"). */
34
+ name: string;
35
+ /** Provider API endpoint URL. `stub://aigc-backend` = the built-in stub. */
36
+ endpoint: string;
37
+ /** Provider API key (stored in memory only; set via GUI or cordis.yml). */
38
+ apiKey: string;
39
+ /** Free-form usage instructions the agent reads via aigc_get_provider_info. */
40
+ instructions: string;
41
+ /** How the http tool attaches the apiKey (default: Authorization: Bearer). */
42
+ auth?: AigcProviderAuth;
43
+ /** Whether this provider is a builtin seed (cordis.yml); user-added providers are never builtin. */
44
+ builtin?: boolean;
45
+ }
46
+ /** Tunable AIGC canvas host settings (every field optional; defaults fill in). */
47
+ export interface AigcCanvasConfig {
48
+ /** One or more AIGC providers; the first is the default. */
49
+ providers?: AigcProvider[];
50
+ /** Per-request timeout for backend calls (ms). */
51
+ requestTimeoutMs?: number;
52
+ /** Maximum media bytes to write to disk per generated asset. */
53
+ mediaSizeLimit?: number;
54
+ }
55
+ /** Schemastery schema for the plugin configuration. */
56
+ export declare const Config: z<AigcCanvasConfig>;
57
+ /** A fully-resolved provider (all fields guaranteed). */
58
+ export interface ResolvedAigcProvider extends AigcProvider {
59
+ name: string;
60
+ endpoint: string;
61
+ apiKey: string;
62
+ instructions: string;
63
+ auth: ResolvedAigcProviderAuth;
64
+ builtin: boolean;
65
+ }
66
+ /** Fully defaulted settings consumed by the host half. */
67
+ export interface ResolvedAigcConfig {
68
+ readonly providers: readonly ResolvedAigcProvider[];
69
+ requestTimeoutMs: number;
70
+ mediaSizeLimit: number;
71
+ }
72
+ /** Returns true when the provider endpoint points at the built-in stub backend. */
73
+ export declare function isStubEndpoint(endpoint: string): boolean;
74
+ /** Validate a provider id; returns an error message or undefined if valid. */
75
+ export declare function validateProviderId(id: string): string | undefined;
76
+ /** Apply direct-call defaults after Loader schema validation has normally run. */
77
+ export declare function resolveAigcConfig(config: AigcCanvasConfig | undefined): ResolvedAigcConfig;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Structural types for the cordis services this plugin consumes, plus the
3
+ * Context augmentation both halves share. A third-party plugin resolves
4
+ * outside the DSH monorepo's single cordis instance, so the upstream
5
+ * `declare module 'cordis'` augmentations do not reach this Context — and
6
+ * the npm cordis package does not declare the DSH-vendored runtime members
7
+ * (`ctx.effect`, the httpServer/sessions/loader faces). The members below
8
+ * mirror the actual runtime shapes this plugin touches:
9
+ *
10
+ * - httpServer: @deepseek-ai/dsh-host-webserver
11
+ * - sessions: @deepseek-ai/dsh-session (host side)
12
+ * - loader: @cordisjs/plugin-loader (entry options)
13
+ * - invariants: @deepseek-ai/dsh-invariants
14
+ * - effect: the DSH-vendored cordis lifecycle helper
15
+ *
16
+ * Drift from upstream is contained to this file.
17
+ */
18
+ import type { IncomingMessage, ServerResponse } from 'node:http';
19
+ import type { Duplex } from 'node:stream';
20
+ import type { Context } from 'cordis';
21
+ import type { AigcCanvasService } from './canvas-registry.js';
22
+ /** One named webserver route (mirror of the host-webserver WebRoute). */
23
+ export interface AigcWebRoute {
24
+ kind: 'exact' | 'prefix';
25
+ path: string;
26
+ handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
27
+ }
28
+ /** One exact-path HTTP upgrade registration (mirror of WebUpgradeRoute). */
29
+ export interface AigcWebUpgradeRoute {
30
+ path: string;
31
+ handler: (req: IncomingMessage, socket: Duplex, head: Buffer) => void | Promise<void>;
32
+ }
33
+ /** The httpServer service face this plugin uses. */
34
+ export interface AigcHttpServer {
35
+ register(route: AigcWebRoute): () => void;
36
+ registerUpgrade(route: AigcWebUpgradeRoute): () => void;
37
+ }
38
+ /** A published session's header slice (authoritative cwd). */
39
+ export interface AigcSessionHeader {
40
+ cwd?: string;
41
+ }
42
+ /** The host session store face (`ctx.sessions.get(id)` returns the live session). */
43
+ export interface AigcSessionStore {
44
+ get(id: string): {
45
+ header: AigcSessionHeader;
46
+ } | undefined;
47
+ }
48
+ /**
49
+ * The minimal Agent face this plugin uses for context injection.
50
+ * Mirrors `@deepseek-ai/dsh-agent`'s `Agent.inject()` — see the DSH
51
+ * agent loop's inbox/splice path. The plugin calls `inject()` to push
52
+ * a notice into the agent's next-step context (non-waking).
53
+ */
54
+ export interface AigcAgent {
55
+ readonly id: string;
56
+ inject(message: AigcUserMessage): void;
57
+ }
58
+ /** A minimal user-role message for agent.inject (mirrors dsh-llm's UserMessage). */
59
+ export interface AigcUserMessage {
60
+ readonly id: string;
61
+ readonly role: 'user';
62
+ readonly content: ReadonlyArray<{
63
+ type: 'text';
64
+ text: string;
65
+ }>;
66
+ readonly source: {
67
+ readonly kind: 'plugin';
68
+ readonly plugin: string;
69
+ readonly form?: 'notice';
70
+ readonly summary?: string;
71
+ };
72
+ }
73
+ /** The agents registry face (`ctx.agents.get(sessionId)` returns the live agent). */
74
+ export interface AigcAgentRegistry {
75
+ get(id: string): AigcAgent | undefined;
76
+ }
77
+ /** One loader entry's options slice (the connection row's resolved config). */
78
+ export interface AigcLoaderEntry {
79
+ options: {
80
+ name: string;
81
+ config?: unknown;
82
+ };
83
+ }
84
+ /** The loader face used to read the connection row's trustedHosts config. */
85
+ export interface AigcLoader {
86
+ entries(): Iterable<AigcLoaderEntry>;
87
+ }
88
+ /** The invariants service face (mirror of @deepseek-ai/dsh-invariants). */
89
+ export interface AigcInvariantsService {
90
+ register(packageName: string, installer: (ctx: Context, fail: (message: string) => never) => void | Promise<void>): () => void;
91
+ }
92
+ /**
93
+ * The invariant service face restated (mirror of @deepseek-ai/dsh-invariants).
94
+ * Mirrored here exactly like better-sidebar does — the dual-cordis-instance
95
+ * resolution otherwise hides the upstream augmentation. The `tools` service
96
+ * face is declared in `./types.d.ts` (the ambient cordis module augmentation)
97
+ * and not restated here to avoid a "subsequent property declarations must
98
+ * have the same type" error.
99
+ */
100
+ export interface AigcToolsService {
101
+ register(tool: unknown): () => void;
102
+ }
103
+ declare module 'cordis' {
104
+ interface Context {
105
+ httpServer: AigcHttpServer;
106
+ sessions: AigcSessionStore;
107
+ agents: AigcAgentRegistry;
108
+ loader: AigcLoader;
109
+ invariants: AigcInvariantsService;
110
+ /**
111
+ * The host-side AIGC canvas registry: holds the per-session element
112
+ * table (prompts + generated assets) and edges. Provided by the host
113
+ * half (see {@link ./canvas-registry.ts}); undefined on the client.
114
+ */
115
+ aigcCanvas: AigcCanvasService;
116
+ /** Register a lifecycle callback (DSH-vendored cordis). */
117
+ effect(fn: () => void | (() => void), label?: string): void;
118
+ }
119
+ }
120
+ export type { Context };
package/lib/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { Context } from './context-types.js';
2
+ import { Config, type AigcCanvasConfig, type AigcProvider, type ResolvedAigcConfig, type ResolvedAigcProvider } from './config.js';
3
+ export { Config };
4
+ export type { AigcCanvasConfig, AigcProvider, ResolvedAigcConfig, ResolvedAigcProvider };
5
+ export type { Context } from './context-types.js';
6
+ export type { AigcCanvasService, AigcElement, AigcEdge, AigcCanvasState, AigcElementKind, } from './canvas-registry.js';
7
+ /** Plugin identity for cordis.yml rows. */
8
+ export declare const name = "dsh-aigc-canvas";
9
+ /** Services required before mounting. */
10
+ export declare const inject: string[];
11
+ /** Plugin body. */
12
+ export declare function apply(ctx: Context, config?: AigcCanvasConfig): void;