@tomflow/chatloop-tools 0.9.14 → 0.9.16
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 +2 -1
- package/index.mjs +8 -1
- package/lib/extension-proxy.mjs +9 -10
- package/lib/trace-observation.mjs +19 -0
- package/package.json +2 -2
- package/providers/form.mjs +226 -0
- package/providers.generated.mjs +3 -2
package/README.md
CHANGED
|
@@ -57,13 +57,14 @@ Start all enabled tools or one.
|
|
|
57
57
|
`providers/<id>.mjs` owns each MCP Provider's tool names, schemas,
|
|
58
58
|
activation condition, scoped call adapter and optional CLI commands.
|
|
59
59
|
|
|
60
|
-
The
|
|
60
|
+
The six built-in Providers are:
|
|
61
61
|
|
|
62
62
|
- `desktop`: allowlisted Desktop Commander tools and isolated fixtures
|
|
63
63
|
- `extension`: official pinned Extension CLI and nine scoped actions
|
|
64
64
|
- `runtime`: exact-request receipt lookup without replay
|
|
65
65
|
- `context`: independent Context SDK read/write schemas and fixed CLI
|
|
66
66
|
- `trace`: Project-scoped diagnosis and SOFT stage observations
|
|
67
|
+
- `form`: two ChatGPT-only fixed-card adapters, `chat_loop_form__prepare` and `chat_loop_form__submit`; optional generated `formId`, no independent approval authority, managed writes delegate to Context
|
|
67
68
|
|
|
68
69
|
`npm run build:providers` generates `providers.generated.mjs`, the static
|
|
69
70
|
assembly and release fingerprint manifest. Both `tools/list` and `tools/call`
|
package/index.mjs
CHANGED
|
@@ -168,7 +168,14 @@ async function runtime(){
|
|
|
168
168
|
// tools/call. Adding an independent provider never edits this Gateway.
|
|
169
169
|
const coreToolRouter=createMcpToolRouter(providerDefinitions,{
|
|
170
170
|
control,release,terminal:terminalPolicy,context:contextGateway,
|
|
171
|
-
|
|
171
|
+
form:{current:apiAspect.current,observe:payload=>control.talk({
|
|
172
|
+
contract:control.CONTRACT,action:'__trace_observation',
|
|
173
|
+
requestId:randomUUID(),event:payload.event,status:'CONFIRMED',
|
|
174
|
+
traceId:payload.traceId,spanId:payload.spanId,
|
|
175
|
+
projectRef:payload.projectRef,
|
|
176
|
+
...(payload.taskRef?{taskRef:payload.taskRef}:{}),
|
|
177
|
+
evidenceRef:payload.formId
|
|
178
|
+
},1800)},trace:traceGateway,
|
|
172
179
|
extension:{
|
|
173
180
|
forwardExtensionAction:extensionProxy.forwardExtensionAction,
|
|
174
181
|
observeExtensionResult:traceGateway.observeExtensionResult
|
package/lib/extension-proxy.mjs
CHANGED
|
@@ -17,13 +17,12 @@ export function configureExtensionProxy(ports){
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
// One
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
20
|
+
// One official CLI provider and one public npm bin. Resolve its npm latest
|
|
21
|
+
// at invocation time, never a manually duplicated release number. The CLI's
|
|
22
|
+
// versioned RESULT contract is checked before any business receipt is trusted.
|
|
23
|
+
// Private environment variables cannot replace the official provider.
|
|
24
24
|
export {extensionTools};
|
|
25
|
-
const EXTENSION_PACKAGE='@tomflow/chatloop-extension@
|
|
26
|
-
const EXTENSION_VERSION='0.4.10';
|
|
25
|
+
const EXTENSION_PACKAGE='@tomflow/chatloop-extension@latest';
|
|
27
26
|
const NPX_COMMAND=process.platform==='win32'?'npx.cmd':'npx';
|
|
28
27
|
const UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
29
28
|
// Match the existing Context child-CLI correlation boundary. Never inherit
|
|
@@ -41,7 +40,7 @@ function childApiEnvironment(){
|
|
|
41
40
|
export const extensionInvocation=name=>{
|
|
42
41
|
const command=extensionCommand(name);
|
|
43
42
|
if(!command)return null;
|
|
44
|
-
return {executable:NPX_COMMAND,
|
|
43
|
+
return {executable:NPX_COMMAND,
|
|
45
44
|
args:['--yes','--package='+EXTENSION_PACKAGE,'chatloop-extension',...command]};
|
|
46
45
|
};
|
|
47
46
|
const fail=code=>({isError:true,content:[{type:'text',text:code}]});
|
|
@@ -76,9 +75,9 @@ export async function forwardExtensionAction(name,args={}) {
|
|
|
76
75
|
// The CLI emits RESULT only after its business outcome is known.
|
|
77
76
|
// Subsequent exit/drain belongs to soft telemetry, not the receipt.
|
|
78
77
|
const result=acceptExtensionCliReceipt(msg,command,msg.ok===true?0:1);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
// Latest is mutable. Trust only the declared CLI v1 protocol, exact
|
|
79
|
+
// command, structural result and action receipt, never a stale pin.
|
|
80
|
+
settle(result.ok?result.value:fail(result.code),true);
|
|
82
81
|
return true;
|
|
83
82
|
};
|
|
84
83
|
// Decode UTF-8 incrementally, and accept the completed RESULT frame
|
|
@@ -67,6 +67,25 @@ export function createSupervisorTraceBridge({traceWriter,contract,error}){
|
|
|
67
67
|
return {contract:CONTRACT,requestId:req.requestId,status:'OK',
|
|
68
68
|
eventId:recorded.eventId};
|
|
69
69
|
}
|
|
70
|
+
const form=/^form\.(prepared|submitted)\.soft_observed$/.test(req?.event||'');
|
|
71
|
+
if(form){
|
|
72
|
+
const allowed=new Set(['contract','action','requestId','traceId','spanId',
|
|
73
|
+
'projectRef','taskRef','evidenceRef','event','status']);
|
|
74
|
+
if(req.contract!==CONTRACT||req.status!=='CONFIRMED'
|
|
75
|
+
||!UUID_RE.test(req.requestId||'')||!UUID_RE.test(req.traceId||'')
|
|
76
|
+
||!UUID_RE.test(req.spanId||'')
|
|
77
|
+
||!(/^[A-Za-z0-9_-]{8,80}$/).test(req.evidenceRef||'')
|
|
78
|
+
||req.taskRef!==undefined&&!(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/).test(req.taskRef)
|
|
79
|
+
||Object.keys(req).some(k=>!allowed.has(k)))
|
|
80
|
+
throw error('TRACE_INVALID_ARGUMENT');
|
|
81
|
+
const written=traceWriter.record({traceId:req.traceId,
|
|
82
|
+
parentSpanId:req.spanId,projectRef:req.projectRef,
|
|
83
|
+
...(req.taskRef?{taskRef:req.taskRef}:{}),requestId:req.requestId,
|
|
84
|
+
component:'gateway',event:req.event,status:'CONFIRMED',
|
|
85
|
+
evidenceRef:req.evidenceRef});
|
|
86
|
+
return {contract:CONTRACT,requestId:req.requestId,status:'OK',
|
|
87
|
+
eventId:written.eventId};
|
|
88
|
+
}
|
|
70
89
|
const intent=/^extension\.(continue|handoff)\.(intent\.queued|receipt\.observed)$/.test(req?.event||'');
|
|
71
90
|
const agent=/^agent\.(intent|project|tooling|requirements|plan|approval)\.soft_(observed|blocked|unverified)$/.test(req?.event||'');
|
|
72
91
|
const agentStatus=req?.event?.endsWith('_observed')?'CONFIRMED':
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.16",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"description": "Chat Loop local tools: MCP gateway, isolated bundled tunnel-client and unified CLI",
|
|
9
9
|
"bin": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@wonderwhy-er/desktop-commander": "0.2.44",
|
|
32
|
-
"@tomflow/chatloop-context": "0.6.
|
|
32
|
+
"@tomflow/chatloop-context": "0.6.11",
|
|
33
33
|
"@tomflow/chatloop-trace": "0.4.4"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// Fixed ChatGPT card adapter, not a second approval authority.
|
|
2
|
+
// Form IDs identify interactions; Context Issue IDs own R/P decisions.
|
|
3
|
+
import {randomUUID} from 'node:crypto';
|
|
4
|
+
const ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
5
|
+
const FORM_ID=/^[A-Za-z0-9_-]{8,80}$/;
|
|
6
|
+
const UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
7
|
+
const ISSUE=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
|
+
const HASH=/^[a-f0-9]{64}$/;
|
|
9
|
+
const fail=code=>Object.assign(Error(code),{code});
|
|
10
|
+
const err=code=>({isError:true,content:[{type:'text',text:code}]});
|
|
11
|
+
const ok=value=>({content:[{type:'text',text:JSON.stringify(value)}]});
|
|
12
|
+
const filled=(s,max)=>typeof s==='string'&&s.trim().length>0&&s.length<=max;
|
|
13
|
+
const shape=(v,fields)=>v&&typeof v==='object'&&!Array.isArray(v)
|
|
14
|
+
&&Object.keys(v).every(k=>fields.includes(k));
|
|
15
|
+
const CARD=['title','description','confirmLabel','modifyLabel',
|
|
16
|
+
'modifyPlaceholder','submitLabel','footer'];
|
|
17
|
+
const PREP=['mode','formId','projectId','taskId','chatRef','kind','documentId',
|
|
18
|
+
'version','contentHash','expectedTaskRevision','expectedStoreEpoch',
|
|
19
|
+
'writeRequestId','card'];
|
|
20
|
+
const SUBMIT=['mode','formId','issueId','projectId','taskId','chatRef','kind',
|
|
21
|
+
'documentId','version','choice','comment','userTurn','presentedAssistantRef',
|
|
22
|
+
'expectedTaskRevision','expectedStoreEpoch','writeRequestId'];
|
|
23
|
+
const common={
|
|
24
|
+
mode:{type:'string',enum:['GENERAL','TEST_ONLY','MANAGED']},
|
|
25
|
+
formId:{type:'string',pattern:FORM_ID.source},projectId:{type:'string',pattern:ID.source},
|
|
26
|
+
taskId:{type:'string',pattern:ID.source},
|
|
27
|
+
chatRef:{type:'string',minLength:8,maxLength:256},
|
|
28
|
+
kind:{type:'string',enum:['R','P','CUSTOM']},
|
|
29
|
+
documentId:{type:'string',pattern:ID.source},
|
|
30
|
+
version:{type:'integer',minimum:1},
|
|
31
|
+
expectedTaskRevision:{type:'integer',minimum:1},
|
|
32
|
+
expectedStoreEpoch:{type:'string',minLength:10,maxLength:64},
|
|
33
|
+
writeRequestId:{type:'string',minLength:8,maxLength:128}
|
|
34
|
+
};
|
|
35
|
+
const cardSchema={type:'object',additionalProperties:false,required:CARD,
|
|
36
|
+
properties:Object.fromEntries(CARD.map(key=>[key,{type:'string',minLength:1,
|
|
37
|
+
maxLength:['description','footer'].includes(key)?1200:180}]))};
|
|
38
|
+
const tools=[
|
|
39
|
+
{name:'chat_loop_form__prepare',description:
|
|
40
|
+
'Prepare the fixed ChatGPT A/B card. Optional formId is preserved; otherwise a fresh UUID is generated. GENERAL/TEST_ONLY never write Context; MANAGED creates one Context R/P Issue and returns its separate issueId.',
|
|
41
|
+
inputSchema:{type:'object',additionalProperties:false,
|
|
42
|
+
required:['mode','card'],
|
|
43
|
+
properties:{...common,contentHash:{type:'string',pattern:HASH.source},
|
|
44
|
+
card:cardSchema}},
|
|
45
|
+
annotations:{readOnlyHint:false}},
|
|
46
|
+
{name:'chat_loop_form__submit',description:
|
|
47
|
+
'Record a caller-asserted ChatGPT user-turn A/B choice for an existing formId; GENERAL/TEST_ONLY is SOFT observation only. MANAGED delegates to Context Issue authority with exact issueId, revisions and original writeRequestId. No click authentication implied.',
|
|
48
|
+
inputSchema:{type:'object',additionalProperties:false,
|
|
49
|
+
required:['mode','formId','choice','userTurn','presentedAssistantRef','writeRequestId'],
|
|
50
|
+
properties:{...common,issueId:{type:'string',pattern:ISSUE.source},
|
|
51
|
+
choice:{type:'string',enum:['A','B']},
|
|
52
|
+
comment:{type:'string',maxLength:4000},
|
|
53
|
+
userTurn:{type:'string',minLength:8,maxLength:256},
|
|
54
|
+
presentedAssistantRef:{type:'string',minLength:8,maxLength:256}}},
|
|
55
|
+
annotations:{readOnlyHint:false}}
|
|
56
|
+
];
|
|
57
|
+
function check(a,fields){
|
|
58
|
+
if(!shape(a,fields)||!['GENERAL','TEST_ONLY','MANAGED'].includes(a.mode)
|
|
59
|
+
||a.formId!==undefined&&!FORM_ID.test(a.formId)
|
|
60
|
+
||a.projectId!==undefined&&!ID.test(a.projectId)
|
|
61
|
+
||a.documentId!==undefined&&!ID.test(a.documentId)
|
|
62
|
+
||a.version!==undefined&&(!Number.isSafeInteger(a.version)||a.version<1)
|
|
63
|
+
||a.kind!==undefined&&!['R','P','CUSTOM'].includes(a.kind))
|
|
64
|
+
throw fail('FORM_INVALID_ARGUMENT');
|
|
65
|
+
if(['R','P'].includes(a.kind)&&(!ID.test(a.documentId||'')
|
|
66
|
+
||!Number.isSafeInteger(a.version)))throw fail('FORM_REVIEW_SCOPE_REQUIRED');
|
|
67
|
+
if(a.mode!=='GENERAL'&&(!ID.test(a.projectId||'')
|
|
68
|
+
||!ID.test(a.documentId||'')||!Number.isSafeInteger(a.version)
|
|
69
|
+
||!['R','P'].includes(a.kind)))throw fail('FORM_REVIEW_SCOPE_REQUIRED');
|
|
70
|
+
if(a.mode==='TEST_ONLY'&&(!filled(a.chatRef,256)||a.chatRef.length<8))
|
|
71
|
+
throw fail('FORM_TEST_CHAT_REQUIRED');
|
|
72
|
+
if(a.mode==='MANAGED'&&(!ID.test(a.taskId||'')
|
|
73
|
+
||!Number.isSafeInteger(a.expectedTaskRevision)
|
|
74
|
+
||a.expectedTaskRevision<1||!filled(a.expectedStoreEpoch,64)
|
|
75
|
+
||!filled(a.writeRequestId,128)))
|
|
76
|
+
throw fail('FORM_MANAGED_SCOPE_REQUIRED');
|
|
77
|
+
}
|
|
78
|
+
function checkCard(a){
|
|
79
|
+
if(!shape(a.card,CARD)||CARD.some(x=>!Object.hasOwn(a.card,x)))
|
|
80
|
+
throw fail('FORM_CARD_INVALID');
|
|
81
|
+
for(const key of CARD){
|
|
82
|
+
if(!filled(a.card[key],['description','footer'].includes(key)?1200:180))
|
|
83
|
+
throw fail('FORM_CARD_INVALID');
|
|
84
|
+
}
|
|
85
|
+
if(!/^A\s*[—-]/.test(a.card.confirmLabel)
|
|
86
|
+
||!/^B\s*[—-]/.test(a.card.modifyLabel)
|
|
87
|
+
||a.kind==='R'&&a.card.submitLabel!=='提交需求评审'
|
|
88
|
+
||a.kind==='P'&&a.card.submitLabel!=='提交方案评审')
|
|
89
|
+
throw fail('FORM_CARD_LAYOUT_INVALID');
|
|
90
|
+
}
|
|
91
|
+
function view(a,formId,issueId,prior){
|
|
92
|
+
const review=a.kind==='R'||a.kind==='P';
|
|
93
|
+
return {template:'chat-loop-review-card-v1',formId,mode:a.mode,
|
|
94
|
+
layout:{card:'rounded-border',radiusPx:12,paddingPx:12,gapPx:12,
|
|
95
|
+
direction:'column',optionDirection:'column',buttonWidth:'full',
|
|
96
|
+
buttonShape:'pill'},
|
|
97
|
+
badges:review
|
|
98
|
+
?[...(prior?[{text:prior+' SUPERSEDED'}]:[]),
|
|
99
|
+
{text:a.documentId+' CURRENT'},{text:'WAITING_APPROVAL'}]
|
|
100
|
+
:[{text:'WAITING_INPUT'}],
|
|
101
|
+
title:a.card.title,description:a.card.description,
|
|
102
|
+
options:[{value:'A',label:a.card.confirmLabel},
|
|
103
|
+
{value:'B',label:a.card.modifyLabel}],
|
|
104
|
+
modifyField:{when:'B',required:true,rows:3,
|
|
105
|
+
placeholder:a.card.modifyPlaceholder},
|
|
106
|
+
submit:{label:a.card.submitLabel,disabledInitially:true,
|
|
107
|
+
singleClickLock:true,issueNewUserTurn:true},
|
|
108
|
+
footer:a.card.footer,
|
|
109
|
+
...(review?{documentId:a.documentId,version:a.version}:{}),
|
|
110
|
+
authority:issueId?'CONTEXT_ISSUE':'NONE'};
|
|
111
|
+
}
|
|
112
|
+
function trace(form){
|
|
113
|
+
const parent=form?.current?.();
|
|
114
|
+
return parent&&UUID.test(parent.traceId||'')&&UUID.test(parent.spanId||'')
|
|
115
|
+
?{traceId:parent.traceId,spanId:parent.spanId}:null;
|
|
116
|
+
}
|
|
117
|
+
function contextAccess(context){
|
|
118
|
+
if(context?.contextGatewayEnabled?.()!==true)
|
|
119
|
+
throw fail('FORM_CONTEXT_UNAVAILABLE');
|
|
120
|
+
}
|
|
121
|
+
async function request(context,kind,args){
|
|
122
|
+
return context.runContextGateway(
|
|
123
|
+
kind==='get'?'chat_loop_context_get':'chat_loop_context_mutate',args);
|
|
124
|
+
}
|
|
125
|
+
async function prepare(a,context,form){
|
|
126
|
+
check(a,PREP);checkCard(a);
|
|
127
|
+
const formId=a.formId||randomUUID();
|
|
128
|
+
if(a.mode!=='MANAGED'){
|
|
129
|
+
return {status:a.mode==='TEST_ONLY'?'TEST_ONLY_PREVIEW':'FORM_PREPARED_SOFT',
|
|
130
|
+
formId,kind:a.kind||'CUSTOM',
|
|
131
|
+
...(a.documentId?{documentId:a.documentId,version:a.version}:{}),
|
|
132
|
+
view:view(a,formId,null,a.kind!=='CUSTOM'&&a.version>1
|
|
133
|
+
?a.documentId[0]+(a.version-1):null),
|
|
134
|
+
trace:trace(form),approvalAuthority:'NONE',businessSideEffects:false,
|
|
135
|
+
provenance:'FORM_ID_ONLY_NO_DURABLE_ISSUE'};
|
|
136
|
+
}
|
|
137
|
+
if(!HASH.test(a.contentHash||''))throw fail('FORM_CONTENT_HASH_REQUIRED');
|
|
138
|
+
contextAccess(context);
|
|
139
|
+
const doc=await request(context,'get',{operation:'document.get',projectId:a.projectId,
|
|
140
|
+
taskId:a.taskId,documentId:a.documentId,version:a.version});
|
|
141
|
+
if(doc?.kind!==a.kind||doc?.contentHash!==a.contentHash)
|
|
142
|
+
throw fail('FORM_DOCUMENT_MISMATCH');
|
|
143
|
+
const list=await request(context,'get',{operation:'document.list',
|
|
144
|
+
projectId:a.projectId,taskId:a.taskId});
|
|
145
|
+
const prior=Array.isArray(list)&&list.some(x=>x.kind===a.kind&&
|
|
146
|
+
x.version===a.version-1&&x.documentId===a.documentId[0]+(a.version-1))
|
|
147
|
+
?a.documentId[0]+(a.version-1):null;
|
|
148
|
+
const issue=await request(context,'mutate',{operation:'document.prepareIssue',
|
|
149
|
+
projectId:a.projectId,taskId:a.taskId,documentId:a.documentId,
|
|
150
|
+
version:a.version,contentHash:a.contentHash,
|
|
151
|
+
expectedTaskRevision:a.expectedTaskRevision,
|
|
152
|
+
expectedStoreEpoch:a.expectedStoreEpoch,writeRequestId:a.writeRequestId});
|
|
153
|
+
if(issue?.status!=='ISSUE_PENDING'||!ISSUE.test(issue.issueId||''))
|
|
154
|
+
throw fail('FORM_ISSUE_RECEIPT_INVALID');
|
|
155
|
+
// Reuse the durable Issue identity by default to keep MANAGED retries stable;
|
|
156
|
+
// a caller-supplied formId is a separate non-authoritative UI correlation ID.
|
|
157
|
+
const managedFormId=a.formId||issue.issueId;
|
|
158
|
+
return {status:'WAITING_APPROVAL',formId:managedFormId,issueId:issue.issueId,
|
|
159
|
+
documentId:a.documentId,version:a.version,kind:a.kind,
|
|
160
|
+
taskRevision:issue.taskRevision,approvalRevision:issue.approvalRevision,
|
|
161
|
+
writeRequestId:a.writeRequestId,trace:trace(form),
|
|
162
|
+
view:view(a,managedFormId,issue.issueId,prior),approvalAuthority:'CONTEXT',
|
|
163
|
+
businessSideEffects:true};
|
|
164
|
+
}
|
|
165
|
+
async function submit(a,context,form){
|
|
166
|
+
check(a,SUBMIT);
|
|
167
|
+
if(!FORM_ID.test(a.formId||'')||!['A','B'].includes(a.choice)
|
|
168
|
+
||!filled(a.userTurn,256)||!filled(a.presentedAssistantRef,256)
|
|
169
|
+
||!filled(a.writeRequestId,128))
|
|
170
|
+
throw fail('FORM_SUBMISSION_INVALID');
|
|
171
|
+
if(a.choice==='B'&&!filled(a.comment,4000)
|
|
172
|
+
||a.choice==='A'&&a.comment!==undefined&&a.comment!=='')
|
|
173
|
+
throw fail('FORM_COMMENT_INVALID');
|
|
174
|
+
if(a.mode!=='MANAGED'){
|
|
175
|
+
return {status:'FORM_SUBMISSION_OBSERVED_SOFT',formId:a.formId,
|
|
176
|
+
choice:a.choice,trace:trace(form),approvalAuthority:'NONE',
|
|
177
|
+
businessSideEffects:false,preparedFormIdVerified:false,
|
|
178
|
+
platformProvenance:'AGENT_ASSERTED_UNVERIFIED'};
|
|
179
|
+
}
|
|
180
|
+
if(!ISSUE.test(a.issueId||''))throw fail('FORM_ISSUE_REF_REQUIRED');
|
|
181
|
+
contextAccess(context);
|
|
182
|
+
const result=await request(context,'mutate',{operation:'approval.observe',
|
|
183
|
+
projectId:a.projectId,taskId:a.taskId,issueId:a.issueId,
|
|
184
|
+
decision:a.choice==='A'?'APPROVE':'REQUEST_CHANGE',
|
|
185
|
+
sourceRole:'user',userTurn:a.userTurn,
|
|
186
|
+
presentedAssistantRef:a.presentedAssistantRef,
|
|
187
|
+
expectedTaskRevision:a.expectedTaskRevision,
|
|
188
|
+
expectedStoreEpoch:a.expectedStoreEpoch,writeRequestId:a.writeRequestId});
|
|
189
|
+
if(!['APPROVED_SOFT','CHANGE_REQUESTED'].includes(result?.status))
|
|
190
|
+
throw fail('FORM_APPROVAL_RECEIPT_INVALID');
|
|
191
|
+
return {status:result.status,formId:a.formId,issueId:a.issueId,
|
|
192
|
+
kind:result.kind,choice:a.choice,taskRevision:result.taskRevision,
|
|
193
|
+
...(result.approvalRevision?{approvalRevision:result.approvalRevision}:{}),
|
|
194
|
+
writeRequestId:a.writeRequestId,trace:trace(form),
|
|
195
|
+
approvalAuthority:'CONTEXT',proofLevel:'SOFT_USER_TURN',
|
|
196
|
+
formIssueBinding:'CALLER_ASSERTED_UNVERIFIED',
|
|
197
|
+
platformProvenance:'AGENT_ASSERTED_UNVERIFIED'};
|
|
198
|
+
}
|
|
199
|
+
export const provider=Object.freeze({
|
|
200
|
+
id:'form',order:5,names:tools.map(x=>x.name),
|
|
201
|
+
create({context,form}={}){
|
|
202
|
+
return Object.freeze({
|
|
203
|
+
tools:()=>tools,
|
|
204
|
+
async call(name,args){
|
|
205
|
+
try{
|
|
206
|
+
const result=name===tools[0].name
|
|
207
|
+
?await prepare(args,context,form)
|
|
208
|
+
:name===tools[1].name?await submit(args,context,form):null;
|
|
209
|
+
if(result&&args?.projectId&&typeof form?.observe==='function'){
|
|
210
|
+
const parent=trace(form);
|
|
211
|
+
if(parent)setImmediate(()=>{
|
|
212
|
+
// Soft evidence, never an approval receipt or a retry trigger.
|
|
213
|
+
try{void Promise.resolve(form.observe({
|
|
214
|
+
event:name===tools[0].name?'form.prepared.soft_observed'
|
|
215
|
+
:'form.submitted.soft_observed',
|
|
216
|
+
projectRef:args.projectId,taskRef:args.taskId,
|
|
217
|
+
formId:result.formId,...parent
|
|
218
|
+
})).catch(()=>{})}catch{/* telemetry isolation */}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return result?ok(result):err('UNKNOWN_TOOL');
|
|
222
|
+
}catch(e){return err(e.code||'FORM_FAILED')}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
});
|
package/providers.generated.mjs
CHANGED
|
@@ -4,5 +4,6 @@ import {provider as p1} from './providers/extension.mjs';
|
|
|
4
4
|
import {provider as p2} from './providers/runtime.mjs';
|
|
5
5
|
import {provider as p3} from './providers/context.mjs';
|
|
6
6
|
import {provider as p4} from './providers/trace.mjs';
|
|
7
|
-
|
|
8
|
-
export const
|
|
7
|
+
import {provider as p5} from './providers/form.mjs';
|
|
8
|
+
export const providerDefinitions=Object.freeze([p0,p1,p2,p3,p4,p5]);
|
|
9
|
+
export const providerFiles=Object.freeze(["providers/desktop.mjs","providers/extension.mjs","providers/runtime.mjs","providers/context.mjs","providers/trace.mjs","providers/form.mjs"]);
|