@tomflow/chatloop-extension 0.4.7 → 0.4.9
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.
|
@@ -157,7 +157,10 @@ function createApiAspect(packageName,{sink,bufferUntilSubscribe=false}={}){
|
|
|
157
157
|
let result;
|
|
158
158
|
try{
|
|
159
159
|
const storage=base?contextStore():null;
|
|
160
|
-
|
|
160
|
+
// A context-inspection API must see its caller's span, not the
|
|
161
|
+
// observation span created to record the inspection itself.
|
|
162
|
+
result=storage&&!options?.preserveCallerContext
|
|
163
|
+
?storage.run({traceId:base.traceId,spanId:base.spanId},execute)
|
|
161
164
|
:execute();
|
|
162
165
|
}catch(e){mark('FAILED',e);throw e}
|
|
163
166
|
const failed=value=>{
|
|
@@ -226,6 +229,8 @@ function createApiAspect(packageName,{sink,bufferUntilSubscribe=false}={}){
|
|
|
226
229
|
const value=Reflect.get(object,key,receiver);
|
|
227
230
|
if(typeof value!=='function'||typeof key!=='string'
|
|
228
231
|
||(descriptors&&!Object.hasOwn(descriptors,key)))return value;
|
|
232
|
+
// Existing public proxies already own a complete BEGIN/terminal pair.
|
|
233
|
+
if(value[Symbol.for('chat-loop.api-observed.v1')]===true)return value;
|
|
229
234
|
if(!cache.has(key))cache.set(key,wrap(key,value));
|
|
230
235
|
return cache.get(key);
|
|
231
236
|
},
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Keep each API span ordered at the existing single Supervisor writer.
|
|
2
2
|
// Telemetry is best-effort: it neither changes nor retries the business call.
|
|
3
3
|
// Concurrent spans are allowed; BEGIN and terminal of one call never race.
|
|
4
|
-
function createOrderedApiObservationSender(deliver,{parallel=
|
|
4
|
+
function createOrderedApiObservationSender(deliver,{parallel=8,capacity=2048}={}){
|
|
5
5
|
if(typeof deliver!=='function'||!Number.isInteger(parallel)||parallel<1||
|
|
6
6
|
!Number.isInteger(capacity)||capacity<2)throw TypeError('OBSERVATION_SENDER_INVALID');
|
|
7
7
|
const waiting=[],active=new Set();
|
|
8
|
-
const health={submitted:0,confirmed:0,dropped:0,failed:0};
|
|
8
|
+
const health={submitted:0,confirmed:0,dropped:0,failed:0,lastFailureCode:null};
|
|
9
9
|
let running=0,scheduled=false;
|
|
10
10
|
function pump(){
|
|
11
11
|
scheduled=false;
|
|
@@ -18,8 +18,12 @@ function createOrderedApiObservationSender(deliver,{parallel=16,capacity=2048}={
|
|
|
18
18
|
Promise.resolve().then(()=>deliver(record)).then(result=>{
|
|
19
19
|
success=result!==false;
|
|
20
20
|
if(success)health.confirmed++;
|
|
21
|
-
else
|
|
22
|
-
},
|
|
21
|
+
else{health.failed++;health.lastFailureCode='OBSERVATION_REJECTED'}
|
|
22
|
+
},error=>{
|
|
23
|
+
health.failed++;
|
|
24
|
+
health.lastFailureCode=/^[A-Z][A-Z0-9_]{1,95}$/.test(error?.code||'')
|
|
25
|
+
?error.code:'OBSERVATION_TRANSPORT_FAILED';
|
|
26
|
+
}).finally(()=>{
|
|
23
27
|
// Keep later terminal evidence even when BEGIN transport failed:
|
|
24
28
|
// an orphan terminal is an auditable gap, not an invisible call.
|
|
25
29
|
active.delete(id);running--;resolve(success);schedule();
|
|
@@ -34,6 +38,7 @@ function createOrderedApiObservationSender(deliver,{parallel=16,capacity=2048}={
|
|
|
34
38
|
health.submitted++;
|
|
35
39
|
if(waiting.length>=capacity){
|
|
36
40
|
health.dropped++;
|
|
41
|
+
health.lastFailureCode='OBSERVATION_QUEUE_FULL';
|
|
37
42
|
return Promise.resolve(false);
|
|
38
43
|
}
|
|
39
44
|
return new Promise(resolve=>{waiting.push({record,resolve});schedule()});
|
|
@@ -59,7 +64,8 @@ function createObservationDrain(aspect,sender){
|
|
|
59
64
|
const a=aspect.health(),s=sender.health();
|
|
60
65
|
state={pending:a.pending+s.pending,inFlight:a.inFlight+s.inFlight,
|
|
61
66
|
dropped:a.dropped+s.dropped,failed:a.sinkFailures+s.failed,
|
|
62
|
-
submitted:s.submitted,confirmed:s.confirmed
|
|
67
|
+
submitted:s.submitted,confirmed:s.confirmed,
|
|
68
|
+
lastFailureCode:s.lastFailureCode};
|
|
63
69
|
if(state.pending===0&&state.inFlight===0)break;
|
|
64
70
|
}while(Date.now()<deadline);
|
|
65
71
|
return Object.freeze({...state,status:state.pending||state.inFlight
|
package/extension/manifest.json
CHANGED
package/index.mjs
CHANGED
|
@@ -11,10 +11,9 @@ const observationSender=createOrderedApiObservationSender(record=>
|
|
|
11
11
|
const INTERNAL_DRAIN=Symbol.for('chat-loop.telemetry.drain.internal');
|
|
12
12
|
const apiAspect=createApiAspect('@tomflow/chatloop-extension',{
|
|
13
13
|
sink:record=>{
|
|
14
|
-
// The
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
record.api==='nativeHostApi.nativeApiObservation')return;
|
|
14
|
+
// The sink uses the private raw IPC transport, not the exported Native
|
|
15
|
+
// callable. Public nativeHostApi/nativeApiObservation calls therefore
|
|
16
|
+
// remain observable without re-entering their own AOP wrappers.
|
|
18
17
|
return observationSender.send({
|
|
19
18
|
callId:record.callId,traceId:record.traceId,spanId:record.spanId,
|
|
20
19
|
...(record.parentSpanId?{parentSpanId:record.parentSpanId}:{}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomflow/chatloop-extension",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
".": "./index.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tomflow/chatloop-trace": "0.4.
|
|
36
|
+
"@tomflow/chatloop-trace": "0.4.3"
|
|
37
37
|
}
|
|
38
38
|
}
|