Constraints

Constraints are short rules (e.g. "avoid jargon", "no more than 200 words") that prompts and collections can reference. The content field is text (not label), capped at 300 chars. Non-versioned, no dedicated visibility endpoint.

Methods

list

client.constraints.list(params?: ListParams): Promise<Page<ConstraintSummary>>

List public constraints
const page = await client.constraints.list({ scope: "public", pageSize: 12 });
return {
  total: page.total,
  items: page.items.map((c) => ({ id: c.id, text: c.text, tags: c.tags })),
};

listAll

client.constraints.listAll(params?: ListParams): AsyncIterable<ConstraintSummary>

Iterate the public constraints feed
const items = [];
for await (const constraint of client.constraints.listAll({ scope: "public", pageSize: 12 })) {
  items.push(constraint.text);
  if (items.length >= 12) break;
}
return items;

get

client.constraints.get(id: string): Promise<Constraint>

Fetch a public constraint detail
const page = await client.constraints.list({ scope: "public", pageSize: 6 });
const first = page.items[0];
if (!first) return { empty: true };
const constraint = await client.constraints.get(first.id);
return {
  id: constraint.id,
  text: constraint.text,
  tags: constraint.tags,
  isPublic: constraint.isPublic,
  isOwner: constraint.isOwner,
};

create

client.constraints.create(input: ConstraintCreateInput): Promise<ConstraintCreateResponse>

⚠️ Writes to your account. Cleans up after itself.
Create then delete
const created = await client.constraints.create({
  text: `docs-demo: stay positive ${Date.now()}`,
  isPublic: false,
  tags: ["demo"],
});
await client.constraints.delete(created.id);
return created;

update

client.constraints.update(id: string, input: ConstraintUpdateInput): Promise<void>

⚠️ Writes to your account. Cleans up after itself.
Create, update, clean up
const created = await client.constraints.create({
  text: `docs-demo: original ${Date.now()}`,
  isPublic: false,
});
await client.constraints.update(created.id, {
  text: `docs-demo: updated ${Date.now()}`,
  tags: ["updated"],
  isPublic: true,
});
const detail = await client.constraints.get(created.id);
await client.constraints.delete(created.id);
return { text: detail.text, tags: detail.tags, isPublic: detail.isPublic };

delete

client.constraints.delete(id: string): Promise<void>

⚠️ Writes to your account. Cleans up after itself.
Create then delete
const created = await client.constraints.create({ text: `docs-demo ${Date.now()}` });
await client.constraints.delete(created.id);
try {
  await client.constraints.get(created.id);
  return { deleted: false };
} catch (err) {
  if (err instanceof PromptyNotFoundError) return { deleted: true };
  throw err;
}

vote

client.constraints.vote(id: string, value: 1 | -1): Promise<void>

⚠️ Writes to your account. Cleans up after itself.
Vote on your own constraint
const created = await client.constraints.create({ text: `docs-demo-vote ${Date.now()}` });
await client.constraints.vote(created.id, 1);
const detail = await client.constraints.get(created.id);
await client.constraints.delete(created.id);
return { upvotes: detail.upvotes, userVote: detail.userVote };

unvote

client.constraints.unvote(id: string): Promise<void>

⚠️ Writes to your account. Cleans up after itself.
Vote, unvote, clean up
const created = await client.constraints.create({ text: `docs-demo-unvote ${Date.now()}` });
await client.constraints.vote(created.id, -1);
await client.constraints.unvote(created.id);
const detail = await client.constraints.get(created.id);
await client.constraints.delete(created.id);
return { downvotes: detail.downvotes, userVote: detail.userVote };

toggleFavorite

client.constraints.toggleFavorite(id: string): Promise<{ favorited: boolean }>

⚠️ Writes to your account. Cleans up after itself.
Toggle on, off, clean up
const created = await client.constraints.create({ text: `docs-demo-fav ${Date.now()}` });
const a = await client.constraints.toggleFavorite(created.id);
const b = await client.constraints.toggleFavorite(created.id);
await client.constraints.delete(created.id);
return { firstToggle: a.favorited, secondToggle: b.favorited };