@sequenceholdings/agent-spec 0.1.2 → 0.1.4
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 +152 -0
- package/dist/agent-definition.d.ts +626 -0
- package/dist/agent-definition.js +250 -0
- package/dist/canonical-json.d.ts +2 -0
- package/dist/canonical-json.js +13 -0
- package/dist/client-proposals.d.ts +20 -0
- package/dist/client-proposals.js +172 -0
- package/dist/index.d.ts +4 -116
- package/dist/index.js +4 -247
- package/dist/input-schema.d.ts +19 -0
- package/dist/input-schema.js +57 -0
- package/dist/job-request-hash.d.ts +27 -0
- package/dist/job-request-hash.js +54 -0
- package/dist/voice-access.d.ts +40 -0
- package/dist/voice-access.js +34 -0
- package/dist/voice-actions-contracts.d.ts +423 -0
- package/dist/voice-actions-contracts.js +95 -0
- package/dist/voice-actions-transitions.d.ts +52 -0
- package/dist/voice-actions-transitions.js +170 -0
- package/dist/voice-actions.d.ts +2 -0
- package/dist/voice-actions.js +2 -0
- package/dist/voice-api.d.ts +1102 -0
- package/dist/voice-api.js +164 -0
- package/dist/voice-authoring.d.ts +463 -0
- package/dist/voice-authoring.js +132 -0
- package/dist/voice-authority-contracts.d.ts +247 -0
- package/dist/voice-authority-contracts.js +177 -0
- package/dist/voice-authority-evaluation.d.ts +29 -0
- package/dist/voice-authority-evaluation.js +80 -0
- package/dist/voice-authority-verification.d.ts +47 -0
- package/dist/voice-authority-verification.js +184 -0
- package/dist/voice-authority.d.ts +3 -0
- package/dist/voice-authority.js +3 -0
- package/dist/voice-common.d.ts +21 -0
- package/dist/voice-common.js +23 -0
- package/dist/voice-drafts.d.ts +441 -0
- package/dist/voice-drafts.js +75 -0
- package/dist/voice-grant.d.ts +19 -0
- package/dist/voice-grant.js +21 -0
- package/dist/voice-lifecycle-control.d.ts +130 -0
- package/dist/voice-lifecycle-control.js +138 -0
- package/dist/voice-lifecycle-session.d.ts +168 -0
- package/dist/voice-lifecycle-session.js +114 -0
- package/dist/voice-lifecycle-states.d.ts +96 -0
- package/dist/voice-lifecycle-states.js +139 -0
- package/dist/voice-lifecycle.d.ts +3 -0
- package/dist/voice-lifecycle.js +3 -0
- package/dist/voice-policy-duration.d.ts +46 -0
- package/dist/voice-policy-duration.js +166 -0
- package/dist/voice-policy-limits.d.ts +174 -0
- package/dist/voice-policy-limits.js +188 -0
- package/dist/voice-policy.d.ts +2 -0
- package/dist/voice-policy.js +2 -0
- package/dist/voice-provider-evidence.d.ts +80 -0
- package/dist/voice-provider-evidence.js +115 -0
- package/dist/voice-provider-publication.d.ts +319 -0
- package/dist/voice-provider-publication.js +117 -0
- package/dist/voice-provider-release.d.ts +386 -0
- package/dist/voice-provider-release.js +154 -0
- package/dist/voice-provider.d.ts +3 -0
- package/dist/voice-provider.js +3 -0
- package/dist/voice-release.d.ts +808 -0
- package/dist/voice-release.js +110 -0
- package/dist/voice-runs-audio.d.ts +157 -0
- package/dist/voice-runs-audio.js +85 -0
- package/dist/voice-runs-evidence.d.ts +183 -0
- package/dist/voice-runs-evidence.js +154 -0
- package/dist/voice-runs-model.d.ts +967 -0
- package/dist/voice-runs-model.js +199 -0
- package/dist/voice-runs-tooling.d.ts +88 -0
- package/dist/voice-runs-tooling.js +100 -0
- package/dist/voice-runs.d.ts +4 -0
- package/dist/voice-runs.js +4 -0
- package/dist/voice.d.ts +13 -0
- package/dist/voice.js +13 -0
- package/package.json +8 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { voiceTimestampSchema } from './voice-common.js';
|
|
2
|
+
import { sameVoiceResource } from './voice-authority-contracts.js';
|
|
3
|
+
import { voiceActionIntentBindingSchema, voiceActionIntentStateSchema, voiceActionIntentTransitionSchema, voicePrepareActionRequestSchema, voicePreparedActionIntentSchema, } from './voice-actions-contracts.js';
|
|
4
|
+
function sameCallSubject({ left, right }) {
|
|
5
|
+
return left.tenantId === right.tenantId &&
|
|
6
|
+
left.environmentId === right.environmentId &&
|
|
7
|
+
left.agentId === right.agentId &&
|
|
8
|
+
left.sessionId === right.sessionId &&
|
|
9
|
+
left.releaseId === right.releaseId;
|
|
10
|
+
}
|
|
11
|
+
function sameAuthoritySubject({ left, right }) {
|
|
12
|
+
if (left.kind !== right.kind)
|
|
13
|
+
return false;
|
|
14
|
+
if (left.kind === 'unverified' || right.kind === 'unverified') {
|
|
15
|
+
return left.kind === right.kind;
|
|
16
|
+
}
|
|
17
|
+
return sameVoiceResource({ left: left.resource, right: right.resource }) &&
|
|
18
|
+
left.verificationId === right.verificationId;
|
|
19
|
+
}
|
|
20
|
+
function bindingFromState({ state }) {
|
|
21
|
+
return {
|
|
22
|
+
intentId: state.intentId,
|
|
23
|
+
subject: state.subject,
|
|
24
|
+
actionAlias: state.actionAlias,
|
|
25
|
+
authoritySubject: state.authoritySubject,
|
|
26
|
+
argumentDigest: state.argumentDigest,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function sameIntentBinding({ left, right }) {
|
|
30
|
+
return left.intentId === right.intentId &&
|
|
31
|
+
sameCallSubject({ left: left.subject, right: right.subject }) &&
|
|
32
|
+
left.actionAlias === right.actionAlias &&
|
|
33
|
+
sameAuthoritySubject({ left: left.authoritySubject, right: right.authoritySubject }) &&
|
|
34
|
+
left.argumentDigest === right.argumentDigest;
|
|
35
|
+
}
|
|
36
|
+
export function prepareVoiceActionIntent({ request, existing }) {
|
|
37
|
+
const parsedRequest = voicePrepareActionRequestSchema.parse(request);
|
|
38
|
+
if (existing !== null) {
|
|
39
|
+
const parsedExisting = voiceActionIntentStateSchema.parse(existing);
|
|
40
|
+
return sameIntentBinding({
|
|
41
|
+
left: bindingFromState({ state: parsedExisting }), right: parsedRequest.binding,
|
|
42
|
+
})
|
|
43
|
+
? { outcome: 'retry', state: parsedExisting }
|
|
44
|
+
: { outcome: 'conflict', reason: 'intent_binding_conflict' };
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
outcome: 'prepared',
|
|
48
|
+
state: voicePreparedActionIntentSchema.parse({
|
|
49
|
+
...parsedRequest.binding, state: 'prepared',
|
|
50
|
+
confirmationSummary: parsedRequest.confirmationSummary,
|
|
51
|
+
preparedAt: parsedRequest.preparedAt, expiresAt: parsedRequest.expiresAt,
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function decideVoiceActionConfirmation({ state, binding, now }) {
|
|
56
|
+
const parsedState = voiceActionIntentStateSchema.parse(state);
|
|
57
|
+
const parsedBinding = voiceActionIntentBindingSchema.parse(binding);
|
|
58
|
+
const parsedNow = voiceTimestampSchema.parse(now);
|
|
59
|
+
if (!sameIntentBinding({ left: bindingFromState({ state: parsedState }),
|
|
60
|
+
right: parsedBinding })) {
|
|
61
|
+
return { decision: 'conflict', reason: 'intent_binding_conflict' };
|
|
62
|
+
}
|
|
63
|
+
if (parsedState.state === 'committed') {
|
|
64
|
+
return { decision: 'return_receipt', receipt: parsedState };
|
|
65
|
+
}
|
|
66
|
+
if (parsedState.state === 'cancelled') {
|
|
67
|
+
return { decision: 'denied', reason: 'intent_cancelled' };
|
|
68
|
+
}
|
|
69
|
+
if (parsedState.state === 'uncertain') {
|
|
70
|
+
return { decision: 'reconcile', reason: 'uncertain_outcome' };
|
|
71
|
+
}
|
|
72
|
+
return Date.parse(parsedNow) >= Date.parse(parsedState.expiresAt)
|
|
73
|
+
? { decision: 'denied', reason: 'intent_expired' }
|
|
74
|
+
: { decision: 'dispatch' };
|
|
75
|
+
}
|
|
76
|
+
function sameCommittedReceipt({ state, transition }) {
|
|
77
|
+
return state.receiptId === transition.receiptId &&
|
|
78
|
+
state.resultDigest === transition.resultDigest &&
|
|
79
|
+
state.resultStatus === transition.resultStatus &&
|
|
80
|
+
state.committedAt === transition.occurredAt;
|
|
81
|
+
}
|
|
82
|
+
function sameCancellationReceipt({ state, transition }) {
|
|
83
|
+
return state.cancellationReceiptId === transition.cancellationReceiptId &&
|
|
84
|
+
state.cancellationResolution === transition.resolution &&
|
|
85
|
+
state.cancelledAt === transition.occurredAt;
|
|
86
|
+
}
|
|
87
|
+
function terminalTransition({ state, transition }) {
|
|
88
|
+
if (state.state === 'committed') {
|
|
89
|
+
if (transition.kind !== 'commit')
|
|
90
|
+
return { outcome: 'denied', reason: 'terminal_intent' };
|
|
91
|
+
return sameCommittedReceipt({ state, transition })
|
|
92
|
+
? { outcome: 'retry', state }
|
|
93
|
+
: { outcome: 'conflict', reason: 'terminal_receipt_conflict' };
|
|
94
|
+
}
|
|
95
|
+
if (state.state === 'cancelled') {
|
|
96
|
+
if (transition.kind !== 'cancel')
|
|
97
|
+
return { outcome: 'denied', reason: 'terminal_intent' };
|
|
98
|
+
return sameCancellationReceipt({ state, transition })
|
|
99
|
+
? { outcome: 'retry', state }
|
|
100
|
+
: { outcome: 'conflict', reason: 'terminal_receipt_conflict' };
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
function uncertaintyTransition({ state, transition }) {
|
|
105
|
+
if (state.state === 'uncertain') {
|
|
106
|
+
const same = state.dispatchAttemptId === transition.dispatchAttemptId &&
|
|
107
|
+
state.uncertainAt === transition.occurredAt;
|
|
108
|
+
return same ? { outcome: 'retry', state }
|
|
109
|
+
: { outcome: 'denied', reason: 'uncertain_requires_reconciliation' };
|
|
110
|
+
}
|
|
111
|
+
if (Date.parse(transition.occurredAt) >= Date.parse(state.expiresAt)) {
|
|
112
|
+
return { outcome: 'denied', reason: 'intent_expired' };
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
outcome: 'transitioned',
|
|
116
|
+
state: {
|
|
117
|
+
...bindingFromState({ state }), state: 'uncertain',
|
|
118
|
+
confirmationSummary: state.confirmationSummary, preparedAt: state.preparedAt,
|
|
119
|
+
expiresAt: state.expiresAt, dispatchAttemptId: transition.dispatchAttemptId,
|
|
120
|
+
uncertainAt: transition.occurredAt,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function commitTransition({ state, transition }) {
|
|
125
|
+
const expired = state.state === 'prepared' &&
|
|
126
|
+
Date.parse(transition.occurredAt) >= Date.parse(state.expiresAt);
|
|
127
|
+
if (expired)
|
|
128
|
+
return { outcome: 'denied', reason: 'intent_expired' };
|
|
129
|
+
return {
|
|
130
|
+
outcome: 'transitioned',
|
|
131
|
+
state: {
|
|
132
|
+
...bindingFromState({ state }), state: 'committed', receiptId: transition.receiptId,
|
|
133
|
+
resultDigest: transition.resultDigest, resultStatus: transition.resultStatus,
|
|
134
|
+
committedAt: transition.occurredAt,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function cancelTransition({ state, transition }) {
|
|
139
|
+
const invalid = (state.state === 'uncertain' && transition.resolution !== 'confirmed_not_committed') ||
|
|
140
|
+
(state.state === 'prepared' && transition.resolution !== 'local_before_dispatch');
|
|
141
|
+
if (invalid)
|
|
142
|
+
return { outcome: 'denied', reason: 'uncertain_requires_reconciliation' };
|
|
143
|
+
return {
|
|
144
|
+
outcome: 'transitioned',
|
|
145
|
+
state: {
|
|
146
|
+
...bindingFromState({ state }), state: 'cancelled',
|
|
147
|
+
cancellationReceiptId: transition.cancellationReceiptId,
|
|
148
|
+
cancellationResolution: transition.resolution, cancelledAt: transition.occurredAt,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export function transitionVoiceActionIntent({ state, transition }) {
|
|
153
|
+
const parsedState = voiceActionIntentStateSchema.parse(state);
|
|
154
|
+
const parsedTransition = voiceActionIntentTransitionSchema.parse(transition);
|
|
155
|
+
if (!sameIntentBinding({ left: bindingFromState({ state: parsedState }),
|
|
156
|
+
right: parsedTransition.binding })) {
|
|
157
|
+
return { outcome: 'conflict', reason: 'intent_binding_conflict' };
|
|
158
|
+
}
|
|
159
|
+
if (parsedState.state === 'committed' || parsedState.state === 'cancelled') {
|
|
160
|
+
const terminal = terminalTransition({ state: parsedState, transition: parsedTransition });
|
|
161
|
+
return terminal ?? { outcome: 'denied', reason: 'terminal_intent' };
|
|
162
|
+
}
|
|
163
|
+
if (parsedTransition.kind === 'mark_uncertain') {
|
|
164
|
+
return uncertaintyTransition({ state: parsedState, transition: parsedTransition });
|
|
165
|
+
}
|
|
166
|
+
if (parsedTransition.kind === 'commit') {
|
|
167
|
+
return commitTransition({ state: parsedState, transition: parsedTransition });
|
|
168
|
+
}
|
|
169
|
+
return cancelTransition({ state: parsedState, transition: parsedTransition });
|
|
170
|
+
}
|