@neta-art/cohub-cli 10.28.1 → 10.29.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 +8 -0
- package/dist/board-gpu/page.js +189 -141
- package/dist/build.json +1 -1
- package/dist/chunks/{Geometry.js → FilterPipe.js} +12377 -11608
- package/dist/chunks/board-kernel.js +16815 -16466
- package/dist/chunks/browserAll.js +83 -43
- package/dist/chunks/client.js +8 -5
- package/dist/chunks/id.js +20 -4
- package/dist/chunks/init.js +97 -99
- package/dist/chunks/spaces.js +54 -9
- package/dist/chunks/webworkerAll.js +1 -1
- package/package.json +3 -3
package/dist/chunks/init.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region ../../node_modules/.pnpm/pixi.js@8.
|
|
1
|
+
import { J as Texture, K as Bounds, N as TexturePool, W as warn, _ as UniformGroup, a as getGlobalRenderableBounds, b as GlProgram, ct as Matrix, f as Filter, ft as ExtensionType, g as BindGroup, h as RendererType, l as Geometry, n as vertex, pt as extensions, r as CanvasFilterSystem, t as FilterPipe, v as GpuProgram } from "./FilterPipe.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.23.0/node_modules/pixi.js/lib/filters/defaults/passthrough/passthrough.frag.mjs
|
|
3
3
|
var fragment = "in vec2 vTextureCoord;\nout vec4 finalColor;\nuniform sampler2D uTexture;\nvoid main() {\n finalColor = texture(uTexture, vTextureCoord);\n}\n";
|
|
4
4
|
//#endregion
|
|
5
|
-
//#region ../../node_modules/.pnpm/pixi.js@8.
|
|
5
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.23.0/node_modules/pixi.js/lib/filters/defaults/passthrough/passthrough.wgsl.mjs
|
|
6
6
|
var source = "struct GlobalFilterUniforms {\n uInputSize: vec4<f32>,\n uInputPixel: vec4<f32>,\n uInputClamp: vec4<f32>,\n uOutputFrame: vec4<f32>,\n uGlobalFrame: vec4<f32>,\n uOutputTexture: vec4<f32>,\n};\n\n@group(0) @binding(0) var <uniform> gfu: GlobalFilterUniforms;\n@group(0) @binding(1) var uTexture: texture_2d<f32>;\n@group(0) @binding(2) var uSampler: sampler;\n\nstruct VSOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) uv: vec2<f32>\n};\n\nfn filterVertexPosition(aPosition: vec2<f32>) -> vec4<f32>\n{\n var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;\n\n position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;\n position.y = position.y * (2.0 * gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;\n\n return vec4(position, 0.0, 1.0);\n}\n\nfn filterTextureCoord(aPosition: vec2<f32>) -> vec2<f32>\n{\n return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);\n}\n\n@vertex\nfn mainVertex(\n @location(0) aPosition: vec2<f32>,\n) -> VSOutput {\n return VSOutput(\n filterVertexPosition(aPosition),\n filterTextureCoord(aPosition)\n );\n}\n\n@fragment\nfn mainFragment(\n @location(0) uv: vec2<f32>,\n) -> @location(0) vec4<f32> {\n return textureSample(uTexture, uSampler, uv);\n}\n";
|
|
7
7
|
//#endregion
|
|
8
|
-
//#region ../../node_modules/.pnpm/pixi.js@8.
|
|
8
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.23.0/node_modules/pixi.js/lib/filters/defaults/passthrough/PassthroughFilter.mjs
|
|
9
9
|
var PassthroughFilter = class extends Filter {
|
|
10
10
|
constructor() {
|
|
11
11
|
const gpuProgram = GpuProgram.from({
|
|
@@ -31,7 +31,7 @@ var PassthroughFilter = class extends Filter {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
//#endregion
|
|
34
|
-
//#region ../../node_modules/.pnpm/pixi.js@8.
|
|
34
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.23.0/node_modules/pixi.js/lib/filters/FilterSystem.mjs
|
|
35
35
|
const quadGeometry = new Geometry({
|
|
36
36
|
attributes: { aPosition: {
|
|
37
37
|
buffer: new Float32Array([
|
|
@@ -99,16 +99,6 @@ var FilterData = class {
|
|
|
99
99
|
* @type {RenderSurface}
|
|
100
100
|
*/
|
|
101
101
|
this.outputRenderSurface = null;
|
|
102
|
-
/**
|
|
103
|
-
* The global frame of the filter area.
|
|
104
|
-
* @type {{ x: number, y: number, width: number, height: number }}
|
|
105
|
-
*/
|
|
106
|
-
this.globalFrame = {
|
|
107
|
-
x: 0,
|
|
108
|
-
y: 0,
|
|
109
|
-
width: 0,
|
|
110
|
-
height: 0
|
|
111
|
-
};
|
|
112
102
|
/** The first enabled filter index in the current filter list. */
|
|
113
103
|
this.firstEnabledIndex = -1;
|
|
114
104
|
/** The last enabled filter index in the current filter list. */
|
|
@@ -148,6 +138,10 @@ var FilterSystem = class {
|
|
|
148
138
|
this._globalFilterBindGroup = new BindGroup({});
|
|
149
139
|
this.renderer = renderer;
|
|
150
140
|
}
|
|
141
|
+
/** @internal */
|
|
142
|
+
init() {
|
|
143
|
+
TexturePool.on("evict", this._unbindPassTextures, this);
|
|
144
|
+
}
|
|
151
145
|
/**
|
|
152
146
|
* The back texture of the currently active filter. Requires the filter to have `blendRequired` set to true.
|
|
153
147
|
* @readonly
|
|
@@ -180,14 +174,6 @@ var FilterSystem = class {
|
|
|
180
174
|
this._calculateFilterBounds(filterData, renderer.renderTarget.rootViewPort, rootAntialias, rootResolution, 1);
|
|
181
175
|
if (filterData.skip) return;
|
|
182
176
|
const previousFilterData = this._getPreviousFilterData();
|
|
183
|
-
const globalResolution = this._findFilterResolution(rootResolution);
|
|
184
|
-
let offsetX = 0;
|
|
185
|
-
let offsetY = 0;
|
|
186
|
-
if (previousFilterData) {
|
|
187
|
-
offsetX = previousFilterData.bounds.minX;
|
|
188
|
-
offsetY = previousFilterData.bounds.minY;
|
|
189
|
-
}
|
|
190
|
-
this._calculateGlobalFrame(filterData, offsetX, offsetY, globalResolution, colorTextureSource.width, colorTextureSource.height);
|
|
191
177
|
this._setupFilterTextures(filterData, bounds, renderer, previousFilterData);
|
|
192
178
|
}
|
|
193
179
|
/**
|
|
@@ -207,7 +193,7 @@ var FilterSystem = class {
|
|
|
207
193
|
* const filters = [new BlurFilter(), new ColorMatrixFilter()];
|
|
208
194
|
*
|
|
209
195
|
* // Apply the filters to the texture
|
|
210
|
-
* const resultTexture =
|
|
196
|
+
* const resultTexture = renderer.filter.generateFilteredTexture({ texture, filters });
|
|
211
197
|
*
|
|
212
198
|
* // Use the resulting texture
|
|
213
199
|
* sprite.texture = resultTexture;
|
|
@@ -218,6 +204,7 @@ var FilterSystem = class {
|
|
|
218
204
|
* 2. If all filters are disabled or skipped, the original texture is returned.
|
|
219
205
|
*/
|
|
220
206
|
generateFilteredTexture({ texture, filters }) {
|
|
207
|
+
if (filters.every((filter) => !filter.enabled)) return texture;
|
|
221
208
|
const filterData = this._pushFilterData();
|
|
222
209
|
this._activeFilterData = filterData;
|
|
223
210
|
filterData.skip = false;
|
|
@@ -225,23 +212,27 @@ var FilterSystem = class {
|
|
|
225
212
|
const colorTextureSource = texture.source;
|
|
226
213
|
const rootResolution = colorTextureSource.resolution;
|
|
227
214
|
const rootAntialias = colorTextureSource.antialias;
|
|
228
|
-
if (filters.every((filter) => !filter.enabled)) {
|
|
229
|
-
filterData.skip = true;
|
|
230
|
-
return texture;
|
|
231
|
-
}
|
|
232
215
|
const bounds = filterData.bounds;
|
|
216
|
+
bounds.clear();
|
|
233
217
|
bounds.addRect(texture.frame);
|
|
234
218
|
this._calculateFilterBounds(filterData, bounds.rectangle, rootAntialias, rootResolution, 0);
|
|
235
|
-
if (filterData.skip)
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
219
|
+
if (filterData.skip) {
|
|
220
|
+
this._popFilterData();
|
|
221
|
+
return texture;
|
|
222
|
+
}
|
|
223
|
+
filterData.outputRenderSurface = TexturePool.getOptimalTexture({
|
|
224
|
+
width: bounds.width,
|
|
225
|
+
height: bounds.height,
|
|
226
|
+
resolution: filterData.resolution,
|
|
227
|
+
antialias: filterData.antialias
|
|
228
|
+
});
|
|
239
229
|
filterData.backTexture = Texture.EMPTY;
|
|
240
230
|
filterData.inputTexture = texture;
|
|
241
231
|
this.renderer.renderTarget.finishRenderPass();
|
|
242
232
|
this._applyFiltersToTexture(filterData, true);
|
|
243
233
|
const outputTexture = filterData.outputRenderSurface;
|
|
244
234
|
outputTexture.source.alphaMode = "premultiplied-alpha";
|
|
235
|
+
this._popFilterData();
|
|
245
236
|
return outputTexture;
|
|
246
237
|
}
|
|
247
238
|
/** @internal */
|
|
@@ -263,18 +254,34 @@ var FilterSystem = class {
|
|
|
263
254
|
* @param previousBounds - The previous bounds to use for offsetting the copy.
|
|
264
255
|
*/
|
|
265
256
|
getBackTexture(lastRenderSurface, bounds, previousBounds) {
|
|
266
|
-
const
|
|
267
|
-
const backTexture = TexturePool.getOptimalTexture(
|
|
257
|
+
const { _resolution: resolution, format } = lastRenderSurface.colorTexture.source;
|
|
258
|
+
const backTexture = TexturePool.getOptimalTexture({
|
|
259
|
+
width: bounds.width,
|
|
260
|
+
height: bounds.height,
|
|
261
|
+
resolution,
|
|
262
|
+
format
|
|
263
|
+
});
|
|
264
|
+
return this._copyBackTexture(lastRenderSurface, backTexture, bounds, previousBounds);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Copies an area of a render surface into a texture at the resolution of the surface.
|
|
268
|
+
* @param lastRenderSurface - The render surface to copy from.
|
|
269
|
+
* @param backTexture - The texture to copy to.
|
|
270
|
+
* @param bounds - The bounds of the area to copy.
|
|
271
|
+
* @param previousBounds - The previous bounds to use for offsetting the copy.
|
|
272
|
+
*/
|
|
273
|
+
_copyBackTexture(lastRenderSurface, backTexture, bounds, previousBounds) {
|
|
274
|
+
const backgroundResolution = backTexture.source._resolution;
|
|
268
275
|
let x = bounds.minX;
|
|
269
276
|
let y = bounds.minY;
|
|
270
277
|
if (previousBounds) {
|
|
271
278
|
x -= previousBounds.minX;
|
|
272
279
|
y -= previousBounds.minY;
|
|
273
280
|
}
|
|
274
|
-
x = Math.floor(x * backgroundResolution);
|
|
275
|
-
y = Math.floor(y * backgroundResolution);
|
|
276
|
-
const width = Math.ceil(bounds.width * backgroundResolution);
|
|
277
|
-
const height = Math.ceil(bounds.height * backgroundResolution);
|
|
281
|
+
x = Math.floor(x * backgroundResolution + 1e-6);
|
|
282
|
+
y = Math.floor(y * backgroundResolution + 1e-6);
|
|
283
|
+
const width = Math.min(Math.ceil(bounds.width * backgroundResolution), backTexture.source.pixelWidth);
|
|
284
|
+
const height = Math.min(Math.ceil(bounds.height * backgroundResolution), backTexture.source.pixelHeight);
|
|
278
285
|
this.renderer.renderTarget.copyToTexture(lastRenderSurface, backTexture, {
|
|
279
286
|
x,
|
|
280
287
|
y
|
|
@@ -298,14 +305,13 @@ var FilterSystem = class {
|
|
|
298
305
|
const renderer = this.renderer;
|
|
299
306
|
const filterData = this._activeFilterData;
|
|
300
307
|
const isFinalTarget = filterData.outputRenderSurface === output;
|
|
301
|
-
const
|
|
302
|
-
const resolution =
|
|
308
|
+
const closestFilterData = this._findClosestFilterData();
|
|
309
|
+
const resolution = closestFilterData ? closestFilterData.inputTexture.source._resolution : renderer.renderTarget.rootRenderTarget.colorTexture.source._resolution;
|
|
303
310
|
let offsetX = 0;
|
|
304
311
|
let offsetY = 0;
|
|
305
|
-
if (isFinalTarget) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
offsetY = offset.y;
|
|
312
|
+
if (isFinalTarget && closestFilterData) {
|
|
313
|
+
offsetX = closestFilterData.bounds.minX;
|
|
314
|
+
offsetY = closestFilterData.bounds.minY;
|
|
309
315
|
}
|
|
310
316
|
this._updateFilterUniforms(input, output, filterData, offsetX, offsetY, resolution, isFinalTarget, clear);
|
|
311
317
|
const filterToApply = filter.enabled ? filter : this._getPassthroughFilter();
|
|
@@ -334,6 +340,18 @@ var FilterSystem = class {
|
|
|
334
340
|
destroy() {
|
|
335
341
|
this._passthroughFilter?.destroy(true);
|
|
336
342
|
this._passthroughFilter = null;
|
|
343
|
+
TexturePool.off("evict", this._unbindPassTextures, this);
|
|
344
|
+
this._globalFilterBindGroup.destroy();
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Swaps the last pass's textures in the filter bind group for the empty texture before the texture pool
|
|
348
|
+
* destroys idle textures, as a bind group warns when a texture bound to it is destroyed.
|
|
349
|
+
*/
|
|
350
|
+
_unbindPassTextures() {
|
|
351
|
+
const bindGroup = this._globalFilterBindGroup;
|
|
352
|
+
bindGroup.setResource(Texture.EMPTY.source, 1);
|
|
353
|
+
bindGroup.setResource(Texture.EMPTY.source.style, 2);
|
|
354
|
+
bindGroup.setResource(Texture.EMPTY.source, 3);
|
|
337
355
|
}
|
|
338
356
|
_getPassthroughFilter() {
|
|
339
357
|
this._passthroughFilter ?? (this._passthroughFilter = new PassthroughFilter());
|
|
@@ -370,11 +388,18 @@ var FilterSystem = class {
|
|
|
370
388
|
*/
|
|
371
389
|
_setupFilterTextures(filterData, bounds, renderer, previousFilterData) {
|
|
372
390
|
filterData.backTexture = Texture.EMPTY;
|
|
373
|
-
filterData.inputTexture = TexturePool.getOptimalTexture(
|
|
391
|
+
filterData.inputTexture = TexturePool.getOptimalTexture({
|
|
392
|
+
width: bounds.width,
|
|
393
|
+
height: bounds.height,
|
|
394
|
+
resolution: filterData.resolution,
|
|
395
|
+
antialias: filterData.antialias
|
|
396
|
+
});
|
|
374
397
|
if (filterData.blendRequired) {
|
|
375
398
|
renderer.renderTarget.finishRenderPass();
|
|
376
399
|
const renderTarget = renderer.renderTarget.getRenderTarget(filterData.outputRenderSurface);
|
|
377
|
-
|
|
400
|
+
const surfaceSource = renderTarget.colorTexture.source;
|
|
401
|
+
const backTexture = TexturePool.getAlignedTexture(filterData.inputTexture, surfaceSource._resolution, surfaceSource.format);
|
|
402
|
+
filterData.backTexture = this._copyBackTexture(renderTarget, backTexture, bounds, previousFilterData?.bounds);
|
|
378
403
|
}
|
|
379
404
|
renderer.renderTarget.bind({
|
|
380
405
|
target: filterData.inputTexture,
|
|
@@ -383,22 +408,6 @@ var FilterSystem = class {
|
|
|
383
408
|
renderer.globalUniforms.push({ offset: bounds });
|
|
384
409
|
}
|
|
385
410
|
/**
|
|
386
|
-
* Calculates and sets the global frame for the filter.
|
|
387
|
-
* @param filterData - The filter data to update
|
|
388
|
-
* @param offsetX - The X offset
|
|
389
|
-
* @param offsetY - The Y offset
|
|
390
|
-
* @param globalResolution - The global resolution
|
|
391
|
-
* @param sourceWidth - The source texture width
|
|
392
|
-
* @param sourceHeight - The source texture height
|
|
393
|
-
*/
|
|
394
|
-
_calculateGlobalFrame(filterData, offsetX, offsetY, globalResolution, sourceWidth, sourceHeight) {
|
|
395
|
-
const globalFrame = filterData.globalFrame;
|
|
396
|
-
globalFrame.x = offsetX * globalResolution;
|
|
397
|
-
globalFrame.y = offsetY * globalResolution;
|
|
398
|
-
globalFrame.width = sourceWidth * globalResolution;
|
|
399
|
-
globalFrame.height = sourceHeight * globalResolution;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
411
|
* Updates the filter uniforms with the current filter state.
|
|
403
412
|
* @param input - The input texture
|
|
404
413
|
* @param output - The output render surface
|
|
@@ -460,36 +469,18 @@ var FilterSystem = class {
|
|
|
460
469
|
this._filterGlobalUniforms.update();
|
|
461
470
|
}
|
|
462
471
|
/**
|
|
463
|
-
* Finds the
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
let currentIndex = this._filterStackIndex - 1;
|
|
469
|
-
while (currentIndex > 0 && this._filterStack[currentIndex].skip) --currentIndex;
|
|
470
|
-
return currentIndex > 0 && this._filterStack[currentIndex].inputTexture ? this._filterStack[currentIndex].inputTexture.source._resolution : rootResolution;
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Finds the offset from the previous non-skipped filter in the stack.
|
|
474
|
-
* @returns The offset coordinates from the previous filter
|
|
472
|
+
* Finds the non-skipped entry closest to the top of the filter stack.
|
|
473
|
+
*
|
|
474
|
+
* `pop()` removes its entry before it applies the filters, so the result is the enclosing filter's entry.
|
|
475
|
+
* `generateFilteredTexture()` applies the filters while its entry is still on the stack, so the result is that entry.
|
|
476
|
+
* @returns The entry, or null if there is none
|
|
475
477
|
*/
|
|
476
|
-
|
|
477
|
-
let
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
while (lastIndex > 0) {
|
|
481
|
-
lastIndex--;
|
|
482
|
-
const prevFilterData = this._filterStack[lastIndex];
|
|
483
|
-
if (!prevFilterData.skip) {
|
|
484
|
-
offsetX = prevFilterData.bounds.minX;
|
|
485
|
-
offsetY = prevFilterData.bounds.minY;
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
478
|
+
_findClosestFilterData() {
|
|
479
|
+
for (let i = this._filterStackIndex - 1; i >= 0; i--) {
|
|
480
|
+
const filterData = this._filterStack[i];
|
|
481
|
+
if (!filterData.skip) return filterData;
|
|
488
482
|
}
|
|
489
|
-
return
|
|
490
|
-
x: offsetX,
|
|
491
|
-
y: offsetY
|
|
492
|
-
};
|
|
483
|
+
return null;
|
|
493
484
|
}
|
|
494
485
|
/**
|
|
495
486
|
* Calculates the filter area bounds based on the instruction type.
|
|
@@ -519,7 +510,11 @@ var FilterSystem = class {
|
|
|
519
510
|
if (firstEnabled === lastEnabled) filters[firstEnabled].apply(this, inputTexture, filterData.outputRenderSurface, clear);
|
|
520
511
|
else {
|
|
521
512
|
let flip = filterData.inputTexture;
|
|
522
|
-
const tempTexture = TexturePool.getOptimalTexture(
|
|
513
|
+
const tempTexture = TexturePool.getOptimalTexture({
|
|
514
|
+
width: bounds.width,
|
|
515
|
+
height: bounds.height,
|
|
516
|
+
resolution: flip.source._resolution
|
|
517
|
+
});
|
|
523
518
|
let flop = tempTexture;
|
|
524
519
|
for (let i = firstEnabled; i < lastEnabled; i++) {
|
|
525
520
|
const filter = filters[i];
|
|
@@ -587,15 +582,18 @@ var FilterSystem = class {
|
|
|
587
582
|
this._filterStackIndex--;
|
|
588
583
|
return this._filterStack[this._filterStackIndex];
|
|
589
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* Finds the closest non-skipped entry that encloses the filter being pushed.
|
|
587
|
+
*
|
|
588
|
+
* `push()` has already added that filter's own entry, so the search starts one entry below it.
|
|
589
|
+
* @returns The entry, or null if there is none
|
|
590
|
+
*/
|
|
590
591
|
_getPreviousFilterData() {
|
|
591
|
-
let
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
index--;
|
|
595
|
-
previousFilterData = this._filterStack[index];
|
|
596
|
-
if (!previousFilterData.skip) break;
|
|
592
|
+
for (let i = this._filterStackIndex - 2; i >= 0; i--) {
|
|
593
|
+
const filterData = this._filterStack[i];
|
|
594
|
+
if (!filterData.skip) return filterData;
|
|
597
595
|
}
|
|
598
|
-
return
|
|
596
|
+
return null;
|
|
599
597
|
}
|
|
600
598
|
_pushFilterData() {
|
|
601
599
|
let filterData = this._filterStack[this._filterStackIndex];
|
|
@@ -610,7 +608,7 @@ FilterSystem.extension = {
|
|
|
610
608
|
name: "filter"
|
|
611
609
|
};
|
|
612
610
|
//#endregion
|
|
613
|
-
//#region ../../node_modules/.pnpm/pixi.js@8.
|
|
611
|
+
//#region ../../node_modules/.pnpm/pixi.js@8.23.0/node_modules/pixi.js/lib/filters/init.mjs
|
|
614
612
|
extensions.add(FilterSystem, CanvasFilterSystem);
|
|
615
613
|
extensions.add(FilterPipe);
|
|
616
614
|
//#endregion
|
package/dist/chunks/spaces.js
CHANGED
|
@@ -278,7 +278,8 @@ const SESSION_TURN_ORIGIN_KINDS = [
|
|
|
278
278
|
"prompt",
|
|
279
279
|
"scheduled_prompt",
|
|
280
280
|
"background_task",
|
|
281
|
-
"hook"
|
|
281
|
+
"hook",
|
|
282
|
+
"reply"
|
|
282
283
|
];
|
|
283
284
|
const record$1 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
284
285
|
const normalizeSessionTurnOrigin = (value) => {
|
|
@@ -292,7 +293,7 @@ const normalizeSessionTurnOrigin = (value) => {
|
|
|
292
293
|
sessionId: source.sessionId,
|
|
293
294
|
turnId: source.turnId,
|
|
294
295
|
...source.toolCallId ? { toolCallId: source.toolCallId } : {},
|
|
295
|
-
...typeof input.depth === "number" && Number.isSafeInteger(input.depth) && input.depth
|
|
296
|
+
...typeof input.depth === "number" && Number.isSafeInteger(input.depth) && input.depth >= 0 ? { depth: input.depth } : {}
|
|
296
297
|
};
|
|
297
298
|
};
|
|
298
299
|
/** Reads durable provenance; legacy background tasks only knew their caller's Session/Turn. */
|
|
@@ -310,6 +311,9 @@ const readSessionTurnOrigin = (meta, spaceId) => {
|
|
|
310
311
|
});
|
|
311
312
|
};
|
|
312
313
|
//#endregion
|
|
314
|
+
//#region ../protocol/src/turn-reply.ts
|
|
315
|
+
const isSessionTurnReplyMode = (value) => value === "note" || value === "prompt";
|
|
316
|
+
//#endregion
|
|
313
317
|
//#region ../protocol/src/sent-turns.ts
|
|
314
318
|
const record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
315
319
|
const normalizeSentTurnRef = (value) => {
|
|
@@ -327,7 +331,8 @@ const normalizeSentTurnRef = (value) => {
|
|
|
327
331
|
sessionId: input.sessionId,
|
|
328
332
|
turnId: input.turnId,
|
|
329
333
|
kind,
|
|
330
|
-
...source?.toolCallId ? { toolCallId: source.toolCallId } : {}
|
|
334
|
+
...source?.toolCallId ? { toolCallId: source.toolCallId } : {},
|
|
335
|
+
...isSessionTurnReplyMode(input.reply) ? { reply: input.reply } : {}
|
|
331
336
|
};
|
|
332
337
|
};
|
|
333
338
|
/** Deduplicates by child Turn, so a retried request cannot render one twice. */
|
|
@@ -345,6 +350,23 @@ const readSentTurns = (meta) => {
|
|
|
345
350
|
return refs;
|
|
346
351
|
};
|
|
347
352
|
//#endregion
|
|
353
|
+
//#region ../protocol/src/speech.ts
|
|
354
|
+
function isRecord(value) {
|
|
355
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
356
|
+
}
|
|
357
|
+
function readSegments(value) {
|
|
358
|
+
if (!Array.isArray(value) || value.length === 0) return null;
|
|
359
|
+
return value.every((segment) => isRecord(segment) && typeof segment.taskId === "string" && (segment.status === "pending" || segment.status === "completed" || segment.status === "failed") && (segment.url === void 0 || typeof segment.url === "string")) ? value : null;
|
|
360
|
+
}
|
|
361
|
+
function readTurnSpeech(meta, voice) {
|
|
362
|
+
const speech = isRecord(meta) && isRecord(meta.speech) ? meta.speech : null;
|
|
363
|
+
const segments = speech ? readSegments(speech[voice]) : null;
|
|
364
|
+
return segments ? {
|
|
365
|
+
voice,
|
|
366
|
+
segments
|
|
367
|
+
} : null;
|
|
368
|
+
}
|
|
369
|
+
//#endregion
|
|
348
370
|
//#region src/space-files/limit.ts
|
|
349
371
|
function createLimiter(concurrency) {
|
|
350
372
|
let active = 0;
|
|
@@ -3259,11 +3281,12 @@ async function confirmRestart(opts) {
|
|
|
3259
3281
|
}
|
|
3260
3282
|
async function sendPrompt(command, words, opts) {
|
|
3261
3283
|
const content = await readPromptContent(words, { allowEmpty: Boolean(opts.image?.length) });
|
|
3262
|
-
|
|
3284
|
+
const scheduleFlags = [
|
|
3263
3285
|
opts.delayMs,
|
|
3264
3286
|
opts.at,
|
|
3265
3287
|
opts.cron
|
|
3266
|
-
].filter((value) => value !== void 0)
|
|
3288
|
+
].filter((value) => value !== void 0);
|
|
3289
|
+
if (scheduleFlags.length > 1) return error("Conflicting schedule", "Use only one of --delay-ms, --at, or --cron");
|
|
3267
3290
|
if (opts.cron && !opts.timezone) return error("Missing timezone", "--timezone is required with --cron");
|
|
3268
3291
|
if (opts.note) {
|
|
3269
3292
|
const agentOnly = Object.entries({
|
|
@@ -3282,6 +3305,7 @@ async function sendPrompt(command, words, opts) {
|
|
|
3282
3305
|
}).flatMap(([flag, value]) => value ? [flag] : []);
|
|
3283
3306
|
if (agentOnly.length) return error("Conflicting options", `--note cannot be combined with ${agentOnly.join(", ")}`);
|
|
3284
3307
|
}
|
|
3308
|
+
if (opts.reply && (opts.note || scheduleFlags.length)) return error("Conflicting options", "--reply cannot be combined with --note or scheduling");
|
|
3285
3309
|
const requestedThinkingLevel = opts.thinkingLevel?.trim() || void 0;
|
|
3286
3310
|
const thinkingLevel = isModelThinkingLevel(requestedThinkingLevel) ? requestedThinkingLevel : void 0;
|
|
3287
3311
|
if (requestedThinkingLevel && !thinkingLevel) return error("Invalid thinking level", `Use ${MODEL_THINKING_LEVELS.join("|")}`);
|
|
@@ -3346,10 +3370,14 @@ async function sendPrompt(command, words, opts) {
|
|
|
3346
3370
|
intent: opts.steer ? "steer" : void 0,
|
|
3347
3371
|
env: parseEnvOptions(opts.env),
|
|
3348
3372
|
schedule,
|
|
3349
|
-
labelRefs: opts.label?.length ? opts.label : void 0
|
|
3373
|
+
labelRefs: opts.label?.length ? opts.label : void 0,
|
|
3374
|
+
...opts.reply ? { reply: "prompt" } : {}
|
|
3350
3375
|
});
|
|
3351
3376
|
if (jsonRequested(opts)) return json(result);
|
|
3352
|
-
if (result.mode === "immediate")
|
|
3377
|
+
if (result.mode === "immediate") {
|
|
3378
|
+
const label = opts.note ? "Note recorded" : opts.reply ? "Prompt sent; the reply will come back to this Chat" : "Prompt sent";
|
|
3379
|
+
return ok(`${label} — sessionId: ${result.session.id}, turnId: ${result.turn.id}`);
|
|
3380
|
+
}
|
|
3353
3381
|
if (result.mode === "repeat") return ok(`Prompt scheduled — cronJobId: ${result.cronJobId}, nextRunAt: ${result.nextRunAt}`);
|
|
3354
3382
|
return ok(`Prompt scheduled — taskRunId: ${result.taskRunId}, scheduledAt: ${result.scheduledAt}`);
|
|
3355
3383
|
} catch (e) {
|
|
@@ -3418,7 +3446,7 @@ async function runCompletionCommand(command, words, opts) {
|
|
|
3418
3446
|
}
|
|
3419
3447
|
}
|
|
3420
3448
|
function registerPrompt(program) {
|
|
3421
|
-
program.command("prompt [content...]").description("Send or schedule a prompt in a space").option("--session <id>", "Target session ID").option("--title <title>", "Title for a newly created session or schedule").option("-m, --model <model>", "Model name").option("-p, --provider <provider>", "Provider name").option("--harness <harness>", `Harness: ${harnessSchema.options.join(", ")}`, "cohub").option("--thinking-level <level>", `Thinking level: ${MODEL_THINKING_LEVELS.join("|")}`).option("--context-window <tokens>", "Context window for this session from this prompt on; capped at the platform value").option("--approval-mode <mode>", `Local Harness approval mode: ${APPROVAL_MODES.join("|")}`).option("--service-tier <tier>", "Local Harness service tier, e.g. priority for Codex Fast").option("--read-only", "Use read-only tools").option("--steer", "Interrupt the current turn and run immediately").option("--delay-ms <ms>", "Delay sending by milliseconds").option("--at <iso>", "Send once at an ISO 8601 time with timezone").option("--cron <expression>", "Repeat using a 5-field cron expression").option("--timezone <tz>", "IANA timezone for --cron, e.g. Asia/Shanghai").option("--label <ref>", "Attach a label, e.g. Bug or Area/Frontend", collectOption, []).option("--env <key=value>", "Set an environment variable for this turn", collectOption, []).option("--image <path>", "Attach an image", collectOption, []).option("--note", "Record the message without an AI reply").option("--json", "Output as JSON").action((words, opts) => sendPrompt(program, words, opts));
|
|
3449
|
+
program.command("prompt [content...]").description("Send or schedule a prompt in a space").option("--session <id>", "Target session ID").option("--title <title>", "Title for a newly created session or schedule").option("-m, --model <model>", "Model name").option("-p, --provider <provider>", "Provider name").option("--harness <harness>", `Harness: ${harnessSchema.options.join(", ")}`, "cohub").option("--thinking-level <level>", `Thinking level: ${MODEL_THINKING_LEVELS.join("|")}`).option("--context-window <tokens>", "Context window for this session from this prompt on; capped at the platform value").option("--approval-mode <mode>", `Local Harness approval mode: ${APPROVAL_MODES.join("|")}`).option("--service-tier <tier>", "Local Harness service tier, e.g. priority for Codex Fast").option("--read-only", "Use read-only tools").option("--steer", "Interrupt the current turn and run immediately").option("--delay-ms <ms>", "Delay sending by milliseconds").option("--at <iso>", "Send once at an ISO 8601 time with timezone").option("--cron <expression>", "Repeat using a 5-field cron expression").option("--timezone <tz>", "IANA timezone for --cron, e.g. Asia/Shanghai").option("--label <ref>", "Attach a label, e.g. Bug or Area/Frontend", collectOption, []).option("--env <key=value>", "Set an environment variable for this turn", collectOption, []).option("--image <path>", "Attach an image", collectOption, []).option("--note", "Record the message without an AI reply").option("--reply", "Send the final reply back to the calling Chat and run its Agent").option("--json", "Output as JSON").action((words, opts) => sendPrompt(program, words, opts));
|
|
3422
3450
|
program.command("completion [content...]").description("Raw LLM completion with full message control").option("-m, --model <model>", "Model name").option("-p, --provider <provider>", "Provider name").option("--system-prompt <path>", "Space-relative system prompt markdown path").option("--stream", "Stream tokens via SSE").option("--temperature <n>", "Sampling temperature").option("--max-tokens <n>", "Maximum output tokens").option("--thinking-level <level>", "Thinking level: off|minimal|low|medium|high|xhigh").option("--json", "Output as JSON").action((words, opts) => runCompletionCommand(program, words, opts));
|
|
3423
3451
|
registerDecisionCommand(program);
|
|
3424
3452
|
}
|
|
@@ -3856,7 +3884,7 @@ function registerSpaces(program) {
|
|
|
3856
3884
|
handleHttp(e);
|
|
3857
3885
|
}
|
|
3858
3886
|
});
|
|
3859
|
-
spacesCmd.command("prompt [content...]", { hidden: true }).alias("send").description("Send or schedule a prompt in the target space").option("--harness <harness>", `Harness: ${harnessSchema.options.join(", ")}`, "cohub").option("--session <id>", "Target session ID").option("--title <title>", "Title for a newly created session or schedule").option("-m, --model <model>", "Model name").option("-p, --provider <provider>", "Provider name").option("--thinking-level <level>", `Thinking level: ${MODEL_THINKING_LEVELS.join("|")}`).option("--context-window <tokens>", "Context window for this session from this prompt on; capped at the platform value").option("--approval-mode <mode>", `Local Harness approval mode: ${APPROVAL_MODES.join("|")}`).option("--service-tier <tier>", "Local Harness service tier, e.g. priority for Codex Fast").option("--read-only", "Use read-only tools").option("--steer", "Interrupt the current turn and run immediately").option("--delay-ms <ms>", "Delay sending by milliseconds").option("--at <iso>", "Send once at an ISO 8601 time with timezone").option("--cron <expression>", "Repeat using a 5-field cron expression").option("--timezone <tz>", "IANA timezone for --cron, e.g. Asia/Shanghai").option("--label <ref>", "Attach a label, e.g. Bug or Area/Frontend", collectOption, []).option("--env <key=value>", "Set an environment variable for this turn", collectOption, []).option("--image <path>", "Attach an image", collectOption, []).option("--note", "Record the message without an AI reply").option("--json", "Output as JSON").action((words, opts) => sendPrompt(spacesCmd, words, opts));
|
|
3887
|
+
spacesCmd.command("prompt [content...]", { hidden: true }).alias("send").description("Send or schedule a prompt in the target space").option("--harness <harness>", `Harness: ${harnessSchema.options.join(", ")}`, "cohub").option("--session <id>", "Target session ID").option("--title <title>", "Title for a newly created session or schedule").option("-m, --model <model>", "Model name").option("-p, --provider <provider>", "Provider name").option("--thinking-level <level>", `Thinking level: ${MODEL_THINKING_LEVELS.join("|")}`).option("--context-window <tokens>", "Context window for this session from this prompt on; capped at the platform value").option("--approval-mode <mode>", `Local Harness approval mode: ${APPROVAL_MODES.join("|")}`).option("--service-tier <tier>", "Local Harness service tier, e.g. priority for Codex Fast").option("--read-only", "Use read-only tools").option("--steer", "Interrupt the current turn and run immediately").option("--delay-ms <ms>", "Delay sending by milliseconds").option("--at <iso>", "Send once at an ISO 8601 time with timezone").option("--cron <expression>", "Repeat using a 5-field cron expression").option("--timezone <tz>", "IANA timezone for --cron, e.g. Asia/Shanghai").option("--label <ref>", "Attach a label, e.g. Bug or Area/Frontend", collectOption, []).option("--env <key=value>", "Set an environment variable for this turn", collectOption, []).option("--image <path>", "Attach an image", collectOption, []).option("--note", "Record the message without an AI reply").option("--reply", "Send the final reply back to the calling Chat and run its Agent").option("--json", "Output as JSON").action((words, opts) => sendPrompt(spacesCmd, words, opts));
|
|
3860
3888
|
spacesCmd.command("completion [content...]").description("Raw LLM completion with full message control").option("-m, --model <model>", "Model name").option("-p, --provider <provider>", "Provider name").option("--system-prompt <path>", "Space-relative system prompt markdown path").option("--stream", "Stream tokens via SSE").option("--temperature <n>", "Sampling temperature").option("--max-tokens <n>", "Maximum output tokens").option("--thinking-level <level>", "Thinking level: off|minimal|low|medium|high|xhigh").option("--json", "Output as JSON").action((words, opts) => runCompletionCommand(spacesCmd, words, opts));
|
|
3861
3889
|
registerDecisionCommand(spacesCmd);
|
|
3862
3890
|
registerFiles(spacesCmd);
|
|
@@ -4736,6 +4764,23 @@ function registerTurns(sessionsCmd) {
|
|
|
4736
4764
|
handleHttp(e);
|
|
4737
4765
|
}
|
|
4738
4766
|
});
|
|
4767
|
+
turnsCmd.command("speak <sessionId> <turnId>").description("Read a turn's reply aloud with the configured voice and print the audio URLs").option("--no-wait", "Return without waiting for audio still being rendered").option("--json", "Output as JSON").action(async (sessionId, turnId, opts) => {
|
|
4768
|
+
const spaceId = await resolveSpace(sessionsCmd);
|
|
4769
|
+
const session = createClient().space(spaceId).session(sessionId);
|
|
4770
|
+
try {
|
|
4771
|
+
let { speech } = await session.turn(turnId).speak();
|
|
4772
|
+
const deadline = Date.now() + 3e5;
|
|
4773
|
+
while (opts.wait && speech.segments.some((segment) => segment.status === "pending") && Date.now() < deadline) {
|
|
4774
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
4775
|
+
speech = readTurnSpeech((await session.turns.get(turnId)).turn.meta, speech.voice) ?? speech;
|
|
4776
|
+
}
|
|
4777
|
+
if (speech.segments.some((segment) => segment.status !== "completed")) process.exitCode = 1;
|
|
4778
|
+
if (jsonRequested(opts)) return json(speech);
|
|
4779
|
+
for (const [index, segment] of speech.segments.entries()) console.log(segment.url ?? ` Segment ${index + 1}: ${segment.status}`);
|
|
4780
|
+
} catch (e) {
|
|
4781
|
+
handleHttp(e);
|
|
4782
|
+
}
|
|
4783
|
+
});
|
|
4739
4784
|
turnsCmd.command("index <sessionId>", { hidden: true }).description("List lightweight turn index").option("--cursor <sequence>", "Turn sequence cursor").option("--limit <n>", "Page size", "100").option("--json", "Output as JSON").action(async (sessionId, opts) => {
|
|
4740
4785
|
const spaceId = await resolveSpace(sessionsCmd);
|
|
4741
4786
|
const client = createClient();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neta-art/cohub-cli",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.29.1",
|
|
4
4
|
"description": "CLI for Cohub — spaces, sessions, and agent collaboration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"NOTICE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@neta-art/cohub": "13.21.0",
|
|
27
28
|
"sharp": "^0.35.4"
|
|
28
29
|
},
|
|
29
30
|
"publishConfig": {
|
|
@@ -33,11 +34,10 @@
|
|
|
33
34
|
"@fontsource-variable/figtree": "^5.3.0",
|
|
34
35
|
"@fontsource-variable/geist": "^5.3.0",
|
|
35
36
|
"@fontsource-variable/geist-mono": "^5.3.0",
|
|
36
|
-
"@neta-art/cohub": "13.20.0",
|
|
37
37
|
"@types/node": "26.6.4",
|
|
38
38
|
"@types/ws": "^8.18.1",
|
|
39
39
|
"commander": "^15.0.0",
|
|
40
|
-
"pixi.js": "^8.
|
|
40
|
+
"pixi.js": "^8.23.0",
|
|
41
41
|
"tsdown": "^0.22.14",
|
|
42
42
|
"typescript": "^7.0.2",
|
|
43
43
|
"ws": "^8.21.3"
|