@arbidocs/sdk 0.4.75 → 0.4.77
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/dist/{browser-BBYaJCyB.d.cts → browser-CK4WQdVH.d.cts} +6290 -5188
- package/dist/{browser-BBYaJCyB.d.ts → browser-CK4WQdVH.d.ts} +6290 -5188
- package/dist/browser.cjs +821 -12
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +820 -13
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +821 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +820 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3494,9 +3494,16 @@ var ArbiSessionExpiredError = class extends ArbiError {
|
|
|
3494
3494
|
}
|
|
3495
3495
|
};
|
|
3496
3496
|
function detailText(detail) {
|
|
3497
|
-
if (
|
|
3498
|
-
|
|
3499
|
-
|
|
3497
|
+
if (typeof detail === "string") return detail || void 0;
|
|
3498
|
+
if (Array.isArray(detail)) {
|
|
3499
|
+
const messages = detail.map((d2) => d2?.msg).filter((m2) => Boolean(m2));
|
|
3500
|
+
return messages.length ? messages.join("; ") : void 0;
|
|
3501
|
+
}
|
|
3502
|
+
if (!detail || typeof detail !== "object") return void 0;
|
|
3503
|
+
const message = typeof detail.message === "string" ? detail.message : void 0;
|
|
3504
|
+
const fields = detail.fields && typeof detail.fields === "object" && !Array.isArray(detail.fields) ? Object.entries(detail.fields).map(([name, problem]) => `${name}: ${String(problem)}`).join("; ") : "";
|
|
3505
|
+
if (message) return fields ? `${message} (${fields})` : message;
|
|
3506
|
+
return fields || void 0;
|
|
3500
3507
|
}
|
|
3501
3508
|
function apiErrorDetail(apiError) {
|
|
3502
3509
|
if (typeof apiError === "string") return apiError || void 0;
|
|
@@ -4461,6 +4468,12 @@ async function streamSSE(response, callbacks = {}) {
|
|
|
4461
4468
|
const { events, remaining } = parseSSEEvents(decoder.decode(value, { stream: true }), sseBuffer);
|
|
4462
4469
|
sseBuffer = remaining;
|
|
4463
4470
|
processEvents(events);
|
|
4471
|
+
if (completed) {
|
|
4472
|
+
sseBuffer = "";
|
|
4473
|
+
void reader.cancel().catch(() => {
|
|
4474
|
+
});
|
|
4475
|
+
break;
|
|
4476
|
+
}
|
|
4464
4477
|
}
|
|
4465
4478
|
if (sseBuffer.trim()) {
|
|
4466
4479
|
const { events } = parseSSEEvents(sseBuffer + "\n\n", "");
|
|
@@ -5692,11 +5705,25 @@ function extractResponseText(response) {
|
|
|
5692
5705
|
// src/operations/tags.ts
|
|
5693
5706
|
var tags_exports = {};
|
|
5694
5707
|
__export(tags_exports, {
|
|
5708
|
+
TAG_FIELD_TYPES: () => TAG_FIELD_TYPES,
|
|
5695
5709
|
createTag: () => createTag,
|
|
5696
5710
|
deleteTag: () => deleteTag,
|
|
5711
|
+
getTagMatrix: () => getTagMatrix,
|
|
5697
5712
|
listTags: () => listTags,
|
|
5698
|
-
|
|
5713
|
+
mergeTagFieldDefinitions: () => mergeTagFieldDefinitions,
|
|
5714
|
+
ownTagFields: () => ownTagFields,
|
|
5715
|
+
tagMatrixColumns: () => tagMatrixColumns,
|
|
5716
|
+
updateTag: () => updateTag,
|
|
5717
|
+
updateTagFields: () => updateTagFields
|
|
5699
5718
|
});
|
|
5719
|
+
var TAG_FIELD_TYPES = [
|
|
5720
|
+
"text",
|
|
5721
|
+
"number",
|
|
5722
|
+
"date",
|
|
5723
|
+
"checkbox",
|
|
5724
|
+
"select",
|
|
5725
|
+
"person"
|
|
5726
|
+
];
|
|
5700
5727
|
async function listTags(arbi) {
|
|
5701
5728
|
return requireData(await arbi.fetch.GET("/v1/tag/list"), "Failed to fetch tags");
|
|
5702
5729
|
}
|
|
@@ -5707,7 +5734,10 @@ async function createTag(arbi, options) {
|
|
|
5707
5734
|
name: options.name,
|
|
5708
5735
|
tag_type: options.tagType ?? { type: "checkbox", options: [] },
|
|
5709
5736
|
instruction: options.instruction ?? null,
|
|
5710
|
-
shared: options.shared ?? false
|
|
5737
|
+
shared: options.shared ?? false,
|
|
5738
|
+
...options.parentId ? { parent_ext_id: options.parentId } : {},
|
|
5739
|
+
...options.fields ? { fields: options.fields } : {},
|
|
5740
|
+
...options.fieldValues ? { field_values: options.fieldValues } : {}
|
|
5711
5741
|
}
|
|
5712
5742
|
}),
|
|
5713
5743
|
"Failed to create tag"
|
|
@@ -5730,6 +5760,46 @@ async function updateTag(arbi, tagId, body) {
|
|
|
5730
5760
|
"Failed to update tag"
|
|
5731
5761
|
);
|
|
5732
5762
|
}
|
|
5763
|
+
async function updateTagFields(arbi, tagId, change) {
|
|
5764
|
+
const body = {};
|
|
5765
|
+
if (change.fields) body.fields = change.fields;
|
|
5766
|
+
if (change.values) body.field_values = change.values;
|
|
5767
|
+
return updateTag(arbi, tagId, body);
|
|
5768
|
+
}
|
|
5769
|
+
async function getTagMatrix(arbi, selection, linksLimit) {
|
|
5770
|
+
const query = "parentId" in selection ? { parent_ext_id: selection.parentId } : { tag_ext_id: selection.tagIds };
|
|
5771
|
+
if (linksLimit !== void 0) query.links_limit = linksLimit;
|
|
5772
|
+
return requireData(
|
|
5773
|
+
await arbi.fetch.GET("/v1/tag/matrix", { params: { query } }),
|
|
5774
|
+
"Failed to fetch the tag matrix"
|
|
5775
|
+
);
|
|
5776
|
+
}
|
|
5777
|
+
function tagMatrixColumns(matrix) {
|
|
5778
|
+
const columns = [];
|
|
5779
|
+
const add = (f2) => {
|
|
5780
|
+
if (!columns.some((c2) => c2.id === f2.id)) columns.push(f2);
|
|
5781
|
+
};
|
|
5782
|
+
for (const f2 of matrix.parent?.fields ?? []) add(f2);
|
|
5783
|
+
for (const row of matrix.rows ?? []) for (const f2 of row.tag.fields ?? []) add(f2);
|
|
5784
|
+
return columns;
|
|
5785
|
+
}
|
|
5786
|
+
function ownTagFields(tag) {
|
|
5787
|
+
return (tag.fields ?? []).filter((f2) => f2.tag_ext_id === tag.external_id);
|
|
5788
|
+
}
|
|
5789
|
+
function mergeTagFieldDefinitions(tag, wanted, { keepOthers = false } = {}) {
|
|
5790
|
+
const own = ownTagFields(tag);
|
|
5791
|
+
const byName = new Map(own.map((f2) => [f2.name.toLowerCase(), f2]));
|
|
5792
|
+
const out = wanted.map((w2) => {
|
|
5793
|
+
const old = w2.id ? void 0 : byName.get(w2.name.trim().toLowerCase());
|
|
5794
|
+
return old ? { ...w2, id: old.id } : w2;
|
|
5795
|
+
});
|
|
5796
|
+
if (keepOthers) {
|
|
5797
|
+
for (const f2 of own)
|
|
5798
|
+
if (!out.some((w2) => w2.id === f2.id))
|
|
5799
|
+
out.push({ id: f2.id, name: f2.name, type: f2.type, options: f2.options ?? null });
|
|
5800
|
+
}
|
|
5801
|
+
return out;
|
|
5802
|
+
}
|
|
5733
5803
|
|
|
5734
5804
|
// src/operations/contacts.ts
|
|
5735
5805
|
var contacts_exports = {};
|
|
@@ -6545,25 +6615,88 @@ var projects_exports = {};
|
|
|
6545
6615
|
__export(projects_exports, {
|
|
6546
6616
|
createProject: () => createProject,
|
|
6547
6617
|
deleteProject: () => deleteProject,
|
|
6618
|
+
formatBudget: () => formatBudget,
|
|
6619
|
+
getProjectConversationUsage: () => getProjectConversationUsage,
|
|
6548
6620
|
getProjectInvoices: () => getProjectInvoices,
|
|
6549
6621
|
getProjectUsage: () => getProjectUsage,
|
|
6550
6622
|
getUserUsageToday: () => getUserUsageToday,
|
|
6623
|
+
listProjectEvents: () => listProjectEvents,
|
|
6551
6624
|
listProjects: () => listProjects,
|
|
6625
|
+
parseBudget: () => parseBudget,
|
|
6552
6626
|
refreshProject: () => refreshProject,
|
|
6553
6627
|
renameProject: () => renameProject,
|
|
6554
6628
|
updateProject: () => updateProject
|
|
6555
6629
|
});
|
|
6556
|
-
async function listProjects(arbi) {
|
|
6557
|
-
|
|
6630
|
+
async function listProjects(arbi, filters = {}) {
|
|
6631
|
+
const query = {};
|
|
6632
|
+
if (filters.stage) query.stage = filters.stage;
|
|
6633
|
+
if (filters.leadUser) query.lead_user = filters.leadUser;
|
|
6634
|
+
return requireData(
|
|
6635
|
+
await arbi.fetch.GET(
|
|
6636
|
+
"/v1/user/projects/",
|
|
6637
|
+
Object.keys(query).length ? { params: { query } } : void 0
|
|
6638
|
+
),
|
|
6639
|
+
"Failed to fetch projects"
|
|
6640
|
+
);
|
|
6558
6641
|
}
|
|
6559
|
-
async function createProject(arbi, name, plan = "free") {
|
|
6642
|
+
async function createProject(arbi, name, plan = "free", details = {}) {
|
|
6560
6643
|
return requireData(
|
|
6561
6644
|
await arbi.fetch.POST("/v1/user/projects/", {
|
|
6562
|
-
body: { name, plan }
|
|
6645
|
+
body: { ...details, name, plan }
|
|
6563
6646
|
}),
|
|
6564
6647
|
"Failed to create project"
|
|
6565
6648
|
);
|
|
6566
6649
|
}
|
|
6650
|
+
async function listProjectEvents(arbi, projectExtId, options = {}) {
|
|
6651
|
+
const query = {};
|
|
6652
|
+
if (options.kind) query.kind = options.kind;
|
|
6653
|
+
if (options.limit !== void 0) query.limit = options.limit;
|
|
6654
|
+
return requireData(
|
|
6655
|
+
await arbi.fetch.GET("/v1/user/projects/{project_ext_id}/events", {
|
|
6656
|
+
params: { path: { project_ext_id: projectExtId }, query }
|
|
6657
|
+
}),
|
|
6658
|
+
"Failed to fetch project events"
|
|
6659
|
+
);
|
|
6660
|
+
}
|
|
6661
|
+
async function getProjectConversationUsage(arbi, projectExtId, monthsBack) {
|
|
6662
|
+
return requireData(
|
|
6663
|
+
await arbi.fetch.GET("/v1/user/projects/{project_ext_id}/usage/conversations", {
|
|
6664
|
+
params: {
|
|
6665
|
+
path: { project_ext_id: projectExtId },
|
|
6666
|
+
query: monthsBack === void 0 ? void 0 : { months_back: monthsBack }
|
|
6667
|
+
}
|
|
6668
|
+
}),
|
|
6669
|
+
"Failed to fetch project usage by conversation"
|
|
6670
|
+
);
|
|
6671
|
+
}
|
|
6672
|
+
function minorDigits(currency) {
|
|
6673
|
+
try {
|
|
6674
|
+
return new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits ?? 2;
|
|
6675
|
+
} catch {
|
|
6676
|
+
throw new Error(`Unknown currency "${currency}": use an ISO 4217 code such as GBP or USD`);
|
|
6677
|
+
}
|
|
6678
|
+
}
|
|
6679
|
+
function parseBudget(text) {
|
|
6680
|
+
const t2 = text.trim();
|
|
6681
|
+
const after = /^([0-9][0-9,_]*(?:\.[0-9]+)?)\s*([A-Za-z]{3})$/.exec(t2);
|
|
6682
|
+
const before = /^([A-Za-z]{3})\s*([0-9][0-9,_]*(?:\.[0-9]+)?)$/.exec(t2);
|
|
6683
|
+
const [amountText, code] = after ? [after[1], after[2]] : before ? [before[2], before[1]] : [];
|
|
6684
|
+
if (!amountText || !code)
|
|
6685
|
+
throw new Error(`Invalid budget "${text}": use an amount and a currency, e.g. 6000GBP`);
|
|
6686
|
+
const currency = code.toUpperCase();
|
|
6687
|
+
const digits = minorDigits(currency);
|
|
6688
|
+
const major = Number(amountText.replace(/[,_]/g, ""));
|
|
6689
|
+
const amount = Math.round(major * 10 ** digits);
|
|
6690
|
+
if (!Number.isFinite(major) || Math.abs(major * 10 ** digits - amount) > 1e-6)
|
|
6691
|
+
throw new Error(`Invalid budget "${text}": ${currency} has ${digits} decimal places`);
|
|
6692
|
+
return { amount, currency };
|
|
6693
|
+
}
|
|
6694
|
+
function formatBudget(budget) {
|
|
6695
|
+
if (!budget) return "";
|
|
6696
|
+
const digits = minorDigits(budget.currency);
|
|
6697
|
+
const major = budget.amount / 10 ** digits;
|
|
6698
|
+
return `${budget.currency} ${major.toLocaleString("en", { minimumFractionDigits: digits, maximumFractionDigits: digits })}`;
|
|
6699
|
+
}
|
|
6567
6700
|
async function updateProject(arbi, projectExtId, body) {
|
|
6568
6701
|
return requireData(
|
|
6569
6702
|
await arbi.fetch.PATCH("/v1/user/projects/{project_ext_id}", {
|
|
@@ -6619,14 +6752,603 @@ async function getUserUsageToday(arbi) {
|
|
|
6619
6752
|
var work_exports = {};
|
|
6620
6753
|
__export(work_exports, {
|
|
6621
6754
|
actOnStep: () => actOnStep,
|
|
6755
|
+
completeStep: () => completeStep,
|
|
6622
6756
|
createWork: () => createWork,
|
|
6623
6757
|
getActivity: () => getActivity,
|
|
6758
|
+
getConversation: () => getConversation,
|
|
6759
|
+
getConversationUsage: () => getConversationUsage,
|
|
6624
6760
|
getPendingAuth: () => getPendingAuth,
|
|
6761
|
+
getRunProgress: () => getRunProgress,
|
|
6762
|
+
getStepAnswers: () => getStepAnswers,
|
|
6625
6763
|
notifyConversation: () => notifyConversation,
|
|
6626
6764
|
planWork: () => planWork,
|
|
6627
6765
|
runConversation: () => runConversation,
|
|
6766
|
+
sendBackStep: () => sendBackStep,
|
|
6767
|
+
skipStep: () => skipStep,
|
|
6628
6768
|
updateConversation: () => updateConversation
|
|
6629
6769
|
});
|
|
6770
|
+
|
|
6771
|
+
// src/workflow-steps.ts
|
|
6772
|
+
var workflow_steps_exports = {};
|
|
6773
|
+
__export(workflow_steps_exports, {
|
|
6774
|
+
PERSON_STEP_KINDS: () => PERSON_STEP_KINDS,
|
|
6775
|
+
PlanStepsError: () => PlanStepsError,
|
|
6776
|
+
SIGNAL_NAME_PATTERN: () => SIGNAL_NAME_PATTERN,
|
|
6777
|
+
STEP_FIELD_TYPES: () => STEP_FIELD_TYPES,
|
|
6778
|
+
STEP_ID_PATTERN: () => STEP_ID_PATTERN,
|
|
6779
|
+
STEP_KINDS: () => STEP_KINDS,
|
|
6780
|
+
checkStepInputs: () => checkStepInputs,
|
|
6781
|
+
describeAssignee: () => describeAssignee,
|
|
6782
|
+
describeInputProblems: () => describeInputProblems,
|
|
6783
|
+
isPersonStep: () => isPersonStep,
|
|
6784
|
+
linkedRuns: () => linkedRuns,
|
|
6785
|
+
messageWorkflowStep: () => messageWorkflowStep,
|
|
6786
|
+
missingRequiredFields: () => missingRequiredFields,
|
|
6787
|
+
parseInputPairs: () => parseInputPairs,
|
|
6788
|
+
parsePlanSteps: () => parsePlanSteps,
|
|
6789
|
+
raisedSignals: () => raisedSignals,
|
|
6790
|
+
runSteps: () => runSteps,
|
|
6791
|
+
runWaitingOn: () => runWaitingOn,
|
|
6792
|
+
sendBacks: () => sendBacks,
|
|
6793
|
+
stepDependencies: () => stepDependencies,
|
|
6794
|
+
stepFields: () => stepFields,
|
|
6795
|
+
stepPhase: () => stepPhase,
|
|
6796
|
+
stepStatesFromActivity: () => stepStatesFromActivity,
|
|
6797
|
+
stepsPlan: () => stepsPlan
|
|
6798
|
+
});
|
|
6799
|
+
var STEP_KINDS = ["form", "upload", "agent", "review"];
|
|
6800
|
+
var PERSON_STEP_KINDS = ["form", "upload", "review"];
|
|
6801
|
+
var STEP_ID_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
6802
|
+
var STEP_EVENTS = {
|
|
6803
|
+
step_started: "running",
|
|
6804
|
+
step_done: "done",
|
|
6805
|
+
step_skipped: "skipped",
|
|
6806
|
+
step_failed: "failed"
|
|
6807
|
+
};
|
|
6808
|
+
var EMPTY_STATE = {
|
|
6809
|
+
status: "pending",
|
|
6810
|
+
responseId: null,
|
|
6811
|
+
error: null,
|
|
6812
|
+
sentBack: false,
|
|
6813
|
+
hasNote: false,
|
|
6814
|
+
announcedTo: null
|
|
6815
|
+
};
|
|
6816
|
+
var str = (v2) => typeof v2 === "string" ? v2 : null;
|
|
6817
|
+
var isFinished = (state) => state?.status === "done" || state?.status === "skipped";
|
|
6818
|
+
var isPersonStep = (step) => PERSON_STEP_KINDS.includes(step.kind);
|
|
6819
|
+
function stepDependencies(steps, id) {
|
|
6820
|
+
const i2 = steps.findIndex((s2) => s2.id === id);
|
|
6821
|
+
if (i2 < 0) return [];
|
|
6822
|
+
const after = steps[i2].after;
|
|
6823
|
+
if (after !== null && after !== void 0) return [...after];
|
|
6824
|
+
return i2 > 0 ? [steps[i2 - 1].id] : [];
|
|
6825
|
+
}
|
|
6826
|
+
function dependsOn(steps, a2, b2) {
|
|
6827
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6828
|
+
const stack = stepDependencies(steps, a2);
|
|
6829
|
+
while (stack.length) {
|
|
6830
|
+
const id = stack.pop();
|
|
6831
|
+
if (id === b2) return true;
|
|
6832
|
+
if (seen.has(id)) continue;
|
|
6833
|
+
seen.add(id);
|
|
6834
|
+
stack.push(...stepDependencies(steps, id));
|
|
6835
|
+
}
|
|
6836
|
+
return false;
|
|
6837
|
+
}
|
|
6838
|
+
function reopenedBy(detail) {
|
|
6839
|
+
const to = str(detail.to);
|
|
6840
|
+
const listed = Array.isArray(detail.reopened) ? detail.reopened : to ? [to] : [];
|
|
6841
|
+
return listed.filter((id) => typeof id === "string");
|
|
6842
|
+
}
|
|
6843
|
+
function stepStatesFromActivity(events) {
|
|
6844
|
+
const states = {};
|
|
6845
|
+
for (const e of events) {
|
|
6846
|
+
const detail = e.detail ?? {};
|
|
6847
|
+
const step = str(detail.step);
|
|
6848
|
+
if (!step) continue;
|
|
6849
|
+
if (e.kind === "step_sent_back") {
|
|
6850
|
+
const to = str(detail.to);
|
|
6851
|
+
for (const id of reopenedBy(detail))
|
|
6852
|
+
states[id] = {
|
|
6853
|
+
...EMPTY_STATE,
|
|
6854
|
+
sentBack: id === to,
|
|
6855
|
+
hasNote: id === to && typeof detail.note_encrypted === "string"
|
|
6856
|
+
};
|
|
6857
|
+
continue;
|
|
6858
|
+
}
|
|
6859
|
+
if (e.kind === "step_ready") {
|
|
6860
|
+
states[step] = { ...states[step] ?? EMPTY_STATE, announcedTo: str(detail.to) };
|
|
6861
|
+
continue;
|
|
6862
|
+
}
|
|
6863
|
+
const status = STEP_EVENTS[e.kind];
|
|
6864
|
+
if (!status) continue;
|
|
6865
|
+
states[step] = {
|
|
6866
|
+
...EMPTY_STATE,
|
|
6867
|
+
status,
|
|
6868
|
+
responseId: str(detail.response_id) ?? states[step]?.responseId ?? null,
|
|
6869
|
+
error: str(detail.error)
|
|
6870
|
+
};
|
|
6871
|
+
}
|
|
6872
|
+
return states;
|
|
6873
|
+
}
|
|
6874
|
+
function raisedSignals(events) {
|
|
6875
|
+
return events.flatMap((e) => {
|
|
6876
|
+
const step = str(e.detail?.step);
|
|
6877
|
+
const signal = str(e.detail?.signal);
|
|
6878
|
+
return e.kind === "step_signal" && step && signal ? [{ step, signal, at: e.created_at ?? null }] : [];
|
|
6879
|
+
});
|
|
6880
|
+
}
|
|
6881
|
+
function linkedRuns(events) {
|
|
6882
|
+
return events.flatMap((e) => {
|
|
6883
|
+
const conversationId = str(e.detail?.conversation_ext_id);
|
|
6884
|
+
return e.kind === "linked_run" && conversationId ? [
|
|
6885
|
+
{
|
|
6886
|
+
step: str(e.detail?.step),
|
|
6887
|
+
signal: str(e.detail?.signal),
|
|
6888
|
+
conversationId,
|
|
6889
|
+
workflowId: str(e.detail?.workflow_ext_id),
|
|
6890
|
+
at: e.created_at ?? null
|
|
6891
|
+
}
|
|
6892
|
+
] : [];
|
|
6893
|
+
});
|
|
6894
|
+
}
|
|
6895
|
+
function sendBacks(events) {
|
|
6896
|
+
return events.flatMap((e) => {
|
|
6897
|
+
const detail = e.detail ?? {};
|
|
6898
|
+
const step = str(detail.step);
|
|
6899
|
+
const to = str(detail.to);
|
|
6900
|
+
return e.kind === "step_sent_back" && step && to ? [
|
|
6901
|
+
{
|
|
6902
|
+
step,
|
|
6903
|
+
to,
|
|
6904
|
+
reopened: reopenedBy(detail),
|
|
6905
|
+
hasNote: typeof detail.note_encrypted === "string",
|
|
6906
|
+
by: e.actor_ext_id ?? null,
|
|
6907
|
+
at: e.created_at ?? null
|
|
6908
|
+
}
|
|
6909
|
+
] : [];
|
|
6910
|
+
});
|
|
6911
|
+
}
|
|
6912
|
+
function stepPhase(steps, states, id) {
|
|
6913
|
+
const state = states[id];
|
|
6914
|
+
if (state && state.status !== "pending") return state.status;
|
|
6915
|
+
return stepDependencies(steps, id).every((d2) => isFinished(states[d2])) ? "ready" : "pending";
|
|
6916
|
+
}
|
|
6917
|
+
function runSteps(steps, events) {
|
|
6918
|
+
const states = stepStatesFromActivity(events);
|
|
6919
|
+
const signals = raisedSignals(events);
|
|
6920
|
+
const links = linkedRuns(events);
|
|
6921
|
+
const backs = sendBacks(events);
|
|
6922
|
+
return steps.map((s2) => {
|
|
6923
|
+
const state = states[s2.id] ?? EMPTY_STATE;
|
|
6924
|
+
return {
|
|
6925
|
+
id: s2.id,
|
|
6926
|
+
title: s2.title,
|
|
6927
|
+
kind: s2.kind,
|
|
6928
|
+
phase: stepPhase(steps, states, s2.id),
|
|
6929
|
+
after: stepDependencies(steps, s2.id),
|
|
6930
|
+
responseId: state.responseId,
|
|
6931
|
+
error: state.error,
|
|
6932
|
+
assignee: s2.assignee ?? null,
|
|
6933
|
+
announcedTo: state.announcedTo,
|
|
6934
|
+
sentBack: state.sentBack,
|
|
6935
|
+
hasNote: state.hasNote,
|
|
6936
|
+
timesSentBack: backs.filter((b2) => b2.to === s2.id).length,
|
|
6937
|
+
signals: [...new Set(signals.filter((x2) => x2.step === s2.id).map((x2) => x2.signal))],
|
|
6938
|
+
linkedRuns: links.filter((l2) => l2.step === s2.id)
|
|
6939
|
+
};
|
|
6940
|
+
});
|
|
6941
|
+
}
|
|
6942
|
+
function describeAssignee(assignee) {
|
|
6943
|
+
if (!assignee) return "";
|
|
6944
|
+
if (assignee.user) return assignee.user;
|
|
6945
|
+
if (assignee.run_owner) return "run owner";
|
|
6946
|
+
if (assignee.project_lead) return "project lead";
|
|
6947
|
+
if (assignee.input) return `input:${assignee.input}`;
|
|
6948
|
+
return "";
|
|
6949
|
+
}
|
|
6950
|
+
function messageWorkflowStep(message) {
|
|
6951
|
+
const tool = message.tools?.workflow_step;
|
|
6952
|
+
return str(tool?.workflow_step);
|
|
6953
|
+
}
|
|
6954
|
+
function runWaitingOn(run) {
|
|
6955
|
+
if (run.length > 0 && run.every((s2) => s2.phase === "done" || s2.phase === "skipped"))
|
|
6956
|
+
return "finished";
|
|
6957
|
+
if (run.some((s2) => s2.phase === "running" || s2.kind === "agent" && s2.phase === "ready"))
|
|
6958
|
+
return "agent";
|
|
6959
|
+
if (run.some((s2) => s2.kind !== "agent" && s2.phase === "ready")) return "person";
|
|
6960
|
+
return "stuck";
|
|
6961
|
+
}
|
|
6962
|
+
var STEP_FIELD_TYPES = [
|
|
6963
|
+
"text",
|
|
6964
|
+
"longtext",
|
|
6965
|
+
"boolean",
|
|
6966
|
+
"select",
|
|
6967
|
+
"number",
|
|
6968
|
+
"date",
|
|
6969
|
+
"scope",
|
|
6970
|
+
"documents",
|
|
6971
|
+
"person"
|
|
6972
|
+
];
|
|
6973
|
+
function stepFields(step) {
|
|
6974
|
+
if (step.kind === "agent") return [];
|
|
6975
|
+
if (Array.isArray(step.fields)) return step.fields;
|
|
6976
|
+
if (step.kind !== "form") return [];
|
|
6977
|
+
const fields = step.ui?.fields;
|
|
6978
|
+
return Array.isArray(fields) ? fields : [];
|
|
6979
|
+
}
|
|
6980
|
+
var blank = (value) => {
|
|
6981
|
+
if (value === void 0 || value === null) return true;
|
|
6982
|
+
if (typeof value === "string") return value.trim() === "";
|
|
6983
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
6984
|
+
if (isRecord(value)) return !["documents", "folders", "labels"].some((k2) => !blank(value[k2]));
|
|
6985
|
+
return false;
|
|
6986
|
+
};
|
|
6987
|
+
function missingRequiredFields(step, inputs) {
|
|
6988
|
+
return stepFields(step).filter((f2) => f2.required && blank(inputs[f2.name])).map((f2) => f2.name);
|
|
6989
|
+
}
|
|
6990
|
+
var PERSON_ID = /^(?:usr|agt)-[a-zA-Z0-9]{8}$/;
|
|
6991
|
+
function fieldProblem(field, value) {
|
|
6992
|
+
if (blank(value)) return field.required ? "required" : null;
|
|
6993
|
+
switch (field.type ?? "text") {
|
|
6994
|
+
case "number": {
|
|
6995
|
+
const n2 = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
6996
|
+
if (Number.isNaN(n2)) return "number";
|
|
6997
|
+
if (field.min !== null && field.min !== void 0 && n2 < field.min) return "min";
|
|
6998
|
+
if (field.max !== null && field.max !== void 0 && n2 > field.max) return "max";
|
|
6999
|
+
return null;
|
|
7000
|
+
}
|
|
7001
|
+
case "boolean":
|
|
7002
|
+
return typeof value === "boolean" ? null : "type";
|
|
7003
|
+
case "select": {
|
|
7004
|
+
if (typeof value !== "string") return "type";
|
|
7005
|
+
const options = (field.options ?? []).map((o2) => o2.value);
|
|
7006
|
+
return options.length === 0 || options.includes(value) ? null : "option";
|
|
7007
|
+
}
|
|
7008
|
+
case "date":
|
|
7009
|
+
return typeof value === "string" && !Number.isNaN(Date.parse(value)) ? null : "type";
|
|
7010
|
+
case "scope":
|
|
7011
|
+
case "documents":
|
|
7012
|
+
return typeof value === "object" ? null : "type";
|
|
7013
|
+
case "person":
|
|
7014
|
+
return typeof value === "string" && PERSON_ID.test(value) ? null : "type";
|
|
7015
|
+
default:
|
|
7016
|
+
return typeof value === "string" || typeof value === "number" ? null : "type";
|
|
7017
|
+
}
|
|
7018
|
+
}
|
|
7019
|
+
function checkStepInputs(step, inputs) {
|
|
7020
|
+
if (!Array.isArray(step.fields)) return {};
|
|
7021
|
+
const given = inputs ?? {};
|
|
7022
|
+
const byName = new Map(step.fields.map((f2) => [f2.name, f2]));
|
|
7023
|
+
const problems = {};
|
|
7024
|
+
for (const name of Object.keys(given)) if (!byName.has(name)) problems[name] = "unknown";
|
|
7025
|
+
for (const [name, field] of byName) {
|
|
7026
|
+
const problem = fieldProblem(field, given[name]);
|
|
7027
|
+
if (problem) problems[name] = problem;
|
|
7028
|
+
}
|
|
7029
|
+
return problems;
|
|
7030
|
+
}
|
|
7031
|
+
function describeInputProblems(step, problems) {
|
|
7032
|
+
const fields = new Map((step.fields ?? []).map((f2) => [f2.name, f2]));
|
|
7033
|
+
return Object.entries(problems).map(([name, problem]) => {
|
|
7034
|
+
const f2 = fields.get(name);
|
|
7035
|
+
switch (problem) {
|
|
7036
|
+
case "unknown":
|
|
7037
|
+
return `${name}: this step does not ask for it (it asks for ${[...fields.keys()].join(", ") || "nothing"})`;
|
|
7038
|
+
case "option":
|
|
7039
|
+
return `${name}: must be one of ${(f2?.options ?? []).map((o2) => o2.value).join(", ")}`;
|
|
7040
|
+
case "min":
|
|
7041
|
+
return `${name}: must be at least ${f2?.min}`;
|
|
7042
|
+
case "max":
|
|
7043
|
+
return `${name}: must be at most ${f2?.max}`;
|
|
7044
|
+
case "number":
|
|
7045
|
+
return `${name}: must be a number`;
|
|
7046
|
+
case "type":
|
|
7047
|
+
return `${name}: must be a ${f2?.type === "person" ? "person id (usr-\u2026 or agt-\u2026)" : f2?.type ?? "value"}`;
|
|
7048
|
+
default:
|
|
7049
|
+
return `${name}: ${problem}`;
|
|
7050
|
+
}
|
|
7051
|
+
}).join("; ");
|
|
7052
|
+
}
|
|
7053
|
+
function parseInputPairs(pairs, fields = []) {
|
|
7054
|
+
const types = new Map(fields.map((f2) => [f2.name, f2.type]));
|
|
7055
|
+
const out = {};
|
|
7056
|
+
for (const pair of pairs) {
|
|
7057
|
+
const eq = pair.indexOf("=");
|
|
7058
|
+
if (eq <= 0) throw new Error(`Invalid input "${pair}": use name=value`);
|
|
7059
|
+
const name = pair.slice(0, eq).trim();
|
|
7060
|
+
const raw = pair.slice(eq + 1);
|
|
7061
|
+
const type = types.get(name);
|
|
7062
|
+
if (type === "number") {
|
|
7063
|
+
const n2 = Number(raw);
|
|
7064
|
+
if (raw.trim() === "" || Number.isNaN(n2))
|
|
7065
|
+
throw new Error(`Input "${name}" must be a number, got "${raw}"`);
|
|
7066
|
+
out[name] = n2;
|
|
7067
|
+
} else if (type === "boolean") {
|
|
7068
|
+
if (!["true", "false"].includes(raw.toLowerCase()))
|
|
7069
|
+
throw new Error(`Input "${name}" must be true or false, got "${raw}"`);
|
|
7070
|
+
out[name] = raw.toLowerCase() === "true";
|
|
7071
|
+
} else out[name] = raw;
|
|
7072
|
+
}
|
|
7073
|
+
return out;
|
|
7074
|
+
}
|
|
7075
|
+
var STEP_KEYS = /* @__PURE__ */ new Set([
|
|
7076
|
+
"id",
|
|
7077
|
+
"title",
|
|
7078
|
+
"kind",
|
|
7079
|
+
"after",
|
|
7080
|
+
"skill",
|
|
7081
|
+
"prompt",
|
|
7082
|
+
"inputs",
|
|
7083
|
+
"branch",
|
|
7084
|
+
"requires_files",
|
|
7085
|
+
"ui",
|
|
7086
|
+
"signals",
|
|
7087
|
+
"assignee",
|
|
7088
|
+
"remind_after_hours",
|
|
7089
|
+
"fields"
|
|
7090
|
+
]);
|
|
7091
|
+
var SIGNAL_NAME_PATTERN = /^[a-z0-9][a-z0-9_.-]{0,63}$/;
|
|
7092
|
+
var FIELD_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_]{0,63}$/;
|
|
7093
|
+
var WHEN_KEYS = ["field", "equals", "contains", "matches", "approved"];
|
|
7094
|
+
var ASSIGNEE_KEYS = ["user", "run_owner", "input", "project_lead"];
|
|
7095
|
+
var isRecord = (v2) => typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
|
|
7096
|
+
var PlanStepsError = class extends Error {
|
|
7097
|
+
constructor(problems) {
|
|
7098
|
+
super(`Invalid workflow steps:
|
|
7099
|
+
${problems.map((p2) => ` - ${p2}`).join("\n")}`);
|
|
7100
|
+
this.problems = problems;
|
|
7101
|
+
this.name = "PlanStepsError";
|
|
7102
|
+
}
|
|
7103
|
+
problems;
|
|
7104
|
+
};
|
|
7105
|
+
var isSet = (v2) => v2 !== void 0 && v2 !== null;
|
|
7106
|
+
function checkSignals(value, at2, problems) {
|
|
7107
|
+
if (!Array.isArray(value)) {
|
|
7108
|
+
problems.push(
|
|
7109
|
+
`${at2}: must be a list of signals, e.g. [{name: risk-high, when: {contains: High}}]`
|
|
7110
|
+
);
|
|
7111
|
+
return;
|
|
7112
|
+
}
|
|
7113
|
+
if (value.length > 10) problems.push(`${at2}: at most 10 signals per step`);
|
|
7114
|
+
value.forEach((signal, j2) => {
|
|
7115
|
+
const here = `${at2}[${j2}]`;
|
|
7116
|
+
if (!isRecord(signal)) {
|
|
7117
|
+
problems.push(`${here}: must be an object with a name`);
|
|
7118
|
+
return;
|
|
7119
|
+
}
|
|
7120
|
+
for (const key of Object.keys(signal))
|
|
7121
|
+
if (key !== "name" && key !== "when")
|
|
7122
|
+
problems.push(`${here}.${key}: unknown field (allowed: name, when)`);
|
|
7123
|
+
if (typeof signal.name !== "string" || !SIGNAL_NAME_PATTERN.test(signal.name))
|
|
7124
|
+
problems.push(
|
|
7125
|
+
`${here}.name: lowercase letters, digits, ".", "_" or "-", starting with a letter or digit (got ${JSON.stringify(signal.name)})`
|
|
7126
|
+
);
|
|
7127
|
+
const when = signal.when;
|
|
7128
|
+
if (!isSet(when)) return;
|
|
7129
|
+
if (!isRecord(when)) {
|
|
7130
|
+
problems.push(`${here}.when: must be an object`);
|
|
7131
|
+
return;
|
|
7132
|
+
}
|
|
7133
|
+
for (const key of Object.keys(when))
|
|
7134
|
+
if (!WHEN_KEYS.includes(key))
|
|
7135
|
+
problems.push(`${here}.when.${key}: unknown field (allowed: ${WHEN_KEYS.join(", ")})`);
|
|
7136
|
+
const shapes = [
|
|
7137
|
+
isSet(when.field) || isSet(when.equals),
|
|
7138
|
+
isSet(when.contains),
|
|
7139
|
+
isSet(when.matches),
|
|
7140
|
+
isSet(when.approved)
|
|
7141
|
+
].filter(Boolean).length;
|
|
7142
|
+
if (shapes !== 1)
|
|
7143
|
+
problems.push(
|
|
7144
|
+
`${here}.when: exactly one of field+equals (a form value), contains or matches (an agent's answer), or approved (a review)`
|
|
7145
|
+
);
|
|
7146
|
+
if (isSet(when.field) !== isSet(when.equals))
|
|
7147
|
+
problems.push(`${here}.when: a field condition needs both field and equals`);
|
|
7148
|
+
if (isSet(when.field) && typeof when.field !== "string")
|
|
7149
|
+
problems.push(`${here}.when.field: must be a field name`);
|
|
7150
|
+
if (isSet(when.equals) && !["string", "number", "boolean"].includes(typeof when.equals))
|
|
7151
|
+
problems.push(`${here}.when.equals: must be text, a number or true/false`);
|
|
7152
|
+
for (const key of ["contains", "matches"])
|
|
7153
|
+
if (isSet(when[key]) && (typeof when[key] !== "string" || !when[key].trim()))
|
|
7154
|
+
problems.push(`${here}.when.${key}: must be text`);
|
|
7155
|
+
if (typeof when.matches === "string")
|
|
7156
|
+
try {
|
|
7157
|
+
new RegExp(when.matches);
|
|
7158
|
+
} catch (err) {
|
|
7159
|
+
problems.push(
|
|
7160
|
+
`${here}.when.matches: not a valid regular expression (${err.message})`
|
|
7161
|
+
);
|
|
7162
|
+
}
|
|
7163
|
+
if (isSet(when.approved) && typeof when.approved !== "boolean")
|
|
7164
|
+
problems.push(`${here}.when.approved: true or false`);
|
|
7165
|
+
});
|
|
7166
|
+
}
|
|
7167
|
+
function checkAssignee(value, at2, problems) {
|
|
7168
|
+
const hint = `one of {user: usr-\u2026}, {run_owner: true}, {input: <person field>} or {project_lead: true}`;
|
|
7169
|
+
if (!isRecord(value)) {
|
|
7170
|
+
problems.push(`${at2}: must be ${hint}`);
|
|
7171
|
+
return;
|
|
7172
|
+
}
|
|
7173
|
+
for (const key of Object.keys(value))
|
|
7174
|
+
if (!ASSIGNEE_KEYS.includes(key)) problems.push(`${at2}.${key}: unknown field (${hint})`);
|
|
7175
|
+
const set = ASSIGNEE_KEYS.filter((k2) => isSet(value[k2]));
|
|
7176
|
+
if (set.length !== 1) problems.push(`${at2}: exactly ${hint}`);
|
|
7177
|
+
if (isSet(value.user) && (typeof value.user !== "string" || !PERSON_ID.test(value.user)))
|
|
7178
|
+
problems.push(`${at2}.user: a person or agent id (usr-\u2026 or agt-\u2026)`);
|
|
7179
|
+
for (const key of ["run_owner", "project_lead"])
|
|
7180
|
+
if (isSet(value[key]) && value[key] !== true) problems.push(`${at2}.${key}: must be true`);
|
|
7181
|
+
if (isSet(value.input) && (typeof value.input !== "string" || !FIELD_NAME_PATTERN.test(value.input)))
|
|
7182
|
+
problems.push(`${at2}.input: the name of a person field, e.g. "reviewer"`);
|
|
7183
|
+
}
|
|
7184
|
+
function checkFields(value, at2, problems) {
|
|
7185
|
+
if (!Array.isArray(value)) {
|
|
7186
|
+
problems.push(`${at2}: must be a list of fields, e.g. [{name: rating, type: select}]`);
|
|
7187
|
+
return;
|
|
7188
|
+
}
|
|
7189
|
+
if (value.length > 50) problems.push(`${at2}: at most 50 fields`);
|
|
7190
|
+
const names = /* @__PURE__ */ new Set();
|
|
7191
|
+
value.forEach((f2, j2) => {
|
|
7192
|
+
const here = `${at2}[${j2}]`;
|
|
7193
|
+
if (!isRecord(f2)) {
|
|
7194
|
+
problems.push(`${here}: must be an object with a name`);
|
|
7195
|
+
return;
|
|
7196
|
+
}
|
|
7197
|
+
if (typeof f2.name !== "string" || !FIELD_NAME_PATTERN.test(f2.name))
|
|
7198
|
+
problems.push(`${here}.name: a field needs a name like "rating" (letters, digits, "_")`);
|
|
7199
|
+
else if (names.has(f2.name)) problems.push(`${here}.name: "${f2.name}" is used twice`);
|
|
7200
|
+
else names.add(f2.name);
|
|
7201
|
+
if (isSet(f2.type) && !STEP_FIELD_TYPES.includes(f2.type))
|
|
7202
|
+
problems.push(
|
|
7203
|
+
`${here}.type: must be one of ${STEP_FIELD_TYPES.join(", ")} (got ${JSON.stringify(f2.type)})`
|
|
7204
|
+
);
|
|
7205
|
+
if (isSet(f2.label) && typeof f2.label !== "string") problems.push(`${here}.label: must be text`);
|
|
7206
|
+
if (isSet(f2.required) && typeof f2.required !== "boolean")
|
|
7207
|
+
problems.push(`${here}.required: true or false`);
|
|
7208
|
+
for (const key of ["min", "max"])
|
|
7209
|
+
if (isSet(f2[key]) && typeof f2[key] !== "number") problems.push(`${here}.${key}: a number`);
|
|
7210
|
+
if (isSet(f2.options)) {
|
|
7211
|
+
if (!Array.isArray(f2.options) || f2.options.some((o2) => !isRecord(o2) || typeof o2.value !== "string"))
|
|
7212
|
+
problems.push(`${here}.options: a list of {value, label}, e.g. [{value: high}]`);
|
|
7213
|
+
}
|
|
7214
|
+
});
|
|
7215
|
+
}
|
|
7216
|
+
var normalFields = (fields) => fields.map((f2) => ({
|
|
7217
|
+
...f2,
|
|
7218
|
+
name: f2.name,
|
|
7219
|
+
type: f2.type ?? "text",
|
|
7220
|
+
required: !!f2.required
|
|
7221
|
+
}));
|
|
7222
|
+
function checkStep(raw, at2, problems) {
|
|
7223
|
+
if (!isRecord(raw)) {
|
|
7224
|
+
problems.push(`${at2}: must be an object with id, title and kind`);
|
|
7225
|
+
return null;
|
|
7226
|
+
}
|
|
7227
|
+
const before = problems.length;
|
|
7228
|
+
for (const key of Object.keys(raw))
|
|
7229
|
+
if (!STEP_KEYS.has(key))
|
|
7230
|
+
problems.push(`${at2}.${key}: unknown field (allowed: ${[...STEP_KEYS].join(", ")})`);
|
|
7231
|
+
const { id, title, kind, after, skill, prompt, inputs, branch, ui } = raw;
|
|
7232
|
+
if (typeof id !== "string" || !STEP_ID_PATTERN.test(id))
|
|
7233
|
+
problems.push(
|
|
7234
|
+
`${at2}.id: must be lowercase letters, digits, "_" or "-", starting with a letter (got ${JSON.stringify(id)})`
|
|
7235
|
+
);
|
|
7236
|
+
if (typeof title !== "string" || !title.trim()) problems.push(`${at2}.title: required text`);
|
|
7237
|
+
if (typeof kind !== "string" || !STEP_KINDS.includes(kind))
|
|
7238
|
+
problems.push(
|
|
7239
|
+
`${at2}.kind: must be one of ${STEP_KINDS.join(", ")} (got ${JSON.stringify(kind)})`
|
|
7240
|
+
);
|
|
7241
|
+
if (after !== void 0 && after !== null) {
|
|
7242
|
+
if (!Array.isArray(after) || after.some((d2) => typeof d2 !== "string"))
|
|
7243
|
+
problems.push(`${at2}.after: must be a list of step ids`);
|
|
7244
|
+
}
|
|
7245
|
+
for (const [key, value] of [
|
|
7246
|
+
["skill", skill],
|
|
7247
|
+
["prompt", prompt]
|
|
7248
|
+
])
|
|
7249
|
+
if (value !== void 0 && value !== null && typeof value !== "string")
|
|
7250
|
+
problems.push(`${at2}.${key}: must be text`);
|
|
7251
|
+
if (inputs !== void 0 && inputs !== null) {
|
|
7252
|
+
if (!isRecord(inputs) || Object.values(inputs).some((v2) => typeof v2 !== "string"))
|
|
7253
|
+
problems.push(
|
|
7254
|
+
`${at2}.inputs: must map each skill input to a text template, e.g. {"q": "{{topic}}"}`
|
|
7255
|
+
);
|
|
7256
|
+
}
|
|
7257
|
+
if (branch !== void 0 && typeof branch !== "boolean")
|
|
7258
|
+
problems.push(`${at2}.branch: true or false`);
|
|
7259
|
+
if (ui !== void 0 && ui !== null && !isRecord(ui)) problems.push(`${at2}.ui: must be an object`);
|
|
7260
|
+
if (kind === "agent") {
|
|
7261
|
+
const hasSkill = typeof skill === "string" && skill.trim() !== "";
|
|
7262
|
+
const hasPrompt = typeof prompt === "string" && prompt.trim() !== "";
|
|
7263
|
+
if (!hasSkill && !hasPrompt) problems.push(`${at2}: an agent step needs a prompt or a skill`);
|
|
7264
|
+
if (hasSkill && hasPrompt)
|
|
7265
|
+
problems.push(`${at2}: an agent step runs a prompt or a skill, not both`);
|
|
7266
|
+
} else if (typeof kind === "string" && STEP_KINDS.includes(kind)) {
|
|
7267
|
+
for (const [key, value] of [
|
|
7268
|
+
["skill", skill],
|
|
7269
|
+
["prompt", prompt],
|
|
7270
|
+
["inputs", inputs]
|
|
7271
|
+
])
|
|
7272
|
+
if (value !== void 0 && value !== null)
|
|
7273
|
+
problems.push(`${at2}.${key}: only agent steps have a ${key} (this is a ${kind} step)`);
|
|
7274
|
+
if (branch) problems.push(`${at2}.branch: only agent steps can branch`);
|
|
7275
|
+
}
|
|
7276
|
+
const { signals, assignee, remind_after_hours: remind, fields: stepFieldsRaw } = raw;
|
|
7277
|
+
if (isSet(signals)) checkSignals(signals, `${at2}.signals`, problems);
|
|
7278
|
+
if (isSet(assignee)) checkAssignee(assignee, `${at2}.assignee`, problems);
|
|
7279
|
+
if (isSet(remind)) {
|
|
7280
|
+
if (typeof remind !== "number" || !(remind > 0) || remind > 24 * 365)
|
|
7281
|
+
problems.push(`${at2}.remind_after_hours: a number of hours above 0 (at most a year: 8760)`);
|
|
7282
|
+
else if (kind === "agent")
|
|
7283
|
+
problems.push(`${at2}.remind_after_hours: only a step that waits for a person can remind them`);
|
|
7284
|
+
}
|
|
7285
|
+
if (isSet(stepFieldsRaw)) {
|
|
7286
|
+
if (kind === "agent")
|
|
7287
|
+
problems.push(`${at2}.fields: an agent step has no fields: a person step asks for them`);
|
|
7288
|
+
else checkFields(stepFieldsRaw, `${at2}.fields`, problems);
|
|
7289
|
+
}
|
|
7290
|
+
if (kind === "form" && isRecord(ui) && ui.fields !== void 0) {
|
|
7291
|
+
if (!Array.isArray(ui.fields)) problems.push(`${at2}.ui.fields: must be a list of fields`);
|
|
7292
|
+
else
|
|
7293
|
+
ui.fields.forEach((f2, j2) => {
|
|
7294
|
+
if (!isRecord(f2) || typeof f2.name !== "string" || !/^[a-z][a-z0-9_]*$/i.test(f2.name))
|
|
7295
|
+
problems.push(`${at2}.ui.fields[${j2}].name: a field needs a name like "client_name"`);
|
|
7296
|
+
});
|
|
7297
|
+
}
|
|
7298
|
+
if (problems.length > before) return null;
|
|
7299
|
+
const fields = kind === "form" && isRecord(ui) && Array.isArray(ui.fields) ? ui.fields.map((f2) => ({
|
|
7300
|
+
...f2,
|
|
7301
|
+
type: typeof f2.type === "string" ? f2.type : "text",
|
|
7302
|
+
label: typeof f2.label === "string" ? f2.label : f2.name
|
|
7303
|
+
})) : void 0;
|
|
7304
|
+
return {
|
|
7305
|
+
id,
|
|
7306
|
+
title: title.trim(),
|
|
7307
|
+
kind,
|
|
7308
|
+
after: after ?? null,
|
|
7309
|
+
skill: skill ?? null,
|
|
7310
|
+
prompt: prompt ?? null,
|
|
7311
|
+
inputs: inputs ?? null,
|
|
7312
|
+
branch: !!branch,
|
|
7313
|
+
requires_files: !!raw.requires_files,
|
|
7314
|
+
ui: isRecord(ui) ? { ...ui, ...fields ? { fields } : {} } : null,
|
|
7315
|
+
...isSet(signals) ? { signals } : {},
|
|
7316
|
+
...isSet(assignee) ? { assignee } : {},
|
|
7317
|
+
...isSet(remind) ? { remind_after_hours: remind } : {},
|
|
7318
|
+
...isSet(stepFieldsRaw) ? { fields: normalFields(stepFieldsRaw) } : {}
|
|
7319
|
+
};
|
|
7320
|
+
}
|
|
7321
|
+
function parsePlanSteps(value) {
|
|
7322
|
+
const list = isRecord(value) ? value.steps : value;
|
|
7323
|
+
if (!Array.isArray(list))
|
|
7324
|
+
throw new PlanStepsError(['expected a list of steps, or an object with a "steps" list']);
|
|
7325
|
+
if (list.length === 0) throw new PlanStepsError(["a workflow needs at least one step"]);
|
|
7326
|
+
const problems = [];
|
|
7327
|
+
const steps = list.map((raw, i2) => checkStep(raw, `steps[${i2}]`, problems));
|
|
7328
|
+
if (problems.length) throw new PlanStepsError(problems);
|
|
7329
|
+
const valid = steps;
|
|
7330
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7331
|
+
valid.forEach((s2, i2) => {
|
|
7332
|
+
if (ids.has(s2.id)) problems.push(`steps[${i2}].id: "${s2.id}" is used twice`);
|
|
7333
|
+
ids.add(s2.id);
|
|
7334
|
+
});
|
|
7335
|
+
valid.forEach((s2, i2) => {
|
|
7336
|
+
for (const d2 of stepDependencies(valid, s2.id)) {
|
|
7337
|
+
if (!ids.has(d2)) problems.push(`steps[${i2}].after: no step "${d2}"`);
|
|
7338
|
+
else if (d2 === s2.id || dependsOn(valid, d2, s2.id))
|
|
7339
|
+
problems.push(`steps[${i2}].after: "${s2.id}" and "${d2}" wait for each other`);
|
|
7340
|
+
else if (valid.findIndex((x2) => x2.id === d2) > i2)
|
|
7341
|
+
problems.push(`steps[${i2}].after: "${d2}" must come before "${s2.id}" in the list`);
|
|
7342
|
+
}
|
|
7343
|
+
});
|
|
7344
|
+
if (problems.length) throw new PlanStepsError(problems);
|
|
7345
|
+
return valid;
|
|
7346
|
+
}
|
|
7347
|
+
function stepsPlan(steps) {
|
|
7348
|
+
return { goal: "", criteria: [], max_passes: 3, documents: [], steps };
|
|
7349
|
+
}
|
|
7350
|
+
|
|
7351
|
+
// src/operations/work.ts
|
|
6630
7352
|
var byId = (conversationId) => ({
|
|
6631
7353
|
params: { path: { conversation_ext_id: conversationId } }
|
|
6632
7354
|
});
|
|
@@ -6669,6 +7391,30 @@ async function actOnStep(arbi, conversationId, body) {
|
|
|
6669
7391
|
"Failed to update the workflow step"
|
|
6670
7392
|
);
|
|
6671
7393
|
}
|
|
7394
|
+
async function completeStep(arbi, conversationId, step, inputs) {
|
|
7395
|
+
return actOnStep(arbi, conversationId, {
|
|
7396
|
+
step,
|
|
7397
|
+
action: "complete",
|
|
7398
|
+
...inputs && Object.keys(inputs).length ? { inputs } : {}
|
|
7399
|
+
});
|
|
7400
|
+
}
|
|
7401
|
+
async function skipStep(arbi, conversationId, step) {
|
|
7402
|
+
return actOnStep(arbi, conversationId, { step, action: "skip" });
|
|
7403
|
+
}
|
|
7404
|
+
async function sendBackStep(arbi, conversationId, step, options = {}) {
|
|
7405
|
+
return actOnStep(arbi, conversationId, {
|
|
7406
|
+
step,
|
|
7407
|
+
action: "send_back",
|
|
7408
|
+
...options.to ? { to: options.to } : {},
|
|
7409
|
+
...options.note?.trim() ? { note: options.note.trim() } : {}
|
|
7410
|
+
});
|
|
7411
|
+
}
|
|
7412
|
+
async function getConversationUsage(arbi, conversationId) {
|
|
7413
|
+
return requireData(
|
|
7414
|
+
await arbi.fetch.GET("/v1/conversation/{conversation_ext_id}/usage", byId(conversationId)),
|
|
7415
|
+
"Failed to fetch the conversation usage"
|
|
7416
|
+
);
|
|
7417
|
+
}
|
|
6672
7418
|
async function notifyConversation(arbi, conversationId, userIds) {
|
|
6673
7419
|
return requireData(
|
|
6674
7420
|
await arbi.fetch.POST("/v1/conversation/{conversation_ext_id}/notify", {
|
|
@@ -6690,6 +7436,46 @@ async function planWork(arbi, body) {
|
|
|
6690
7436
|
"Failed to draft a plan"
|
|
6691
7437
|
);
|
|
6692
7438
|
}
|
|
7439
|
+
async function getConversation(arbi, conversationId) {
|
|
7440
|
+
const all = requireData(
|
|
7441
|
+
await arbi.fetch.GET("/v1/conversation/list"),
|
|
7442
|
+
"Failed to fetch conversations"
|
|
7443
|
+
);
|
|
7444
|
+
const found = all.find((c2) => c2.external_id === conversationId);
|
|
7445
|
+
if (!found) throw new Error(`No conversation ${conversationId} in this workspace`);
|
|
7446
|
+
return found;
|
|
7447
|
+
}
|
|
7448
|
+
async function getRunProgress(arbi, conversationId) {
|
|
7449
|
+
const [conversation, activity] = await Promise.all([
|
|
7450
|
+
getConversation(arbi, conversationId),
|
|
7451
|
+
getActivity(arbi, conversationId)
|
|
7452
|
+
]);
|
|
7453
|
+
const plan = conversation.plan?.steps ?? [];
|
|
7454
|
+
if (!plan.length)
|
|
7455
|
+
throw new Error(`${conversationId} is not a stepped workflow run (its plan has no steps)`);
|
|
7456
|
+
const steps = runSteps(plan, activity);
|
|
7457
|
+
return {
|
|
7458
|
+
conversation,
|
|
7459
|
+
steps,
|
|
7460
|
+
waitingOn: runWaitingOn(steps),
|
|
7461
|
+
signals: raisedSignals(activity),
|
|
7462
|
+
linkedRuns: linkedRuns(activity),
|
|
7463
|
+
sendBacks: sendBacks(activity)
|
|
7464
|
+
};
|
|
7465
|
+
}
|
|
7466
|
+
async function getStepAnswers(arbi, conversationId, responseIds) {
|
|
7467
|
+
if (!responseIds.length) return {};
|
|
7468
|
+
const data = requireData(
|
|
7469
|
+
await arbi.fetch.GET("/v1/conversation/{conversation_ext_id}/threads", byId(conversationId)),
|
|
7470
|
+
"Failed to fetch the thread"
|
|
7471
|
+
);
|
|
7472
|
+
const wanted = new Set(responseIds);
|
|
7473
|
+
const out = {};
|
|
7474
|
+
for (const thread of data.threads ?? [])
|
|
7475
|
+
for (const m2 of thread.history ?? [])
|
|
7476
|
+
if (wanted.has(m2.external_id) && typeof m2.content === "string") out[m2.external_id] = m2.content;
|
|
7477
|
+
return out;
|
|
7478
|
+
}
|
|
6693
7479
|
|
|
6694
7480
|
// src/operations/workflows.ts
|
|
6695
7481
|
var workflows_exports = {};
|
|
@@ -7054,8 +7840,15 @@ var Arbi = class {
|
|
|
7054
7840
|
}
|
|
7055
7841
|
// ── Projects ──────────────────────────────────────────────────────────
|
|
7056
7842
|
projects = {
|
|
7057
|
-
|
|
7058
|
-
|
|
7843
|
+
/** The caller's projects; only those at `stage` and/or led by `leadUser` when given. */
|
|
7844
|
+
list: (filters) => listProjects(this.requireClient(), filters),
|
|
7845
|
+
create: (name, plan, details) => createProject(this.requireClient(), name, plan, details),
|
|
7846
|
+
/** Patch a project: name, daily cap, budget, client, stage, lead, fields (merged key by key). */
|
|
7847
|
+
update: (projectExtId, body) => updateProject(this.requireClient(), projectExtId, body),
|
|
7848
|
+
/** The project's stage and budget changes, newest first. */
|
|
7849
|
+
events: (projectExtId, options) => listProjectEvents(this.requireClient(), projectExtId, options),
|
|
7850
|
+
/** The project's spend by conversation in a billing period (credits). */
|
|
7851
|
+
usageByConversation: (projectExtId, monthsBack) => getProjectConversationUsage(this.requireClient(), projectExtId, monthsBack),
|
|
7059
7852
|
refresh: (projectExtId) => refreshProject(this.requireClient(), projectExtId),
|
|
7060
7853
|
/** AI usage + spend breakdown for a project's billing period. */
|
|
7061
7854
|
usage: (projectExtId, monthsBack) => getProjectUsage(this.requireClient(), projectExtId, monthsBack),
|
|
@@ -7332,6 +8125,16 @@ var Arbi = class {
|
|
|
7332
8125
|
activity: (conversationId) => getActivity(this.requireClient(), conversationId),
|
|
7333
8126
|
/** Complete or skip a step of a workflow run; the run goes on to its next agent step. */
|
|
7334
8127
|
actOnStep: (conversationId, body) => actOnStep(this.requireClient(), conversationId, body),
|
|
8128
|
+
/** Complete a person step (with its inputs, checked against the step's `fields`). */
|
|
8129
|
+
completeStep: (conversationId, step, inputs) => completeStep(this.requireClient(), conversationId, step, inputs),
|
|
8130
|
+
/** Skip a step so what waits for it can go on. */
|
|
8131
|
+
skipStep: (conversationId, step) => skipStep(this.requireClient(), conversationId, step),
|
|
8132
|
+
/** Send the work back from a person step to an earlier one (`to`), with an optional note. */
|
|
8133
|
+
sendBackStep: (conversationId, step, options) => sendBackStep(this.requireClient(), conversationId, step, options),
|
|
8134
|
+
/** A stepped run's steps, signals, linked runs and send-backs, and what it waits for. */
|
|
8135
|
+
runProgress: (conversationId) => getRunProgress(this.requireClient(), conversationId),
|
|
8136
|
+
/** What the conversation's AI work cost: by step, run, model, agent and feature (credits). */
|
|
8137
|
+
usage: (conversationId) => getConversationUsage(this.requireClient(), conversationId),
|
|
7335
8138
|
/** Notify people about a conversation (each gets a notification); resolves with who was. */
|
|
7336
8139
|
notify: (conversationId, userIds) => notifyConversation(this.requireClient(), conversationId, userIds),
|
|
7337
8140
|
/** Draft an editable plan from an objective. */
|
|
@@ -7475,7 +8278,11 @@ var Arbi = class {
|
|
|
7475
8278
|
workspaceId: options.workspaceId ?? this.requireWorkspace()
|
|
7476
8279
|
}),
|
|
7477
8280
|
delete: (tagId) => deleteTag(this.requireClient(), tagId),
|
|
7478
|
-
update: (tagId, body) => updateTag(this.requireClient(), tagId, body)
|
|
8281
|
+
update: (tagId, body) => updateTag(this.requireClient(), tagId, body),
|
|
8282
|
+
/** Replace a tag's own field definitions and/or merge-patch its values (`null` clears one). */
|
|
8283
|
+
updateFields: (tagId, change) => updateTagFields(this.requireClient(), tagId, change),
|
|
8284
|
+
/** Tags as rows (a parent's children, or the given tags) with field values, docs and facts. */
|
|
8285
|
+
matrix: (selection, linksLimit) => getTagMatrix(this.requireClient(), selection, linksLimit)
|
|
7479
8286
|
};
|
|
7480
8287
|
// ── Document Tags ─────────────────────────────────────────────────────
|
|
7481
8288
|
doctags = {
|
|
@@ -8892,6 +9699,6 @@ async function startDmListener(options) {
|
|
|
8892
9699
|
};
|
|
8893
9700
|
}
|
|
8894
9701
|
|
|
8895
|
-
export { Arbi, ArbiApiError, ArbiError, ArbiSessionExpiredError, ClaudeOrchestrator, DOC_TERMINAL_STATUSES, FileConfigStore, OpenClawOrchestrator, WebSocketAuthError, account_exports as account, agentconfig_exports as agentconfig, agents_exports as agents, assistant_exports as assistant, authenticatedFetch, buildDocNameMap, buildFactsContextTool, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts_exports as contacts, conversations_exports as conversations, countCitations, createAuthenticatedClient, createDocumentWaiter, device_flow_exports as deviceFlow, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, facts_exports as facts, files_exports as files, filterSkills, formatAgentStepLabel, formatFileSize, formatItemLabel, formatStreamSummary, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, generateNewWorkspaceKey, getErrorCode, getErrorMessage, getRawWorkspaceKey, health_exports as health, identityErrorCode, identity_exports as identityVerification, listen_exports as listen, mail_exports as mail, mail_node_exports as mailNode, parseSSEEvents, parseSlashCommand, parseSlashTokenInProgress, performPasswordLogin, performSigningKeyLogin, performSsoDeviceFlowLogin, profile_exports as profile, projects_exports as projects, requireData, requireOk, resolveAuth, resolveCitations, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, sessions_exports as sessions, settings_exports as settings, startDmListener, streamSSE, stripCitationMarkdown, summarizeCitations, tags_exports as tags, work_exports as work, workflows_exports as workflows, workspaces_exports as workspaces };
|
|
9702
|
+
export { Arbi, ArbiApiError, ArbiError, ArbiSessionExpiredError, ClaudeOrchestrator, DOC_TERMINAL_STATUSES, FileConfigStore, OpenClawOrchestrator, PlanStepsError, WebSocketAuthError, account_exports as account, agentconfig_exports as agentconfig, agents_exports as agents, assistant_exports as assistant, authenticatedFetch, buildDocNameMap, buildFactsContextTool, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts_exports as contacts, conversations_exports as conversations, countCitations, createAuthenticatedClient, createDocumentWaiter, device_flow_exports as deviceFlow, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, facts_exports as facts, files_exports as files, filterSkills, formatAgentStepLabel, formatFileSize, formatItemLabel, formatStreamSummary, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, generateNewWorkspaceKey, getErrorCode, getErrorMessage, getRawWorkspaceKey, health_exports as health, identityErrorCode, identity_exports as identityVerification, listen_exports as listen, mail_exports as mail, mail_node_exports as mailNode, parseSSEEvents, parseSlashCommand, parseSlashTokenInProgress, performPasswordLogin, performSigningKeyLogin, performSsoDeviceFlowLogin, profile_exports as profile, projects_exports as projects, requireData, requireOk, resolveAuth, resolveCitations, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, sessions_exports as sessions, settings_exports as settings, startDmListener, streamSSE, stripCitationMarkdown, summarizeCitations, tags_exports as tags, work_exports as work, workflow_steps_exports as workflowSteps, workflows_exports as workflows, workspaces_exports as workspaces };
|
|
8896
9703
|
//# sourceMappingURL=index.js.map
|
|
8897
9704
|
//# sourceMappingURL=index.js.map
|