@nseng-ai/ns 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.
@@ -0,0 +1,139 @@
1
+ import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
2
+
3
+ // ../../infra/foundation/src/primitives/primitives.ts
4
+ function optionalEntries(entries) {
5
+ return Object.fromEntries(
6
+ Object.entries(entries).filter(([, value]) => value !== void 0)
7
+ );
8
+ }
9
+ function optionalEntry(key, value) {
10
+ return optionalEntries({ [key]: value });
11
+ }
12
+
13
+ // ../../kernel/src/sdk/schema.ts
14
+ import { z } from "zod";
15
+
16
+ // ../../kernel/src/sdk/extension-manifest.ts
17
+ var nsExtensionManifestCommandSchema = z.looseObject({
18
+ name: z.string().optional(),
19
+ path: z.array(z.string()).optional(),
20
+ group: z.string().optional(),
21
+ description: z.string().optional(),
22
+ fullDescription: z.string().optional(),
23
+ entry: z.string().optional()
24
+ });
25
+ var nsExtensionManifestSchema = z.looseObject({
26
+ description: z.string().optional(),
27
+ group: z.string().optional(),
28
+ commands: z.array(z.unknown()).optional()
29
+ });
30
+ var nsExtensionPackageManifestSchema = z.looseObject({
31
+ description: z.string().optional(),
32
+ ns: nsExtensionManifestSchema.optional()
33
+ });
34
+
35
+ // ../../kernel/src/sdk/services.ts
36
+ var noopNsCommandIo = {
37
+ phase: () => {
38
+ },
39
+ notify: () => {
40
+ },
41
+ message: () => {
42
+ },
43
+ clearPhase: () => {
44
+ }
45
+ };
46
+ var noopNsProgress = {
47
+ phase: () => {
48
+ }
49
+ };
50
+
51
+ // ../../kernel/src/runtime/command-io.ts
52
+ async function runWithNsCommandIo(io, fn) {
53
+ try {
54
+ return await fn(io);
55
+ } finally {
56
+ io.clearPhase();
57
+ }
58
+ }
59
+ function createCliCommandIo(input, options = {}) {
60
+ const onOutput = input.onOutput;
61
+ const io = createCommandIo({
62
+ ...optionalEntries({
63
+ phaseTransient: onOutput === void 0 ? void 0 : (text) => onOutput("stderr", text),
64
+ phaseFallback: input.stderr,
65
+ notifyInfo: input.stdout,
66
+ notifyDiagnostic: input.stderr,
67
+ shouldSuppress: options.shouldSuppress
68
+ })
69
+ });
70
+ const onNotifyError = options.onNotifyError;
71
+ if (onNotifyError === void 0) return io;
72
+ return {
73
+ ...io,
74
+ notify: (message, level = "info") => {
75
+ if (level === "error") onNotifyError();
76
+ io.notify(message, level);
77
+ }
78
+ };
79
+ }
80
+ function createCommandIo(channels) {
81
+ function phase(message2) {
82
+ if (channels.shouldSuppress === true) return;
83
+ if (channels.phaseSticky !== void 0) {
84
+ channels.phaseSticky(message2);
85
+ return;
86
+ }
87
+ const line = `${message2}
88
+ `;
89
+ if (channels.phaseTransient !== void 0) {
90
+ channels.phaseTransient(line);
91
+ return;
92
+ }
93
+ channels.phaseFallback?.(line);
94
+ }
95
+ function notify(message2, level = "info") {
96
+ if (channels.notifyUi !== void 0) {
97
+ channels.notifyUi(message2, level);
98
+ return;
99
+ }
100
+ const line = `${message2.trimEnd()}
101
+ `;
102
+ if (level === "info" && channels.shouldSuppress !== true) {
103
+ channels.notifyInfo?.(line);
104
+ return;
105
+ }
106
+ channels.notifyDiagnostic?.(line);
107
+ }
108
+ function message(text, options = {}) {
109
+ const level = options.level ?? "info";
110
+ if (channels.richMessage !== void 0) {
111
+ channels.richMessage(text, {
112
+ level,
113
+ ...optionalEntry("details", options.details)
114
+ });
115
+ return;
116
+ }
117
+ if (options.isRichOnly === true) return;
118
+ phase(text);
119
+ }
120
+ function clearPhase() {
121
+ channels.phaseSticky?.(void 0);
122
+ }
123
+ return { phase, notify, message, clearPhase };
124
+ }
125
+ function commandIoFromNsExtensionApi(ctx, options = {}) {
126
+ if (options.shouldSuppress === void 0) return ctx.commandIo;
127
+ return createCliCommandIo(
128
+ optionalEntries({ stdout: ctx.stdout, stderr: ctx.stderr, onOutput: ctx.onOutput }),
129
+ { shouldSuppress: options.shouldSuppress }
130
+ );
131
+ }
132
+ export {
133
+ commandIoFromNsExtensionApi,
134
+ createCliCommandIo,
135
+ createCommandIo,
136
+ noopNsCommandIo,
137
+ noopNsProgress,
138
+ runWithNsCommandIo
139
+ };