@camstack/addon-export-alexa 1.2.194 → 1.2.195

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.
@@ -6050,7 +6050,7 @@ var ZodIssueCode = {
6050
6050
  var ZodFirstPartyTypeKind;
6051
6051
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6052
6052
  //#endregion
6053
- //#region ../types/dist/sleep-Bn346wCJ.mjs
6053
+ //#region ../types/dist/sleep-D0roI_CZ.mjs
6054
6054
  /**
6055
6055
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6056
6056
  * window to float samples (D455).
@@ -16160,6 +16160,10 @@ Object.freeze({
16160
16160
  "path": "lastEvent.eventType",
16161
16161
  "valueType": "string"
16162
16162
  },
16163
+ {
16164
+ "path": "lastEvent.sourceId",
16165
+ "valueType": "string"
16166
+ },
16163
16167
  {
16164
16168
  "path": "lastEvent.timestamp",
16165
16169
  "valueType": "number"
@@ -19180,6 +19184,7 @@ function buildAddonRouteProvider(id, routes) {
19180
19184
  query: input.query,
19181
19185
  body: input.body,
19182
19186
  headers: input.headers,
19187
+ ...match.route.perInstance === true && input.instanceId !== void 0 ? { instanceId: input.instanceId } : {},
19183
19188
  ...input.user ? { user: input.user } : {},
19184
19189
  ...input.scopedToken !== void 0 ? { scopedToken: input.scopedToken } : {}
19185
19190
  };
@@ -19247,6 +19252,18 @@ function buildCapturingReply(envelope) {
19247
19252
  };
19248
19253
  return wrapper;
19249
19254
  }
19255
+ /** The instance a link was made for, with the default one spelled as the addon id. */
19256
+ function oauthLinkInstanceId(link, addonId) {
19257
+ return link.instanceId ?? addonId;
19258
+ }
19259
+ /**
19260
+ * True when a verified link may be used on a request addressed to
19261
+ * `requestInstanceId` (`AddonHttpRequest.instanceId`, absent on a route that
19262
+ * is not per-instance, which is the default instance).
19263
+ */
19264
+ function oauthLinkServesInstance(link, requestInstanceId, addonId) {
19265
+ return oauthLinkInstanceId(link, addonId) === (requestInstanceId ?? addonId);
19266
+ }
19250
19267
  /**
19251
19268
  * notification-output — canonical, capability-gated notification delivery.
19252
19269
  *
@@ -44035,6 +44052,41 @@ function macroOnly(macro) {
44035
44052
  };
44036
44053
  }
44037
44054
  }
44055
+ var EventVocabularyKindSchema = _enum([
44056
+ "press",
44057
+ "long-press",
44058
+ "long-press-start",
44059
+ "release",
44060
+ "repeat",
44061
+ "double-press",
44062
+ "other"
44063
+ ]);
44064
+ /** The part of the device an event comes from: a button, a channel. */
44065
+ var EventVocabularySourceSchema = object({
44066
+ id: string().min(1),
44067
+ label: string().min(1)
44068
+ });
44069
+ /** One scalar field of an event's `data`, by dotted path. */
44070
+ var EventVocabularyFieldSchema = object({
44071
+ path: string().min(1),
44072
+ kind: _enum([
44073
+ "string",
44074
+ "number",
44075
+ "boolean",
44076
+ "enum"
44077
+ ]),
44078
+ enumValues: array(string()).optional(),
44079
+ label: string().min(1).optional()
44080
+ });
44081
+ var EventVocabularyEntrySchema = object({
44082
+ /** The native token, verbatim. */
44083
+ id: string().min(1),
44084
+ source: EventVocabularySourceSchema.optional(),
44085
+ label: string().min(1),
44086
+ description: string().optional(),
44087
+ kind: EventVocabularyKindSchema.optional(),
44088
+ payload: array(EventVocabularyFieldSchema).optional()
44089
+ });
44038
44090
  Math.PI / 180;
44039
44091
  /**
44040
44092
  * WHEN something happens, as data (D983) — the one time vocabulary of the
@@ -44242,6 +44294,33 @@ var ScheduleLeafSchema = object({
44242
44294
  /** @deprecated legacy cron — new schedules use `at`. */
44243
44295
  cron: string().min(1).max(120).optional()
44244
44296
  }).refine((leaf) => leaf.at === void 0 !== (leaf.cron === void 0), { message: "a schedule names exactly one of `at` (a time spec) and `cron` (legacy)" }).refine((leaf) => leaf.days === void 0 || leaf.at !== void 0, { message: "`days` goes with `at`; a cron expression carries its own days" });
44297
+ /**
44298
+ * One payload predicate of a `device-fired` row: the value at `path` inside
44299
+ * the fire's `data` (dotted) equals `equals`. Compared strictly, no coercion.
44300
+ */
44301
+ var DeviceFiredMatchSchema = object({
44302
+ path: string().min(1).max(120),
44303
+ equals: union([
44304
+ string(),
44305
+ number$1(),
44306
+ boolean()
44307
+ ])
44308
+ });
44309
+ /**
44310
+ * "fires": one device of the `event-emitter` capability reported an event
44311
+ * (D1045). Every list is an OR, the lists together an AND; an absent list does
44312
+ * not narrow. `eventIds` are the device's own tokens, `sourceIds` the parts of
44313
+ * the device (a button), `kinds` the shared press kinds of its vocabulary.
44314
+ */
44315
+ var DeviceFiredLeafSchema = object({
44316
+ kind: literal("device-fired"),
44317
+ ...eventLeafId,
44318
+ deviceId: number$1().int().nonnegative(),
44319
+ eventIds: array(string().min(1)).min(1).max(64).optional(),
44320
+ sourceIds: array(string().min(1)).min(1).max(64).optional(),
44321
+ kinds: array(EventVocabularyKindSchema).min(1).optional(),
44322
+ match: array(DeviceFiredMatchSchema).min(1).max(8).optional()
44323
+ });
44245
44324
  var ManualLeafSchema = object({
44246
44325
  kind: literal("manual"),
44247
44326
  ...eventLeafId
@@ -44383,6 +44462,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
44383
44462
  }),
44384
44463
  DeviceBecomesLeafSchema,
44385
44464
  DeviceEventLeafSchema,
44465
+ DeviceFiredLeafSchema,
44386
44466
  ScheduleLeafSchema,
44387
44467
  ManualLeafSchema,
44388
44468
  IntervalLeafSchema,
@@ -44397,6 +44477,7 @@ var AutomationWhenSchema = lazy(() => discriminatedUnion("kind", [
44397
44477
  var EVENT_KINDS = new Set([
44398
44478
  "device-becomes",
44399
44479
  "device-event",
44480
+ "device-fired",
44400
44481
  "schedule",
44401
44482
  "manual",
44402
44483
  "interval",
@@ -44477,6 +44558,7 @@ function hasEmptyContainer(node) {
44477
44558
  var LEAF_WORDS = {
44478
44559
  "device-becomes": "a device value that becomes",
44479
44560
  "device-event": "a device event",
44561
+ "device-fired": "a device firing an event",
44480
44562
  schedule: "a schedule",
44481
44563
  manual: "a manual run",
44482
44564
  interval: "an interval",
@@ -44742,9 +44824,12 @@ function convertLegacyWhen(half) {
44742
44824
  * every caller — automations, Actions, and the notification centre, which runs
44743
44825
  * only Actions (planning#473).
44744
44826
  */
44827
+ /** The longest one `wait` step lasts. It is cut by a restart of the run and does not survive a hub restart. */
44828
+ var WAIT_MAX_SECONDS = 3600;
44829
+ var WAIT_TOO_LONG = `a wait is at most one hour (${WAIT_MAX_SECONDS} s)`;
44745
44830
  var AutomationWaitStepSchema = object({
44746
44831
  kind: literal("wait"),
44747
- seconds: number$1().min(0).max(300)
44832
+ seconds: number$1().min(0).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG)
44748
44833
  });
44749
44834
  /** The legacy `deviceId` of a cap step: still READ, never written (D983). */
44750
44835
  var LegacyStepDeviceSchema = union([
@@ -44814,39 +44899,227 @@ var elseNeedsIf = {
44814
44899
  path: ["else"]
44815
44900
  };
44816
44901
  var GuardedWaitStepSchema = AutomationWaitStepSchema.extend(stepGuardShape).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
44817
- var GuardedCapStepSchema = AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
44818
- message: "a cap step needs a target",
44819
- path: ["target"]
44820
- }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
44821
- message: "a domain target needs the vocabulary action it applies to (actionId)",
44822
- path: ["actionId"]
44823
- }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
44824
44902
  /**
44825
44903
  * A step of a STANDALONE list (an action, a scheduler point, a preset): the
44826
44904
  * same two step kinds an automation runs, minus a guard that reads the
44827
44905
  * automation's trigger, which such a list does not have.
44828
44906
  */
44829
- var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, GuardedCapStepSchema]).superRefine((step, ctx) => {
44907
+ var ActionStepSchema = discriminatedUnion("kind", [GuardedWaitStepSchema, AutomationCapStepBaseSchema.extend(stepGuardShape).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
44908
+ message: "a cap step needs a target",
44909
+ path: ["target"]
44910
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
44911
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
44912
+ path: ["actionId"]
44913
+ }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf)]).superRefine((step, ctx) => {
44830
44914
  if (step.if !== void 0 && hasTriggeredByLeaves(step.if)) ctx.addIssue({
44831
44915
  code: "custom",
44832
44916
  message: TRIGGERED_BY_NEEDS_AUTOMATION,
44833
44917
  path: ["if"]
44834
44918
  });
44835
44919
  });
44920
+ /**
44921
+ * Flow control of an AUTOMATION's list (#500). A standalone list (an action, a
44922
+ * scheduler point, a preset) stays `wait` and `cap`: it has no run of its own
44923
+ * to end and no variable bag to write.
44924
+ */
44925
+ var continueOnErrorShape = {
44926
+ /** A failure of this step is traced `failed-continued` and the next step runs. */
44927
+ continueOnError: literal(true).optional() };
44928
+ /** An automation's cap step: the shared guarded cap step, plus `continueOnError`. */
44929
+ var AutomationGuardedCapStepSchema = AutomationCapStepBaseSchema.extend({
44930
+ ...stepGuardShape,
44931
+ ...continueOnErrorShape
44932
+ }).refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
44933
+ message: "a cap step needs a target",
44934
+ path: ["target"]
44935
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
44936
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
44937
+ path: ["actionId"]
44938
+ }).refine((step) => step.else === void 0 || step.if !== void 0, elseNeedsIf);
44939
+ /** End the run here, on purpose. `reason` may carry `{{vars.x}}` slots. */
44940
+ var AutomationStopStepSchema = object({
44941
+ kind: literal("stop"),
44942
+ reason: string().min(1, "a stop needs a reason: it is what the run trace shows").max(200),
44943
+ /** `ok`: the run ends as a success. `failed`: it ends as a failure, with the reason. */
44944
+ outcome: _enum(["ok", "failed"]),
44945
+ /** Stop only when this reads true; false or unknown does not stop. */
44946
+ if: AutomationWhenSchema.optional()
44947
+ });
44948
+ var SET_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]{0,39}$/;
44949
+ /** Names the run itself writes and reads (`leaf` is what `triggered-by` judges): a step may not overwrite them. */
44950
+ var RESERVED_RUN_VARS = [
44951
+ "kind",
44952
+ "leaf",
44953
+ "at"
44954
+ ];
44955
+ /**
44956
+ * Write variables into the run's bag, for the steps after it. SUBSTITUTION
44957
+ * only, never evaluation: a text value may carry `{{vars.x}}` slots.
44958
+ */
44959
+ var AutomationSetStepSchema = object({
44960
+ kind: literal("set"),
44961
+ vars: record(string(), union([
44962
+ string().max(500),
44963
+ number$1(),
44964
+ boolean()
44965
+ ])).refine((vars) => Object.keys(vars).every((name) => SET_VAR_NAME_RE.test(name)), { message: "a variable name is letters, digits and _, not starting with a digit (max 40)" }).refine((vars) => Object.keys(vars).length >= 1, { message: "set needs at least one variable" }).refine((vars) => Object.keys(vars).length <= 20, { message: `set holds at most 20 variables` }).refine((vars) => Object.keys(vars).every((name) => !RESERVED_RUN_VARS.includes(name)), { message: `the names ${RESERVED_RUN_VARS.join(", ")} belong to the run and cannot be set` }),
44966
+ /** Set only when this reads true; false or unknown leaves the bag as it is. */
44967
+ if: AutomationWhenSchema.optional()
44968
+ });
44969
+ var AutomationRunActionStepSchema = object({
44970
+ kind: literal("action"),
44971
+ /** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
44972
+ actionId: string().min(1),
44973
+ /** Values for the action's declared variables; the others take their default. */
44974
+ variables: record(string(), union([
44975
+ string(),
44976
+ number$1(),
44977
+ boolean()
44978
+ ])).optional(),
44979
+ ...continueOnErrorShape
44980
+ });
44981
+ /**
44982
+ * A step INSIDE a branch of a `choose`: a flow step with no condition of its
44983
+ * own (the branch is the condition) and no block inside it. Strict, so an `if`
44984
+ * written on such a step is refused rather than dropped.
44985
+ */
44986
+ /** The longest a `wait-until` may wait: six hours. */
44987
+ var WAIT_UNTIL_TIMEOUT_MAX_S = 21600;
44988
+ /**
44989
+ * Pause the run until a condition is true (#500). The timeout is mandatory: a
44990
+ * run never waits without an end. `onTimeout` says what a wait that ran out
44991
+ * does: `continue` goes on to the next step, `stop` ends the run as a failure.
44992
+ * A condition that cannot be read is not "true": the wait goes on (D49).
44993
+ */
44994
+ var AutomationWaitUntilStepSchema = object({
44995
+ kind: literal("wait-until"),
44996
+ when: AutomationWhenSchema,
44997
+ timeoutS: number$1().int().min(1, "a wait needs a timeout of at least one second").max(WAIT_UNTIL_TIMEOUT_MAX_S, `a wait for a condition is at most six hours (${WAIT_UNTIL_TIMEOUT_MAX_S} s)`),
44998
+ onTimeout: _enum(["continue", "stop"])
44999
+ }).strict();
45000
+ /** The step kinds that hold steps of their own, or pause on a condition: they nest two levels at most. */
45001
+ var BLOCK_STEP_KINDS = [
45002
+ "choose",
45003
+ "repeat",
45004
+ "parallel",
45005
+ "wait-until"
45006
+ ];
45007
+ var NEST_TOO_DEEP = `steps nest two levels at most: a step inside a nested choose or repeat can be a plain step only`;
45008
+ function kindOf(input) {
45009
+ return typeof input === "object" && input !== null ? Reflect.get(input, "kind") : void 0;
45010
+ }
45011
+ /** Where the nesting ends, a block step is refused in words rather than as an unknown kind. */
45012
+ function nestTooDeep(issue) {
45013
+ const kind = kindOf(issue.input);
45014
+ return typeof kind === "string" && BLOCK_STEP_KINDS.includes(kind) ? NEST_TOO_DEEP : void 0;
45015
+ }
45016
+ var plainStepSchemas = [
45017
+ AutomationWaitStepSchema.strict(),
45018
+ AutomationCapStepBaseSchema.extend(continueOnErrorShape).strict().refine((step) => step.target !== void 0 || step.deviceId !== void 0, {
45019
+ message: "a cap step needs a target",
45020
+ path: ["target"]
45021
+ }).refine((step) => step.target?.kind !== "domain" || step.actionId !== void 0, {
45022
+ message: "a domain target needs the vocabulary action it applies to (actionId)",
45023
+ path: ["actionId"]
45024
+ }),
45025
+ AutomationStopStepSchema.omit({ if: true }).strict(),
45026
+ AutomationSetStepSchema.omit({ if: true }).strict(),
45027
+ AutomationRunActionStepSchema.strict()
45028
+ ];
45029
+ /**
45030
+ * A plain step: a flow step with no condition of its own and no step inside
45031
+ * it. The second (last) level of nesting holds these only.
45032
+ */
45033
+ var AutomationBranchStepSchema = discriminatedUnion("kind", plainStepSchemas, { error: nestTooDeep });
45034
+ /** A step that can run beside others: it writes no variable and does not end the run. */
45035
+ var AutomationParallelMemberSchema = AutomationBranchStepSchema.refine((step) => step.kind === "cap" || step.kind === "action" || step.kind === "wait", "a parallel holds device commands, actions and waits only: a set or a stop beside other steps has no order");
45036
+ /**
45037
+ * Several steps at once (#500): all are started together and all are awaited.
45038
+ * A failure fails the run once the others finished, as in a sequence; a member
45039
+ * marked "continue if this fails" does not.
45040
+ */
45041
+ var AutomationParallelStepSchema = object({
45042
+ kind: literal("parallel"),
45043
+ steps: array(AutomationParallelMemberSchema).min(2, "a parallel needs at least two steps").max(5, `a parallel takes at most 5 steps`)
45044
+ }).strict();
45045
+ var REPEAT_NEEDS_MAX = "a repeat on a condition needs a maximum number of iterations";
45046
+ /** A loop on a condition: the bound is mandatory, so a run never loops without an end. */
45047
+ var repeatConditionShape = {
45048
+ when: AutomationWhenSchema,
45049
+ maxIterations: number$1({ error: REPEAT_NEEDS_MAX }).int().min(1, REPEAT_NEEDS_MAX).max(50, `a repeat on a condition runs at most 50 times`),
45050
+ /** A pause between two iterations, never after the last. */
45051
+ waitS: number$1().int().min(1).max(WAIT_MAX_SECONDS, WAIT_TOO_LONG).optional()
45052
+ };
45053
+ /** What decides how many times a `repeat` runs. */
45054
+ var AutomationRepeatLoopSchema = discriminatedUnion("by", [
45055
+ object({
45056
+ by: literal("count"),
45057
+ count: number$1().int().min(1).max(20, `a repeat runs at most 20 times`)
45058
+ }).strict(),
45059
+ object({
45060
+ by: literal("while"),
45061
+ ...repeatConditionShape
45062
+ }).strict(),
45063
+ object({
45064
+ by: literal("until"),
45065
+ ...repeatConditionShape
45066
+ }).strict(),
45067
+ object({
45068
+ by: literal("forEach"),
45069
+ target: object({
45070
+ kind: literal("devices"),
45071
+ ids: array(number$1().int()).min(1, "a repeat over devices needs at least one device").max(50, `a repeat over devices takes at most 50 devices`)
45072
+ }).strict()
45073
+ }).strict()
45074
+ ]);
45075
+ /**
45076
+ * The same steps several times (#500). Every form is bounded at save, so a
45077
+ * run cannot loop without an end. A failure or a `stop` in the steps ends the
45078
+ * loop and the run, as in a sequence.
45079
+ */
45080
+ function repeatSchemaOf(step) {
45081
+ return object({
45082
+ kind: literal("repeat"),
45083
+ loop: AutomationRepeatLoopSchema,
45084
+ steps: array(step).min(1, "a repeat needs at least one step").max(10, `a repeat takes at most 10 steps`)
45085
+ }).strict();
45086
+ }
45087
+ /**
45088
+ * One step, several ways (#500): the branches are read in order and the FIRST
45089
+ * whose condition is true runs; `else` runs when every branch is false. A
45090
+ * branch that cannot be read ends the choice: nothing runs, not the branches
45091
+ * after it and not the else (D49). The #472 `if` / `else` of a wait or cap
45092
+ * step is the one-branch case and stays as it is stored.
45093
+ */
45094
+ function chooseSchemaOf(step) {
45095
+ const steps = array(step).max(10);
45096
+ return object({
45097
+ kind: literal("choose"),
45098
+ branches: array(object({
45099
+ if: AutomationWhenSchema,
45100
+ steps: steps.min(1, "a branch needs at least one step")
45101
+ })).min(1, "a choose needs at least one branch").max(6, `a choose takes at most 6 branches`),
45102
+ else: steps.optional()
45103
+ });
45104
+ }
45105
+ var AutomationBodyStepSchema = discriminatedUnion("kind", [
45106
+ ...plainStepSchemas,
45107
+ AutomationWaitUntilStepSchema,
45108
+ AutomationParallelStepSchema,
45109
+ chooseSchemaOf(AutomationBranchStepSchema),
45110
+ repeatSchemaOf(AutomationBranchStepSchema)
45111
+ ]);
45112
+ var AutomationRepeatStepSchema = repeatSchemaOf(AutomationBodyStepSchema);
44836
45113
  var AutomationActionSchema = discriminatedUnion("kind", [
44837
45114
  GuardedWaitStepSchema,
44838
- GuardedCapStepSchema,
44839
- object({
44840
- kind: literal("action"),
44841
- /** An entry of the `actions` surface (`internal:<uuid>` or `<addonId>:<localId>`). */
44842
- actionId: string().min(1),
44843
- /** Values for the action's declared variables; the others take their default. */
44844
- variables: record(string(), union([
44845
- string(),
44846
- number$1(),
44847
- boolean()
44848
- ])).optional()
44849
- }),
45115
+ AutomationGuardedCapStepSchema,
45116
+ AutomationStopStepSchema,
45117
+ AutomationSetStepSchema,
45118
+ chooseSchemaOf(AutomationBodyStepSchema),
45119
+ AutomationWaitUntilStepSchema,
45120
+ AutomationParallelStepSchema,
45121
+ AutomationRepeatStepSchema,
45122
+ AutomationRunActionStepSchema,
44850
45123
  object({
44851
45124
  kind: literal("code"),
44852
45125
  /** Compiled into the automation's OWN block by esbuild — not a third
@@ -44909,11 +45182,6 @@ function convertLegacyRecipe(legacy) {
44909
45182
  ...rest
44910
45183
  };
44911
45184
  }
44912
- /**
44913
- * Where recipes are PARSED (the core-blocks cap, the MCP tool, the literal a
44914
- * saved block carries): the new shape as it is, or the old shape converted to
44915
- * it. The output type is always the new one.
44916
- */
44917
45185
  var AutomationRecipeSchema = union([CurrentAutomationRecipeSchema, LegacyAutomationRecipeSchema.transform(convertLegacyRecipe)]);
44918
45186
  var DETECTION_DESCRIPTIONS = {
44919
45187
  deviceId: "the camera that saw it",
@@ -44934,6 +45202,16 @@ var BECOMES_DESCRIPTIONS = {
44934
45202
  from: "the value before the change, empty when it is not known",
44935
45203
  to: "the value it changed to"
44936
45204
  };
45205
+ /**
45206
+ * A fire's payload is offered too, as `data.<path>` (`{{vars.data.channel}}`):
45207
+ * those names depend on the device, so they are not in this list.
45208
+ */
45209
+ var FIRED_DESCRIPTIONS = {
45210
+ deviceId: "the device that fired",
45211
+ eventType: "the event, as the device names it",
45212
+ sourceId: "the part of the device that fired (a button), empty when it names none",
45213
+ eventKind: "the kind of press (press, long-press …), empty when the device declares none"
45214
+ };
44937
45215
  function describe$1(descriptions) {
44938
45216
  return Object.entries(descriptions).map(([name, description]) => ({
44939
45217
  name,
@@ -44942,12 +45220,50 @@ function describe$1(descriptions) {
44942
45220
  }
44943
45221
  describe$1(DETECTION_DESCRIPTIONS);
44944
45222
  describe$1(STATIONARY_DESCRIPTIONS);
45223
+ describe$1(FIRED_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
45224
+ ...v,
45225
+ hintKey: "firedDeviceId"
45226
+ } : v);
44945
45227
  describe$1(BECOMES_DESCRIPTIONS).map((v) => v.name === "deviceId" ? {
44946
45228
  ...v,
44947
45229
  hintKey: "becomesDeviceId"
44948
45230
  } : v);
44949
45231
  new Set(Object.values(COCO_TO_MACRO.mapping));
44950
45232
  /**
45233
+ * Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
45234
+ * device. Carries the device's EXACT declared event vocabulary verbatim
45235
+ * (NO normalization). Two shapes:
45236
+ * - structured source (HA `event.*` entity) → `vocabulary` is the fixed
45237
+ * declared set (e.g. press_short, press_long, …).
45238
+ * - generic/legacy source (HA bus events, e.g. zha_event) → `vocabulary`
45239
+ * is [] (open) and `lastEvent.data` carries the complex payload.
45240
+ * `vocabulary` (D1044) names each event for a person and types it for a
45241
+ * rule; `eventTypes` is its list of native tokens, kept for older readers.
45242
+ * A fire names the part of the device it came from in `sourceId` when the
45243
+ * vocabulary declares sources (a remote's buttons).
45244
+ * `seq` is monotonic so two identical events still produce distinct slice writes.
45245
+ */
45246
+ var EventFireSchema = object({
45247
+ deviceId: number$1(),
45248
+ eventType: string(),
45249
+ sourceId: string().optional(),
45250
+ data: record(string(), unknown()).nullable(),
45251
+ timestamp: number$1().meta(readingMeta("none")),
45252
+ seq: number$1().meta(readingMeta("count"))
45253
+ });
45254
+ var EventEmitterStatusSchema = object({
45255
+ eventTypes: array(string()),
45256
+ /**
45257
+ * Required of a provider by the type. A status written before the field
45258
+ * existed still parses, as an empty vocabulary: read it through
45259
+ * `readEventVocabulary`, which then answers with the plain tokens.
45260
+ */
45261
+ vocabulary: array(EventVocabularyEntrySchema).default([]),
45262
+ lastEvent: EventFireSchema.nullable(),
45263
+ eventCountSinceStart: number$1().meta(readingMeta("count"))
45264
+ });
45265
+ DeviceType.EventEmitter;
45266
+ /**
44951
45267
  * Schedulers (D983) — an entity that performs actions over the day.
44952
45268
  *
44953
45269
  * A scheduler has profiles; a profile has weekdays and a timeline of POINTS.
@@ -44998,12 +45314,16 @@ var HoldOverrideSchema = discriminatedUnion("mode", [object({ mode: literal("res
44998
45314
  })]);
44999
45315
  /** A missed edge up to this late still runs. */
45000
45316
  var DEFAULT_MAX_LATE_MS = 10 * 6e4;
45317
+ var SchedulerStepSchema = ActionStepSchema.refine((step) => step.kind !== "wait" || step.seconds <= 300, {
45318
+ message: `a scheduler point waits at most five minutes (300 s); put a longer wait in an action`,
45319
+ path: ["seconds"]
45320
+ });
45001
45321
  var SchedulerPointSchema = object({
45002
45322
  id: string().min(1).max(64),
45003
45323
  at: SchedulerTimeSpecSchema,
45004
45324
  mode: SchedulerPointModeSchema,
45005
45325
  /** The actions of an `edge` or `hold`; a `release` has none. */
45006
- steps: array(ActionStepSchema).max(20).default([]),
45326
+ steps: array(SchedulerStepSchema).max(20).default([]),
45007
45327
  /** Checked when the point runs (an edge) or is applied (a hold). */
45008
45328
  conditions: SchedulerStateTreeSchema.optional(),
45009
45329
  /** Hold only; absent means `respect`. */
@@ -45201,6 +45521,7 @@ var AutomationConditionTraceNodeSchema = object({
45201
45521
  "triggered-by",
45202
45522
  "device-becomes",
45203
45523
  "device-event",
45524
+ "device-fired",
45204
45525
  "schedule",
45205
45526
  "interval",
45206
45527
  "manual",
@@ -45271,18 +45592,46 @@ var StepTraceBaseSchema = object({
45271
45592
  ]).optional(),
45272
45593
  /** Why the condition read what it read, in the evaluator's own words. */
45273
45594
  conditionReason: string().optional(),
45274
- /** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. `skipped`: its `if` was false (or unknown) and nothing ran in its place. */
45595
+ /** `empty`: the target resolved to no device, so nothing was done — never silently `ok`. `skipped`: its `if` was false (or unknown) and nothing ran in its place. `failed-continued`: it failed and was marked to be passed over (#500). */
45275
45596
  outcome: _enum([
45276
45597
  "ok",
45277
45598
  "error",
45278
45599
  "not-run",
45279
45600
  "empty",
45280
- "skipped"
45601
+ "skipped",
45602
+ "failed-continued",
45603
+ "timed-out"
45281
45604
  ]),
45282
45605
  message: string().optional()
45283
45606
  });
45607
+ /** What a block step adds to its row: which list ran, what each branch read, how many rounds. */
45608
+ var blockTraceShape = {
45609
+ /** A `choose` step (#500): the list that ran, `branches.<n>` or `else`. Absent when none did. */
45610
+ branch: string().optional(),
45611
+ /** A `choose` step: what each branch read, in order, up to the one that decided. */
45612
+ branchChecks: array(object({
45613
+ condition: _enum([
45614
+ "true",
45615
+ "false",
45616
+ "unknown"
45617
+ ]),
45618
+ conditionReason: string().optional()
45619
+ })).optional(),
45620
+ /** A `repeat` step (#500): how many times its steps ran. */
45621
+ iterations: number$1().int().optional()
45622
+ };
45623
+ /** A step one level down: it may be a block step itself, whose own steps are plain rows (the nesting ends there). */
45624
+ var NestedStepTraceSchema = StepTraceBaseSchema.extend({
45625
+ ...blockTraceShape,
45626
+ steps: array(StepTraceBaseSchema).optional()
45627
+ });
45284
45628
  /** A step trace; the `else` steps that ran are one level of the same shape (the nesting is bounded at one). */
45285
- var AutomationStepTraceSchema = StepTraceBaseSchema.extend({ else: array(StepTraceBaseSchema).optional() });
45629
+ var AutomationStepTraceSchema = StepTraceBaseSchema.extend({
45630
+ else: array(StepTraceBaseSchema).optional(),
45631
+ ...blockTraceShape,
45632
+ /** A `choose` step: the steps of the list that ran. A `parallel`: its members. A `repeat`: the LAST iteration. */
45633
+ steps: array(NestedStepTraceSchema).optional()
45634
+ });
45286
45635
  var AutomationRunTraceSchema = object({
45287
45636
  runId: string().min(1),
45288
45637
  startedAt: number$1(),
@@ -45772,7 +46121,9 @@ var AddonHttpRouteSchema = object({
45772
46121
  ]).optional(),
45773
46122
  description: string().optional(),
45774
46123
  /** The hub limits this route per client address before the handler runs. */
45775
- rateLimit: _enum(["auth"]).optional()
46124
+ rateLimit: _enum(["auth"]).optional(),
46125
+ /** Served once per integration instance; the handler reads `instanceId`. */
46126
+ perInstance: boolean().optional()
45776
46127
  });
45777
46128
  /**
45778
46129
  * Cross-process route invocation envelope. The hub captures the
@@ -45789,6 +46140,8 @@ var InvokeRequestSchema = object({
45789
46140
  query: record(string(), string()),
45790
46141
  body: unknown(),
45791
46142
  headers: record(string(), string()),
46143
+ /** The instance the hub resolved for a `perInstance` route. */
46144
+ instanceId: string().optional(),
45792
46145
  user: object({
45793
46146
  id: string(),
45794
46147
  username: string(),
@@ -55046,29 +55399,6 @@ var EnumSensorStatusSchema = object({
55046
55399
  lastFetchedAt: number$1()
55047
55400
  });
55048
55401
  DeviceType.Sensor;
55049
- /**
55050
- * Generic stateless event emitter. Installed on a `DeviceType.EventEmitter`
55051
- * device. Carries the device's EXACT declared event vocabulary verbatim
55052
- * (NO normalization). Two shapes:
55053
- * - structured source (HA `event.*` entity) → `eventTypes` is the fixed
55054
- * declared vocabulary (e.g. ['press_short','press_long',...]).
55055
- * - generic/legacy source (HA bus events, e.g. zha_event) → `eventTypes`
55056
- * is [] (open) and `lastEvent.data` carries the complex payload.
55057
- * `seq` is monotonic so two identical events still produce distinct slice writes.
55058
- */
55059
- var EventFireSchema = object({
55060
- deviceId: number$1(),
55061
- eventType: string(),
55062
- data: record(string(), unknown()).nullable(),
55063
- timestamp: number$1().meta(readingMeta("none")),
55064
- seq: number$1().meta(readingMeta("count"))
55065
- });
55066
- var EventEmitterStatusSchema = object({
55067
- eventTypes: array(string()),
55068
- lastEvent: EventFireSchema.nullable(),
55069
- eventCountSinceStart: number$1().meta(readingMeta("count"))
55070
- });
55071
- DeviceType.EventEmitter;
55072
55402
  var IdentitySchema = object({
55073
55403
  id: string(),
55074
55404
  name: string(),
@@ -69259,7 +69589,18 @@ var OauthIntegrationDescriptorSchema = object({
69259
69589
  * The value is baked into the authorization code at `/authorize` and travels
69260
69590
  * on the tokens, so editing this field changes FUTURE links only.
69261
69591
  */
69262
- refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional()
69592
+ refreshTokenTtlSec: union([number$1().int().positive(), literal("never")]).optional(),
69593
+ /**
69594
+ * The integration instances an account can be linked to (planning#415),
69595
+ * beside the default one. `/api/oauth2/authorize?instance=<id>` is accepted
69596
+ * only for an id listed here; with no `instance=` the link is made to the
69597
+ * default instance, which is never listed and always accepted — it is the
69598
+ * address third parties already hold. Omit for a single-instance integration.
69599
+ */
69600
+ instances: array(object({
69601
+ id: string(),
69602
+ displayName: string()
69603
+ })).optional()
69263
69604
  });
69264
69605
  var oauthIntegrationCapability = {
69265
69606
  name: "oauth-integration",
@@ -75404,6 +75745,13 @@ var SsoBridgeClaimsSchema = object({
75404
75745
  /** OAuth authorization-code binding — set only on `oauth-code` tokens. */
75405
75746
  redirectUri: string().optional(),
75406
75747
  integrationId: string().optional(),
75748
+ /**
75749
+ * The integration INSTANCE an OAuth link was made for (planning#415). Set on
75750
+ * `oauth-code`, `oauth-access` and `oauth-refresh` tokens of a link made
75751
+ * with `instance=`; absent on a link to the default instance. A cloud relay
75752
+ * reads it off the access token to route; the hub answers from the session.
75753
+ */
75754
+ instanceId: string().optional(),
75407
75755
  /** JWT ID — unique per issued code; consumed-set enforces single-use. */
75408
75756
  jti: string().optional(),
75409
75757
  /** PKCE S256 challenge — set only on `oauth-code` tokens issued to a public
@@ -77492,6 +77840,8 @@ var OauthSessionSummarySchema = object({
77492
77840
  userId: string(),
77493
77841
  username: string(),
77494
77842
  integrationId: string(),
77843
+ /** The instance the link was made for; `null` = the default instance. */
77844
+ instanceId: string().nullable().optional(),
77495
77845
  scopes: array(TokenScopeSchema),
77496
77846
  createdAt: number$1(),
77497
77847
  lastUsedAt: number$1(),
@@ -77591,6 +77941,9 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
77591
77941
  access: "view"
77592
77942
  }), method(object({
77593
77943
  integrationId: string(),
77944
+ /** The integration instance the link is for. Omit for the default
77945
+ * instance — never pass the addon id to mean it. */
77946
+ instanceId: string().optional(),
77594
77947
  userId: string(),
77595
77948
  username: string(),
77596
77949
  scopes: array(TokenScopeSchema),
@@ -77629,7 +77982,13 @@ method(_void(), array(UserSummarySchema), { auth: "admin" }), method(_void(), ob
77629
77982
  }), method(object({ token: string() }), object({
77630
77983
  userId: string(),
77631
77984
  username: string(),
77632
- scopes: array(TokenScopeSchema)
77985
+ scopes: array(TokenScopeSchema),
77986
+ /** The instance the link was made for, read from the SESSION.
77987
+ * Absent = the default instance. `oauthLinkServesInstance` is the
77988
+ * helper a per-instance route calls to compare it with the instance
77989
+ * of its path; no route declares `perInstance` yet (the Alexa
77990
+ * per-instance route, T3, is the first consumer). */
77991
+ instanceId: string().optional()
77633
77992
  }).nullable(), { access: "view" }), method(object({ userId: string() }), array(ExternalIdentitySchema), { auth: "admin" }), method(ExternalIdentityKeySchema, object({
77634
77993
  userId: string(),
77635
77994
  issuer: string()
@@ -104645,6 +105004,21 @@ async function rotateBrokerCredential(fetchImpl, brokerUrl, credential) {
104645
105004
  async function revokeBrokerCredential(fetchImpl, brokerUrl, credential) {
104646
105005
  await call(fetchImpl, brokerUrl, "/broker/revoke", { bearer: credential }, unknown());
104647
105006
  }
105007
+ function judgeTokenInstance(token, skill) {
105008
+ if (token.instanceId !== void 0) return oauthLinkServesInstance({ instanceId: token.instanceId }, skill.id, "export-alexa") ? { kind: "serves" } : {
105009
+ kind: "refused",
105010
+ reason: "token-instance-mismatch"
105011
+ };
105012
+ if (skill.id === "export-alexa") return { kind: "serves" };
105013
+ return skill.hasLinkedUser(token.userId) ? { kind: "serves" } : {
105014
+ kind: "refused",
105015
+ reason: "token-instance-unstated"
105016
+ };
105017
+ }
105018
+ /** The operator-facing sentence for a refusal, sent back to the Lambda and logged. */
105019
+ function describeTokenInstanceRefusal(reason) {
105020
+ return reason === "token-instance-mismatch" ? "the account was linked to another skill instance of this hub" : "the account link names no skill instance and this skill has not linked the account; update the skill Lambda and link again";
105021
+ }
104648
105022
  //#endregion
104649
105023
  //#region src/handlers/lwa-tokens-callback.ts
104650
105024
  /**
@@ -104669,13 +105043,33 @@ async function revokeBrokerCredential(fetchImpl, brokerUrl, credential) {
104669
105043
  var OauthVerifiedResultSchema$1 = object({
104670
105044
  userId: string(),
104671
105045
  username: string(),
104672
- scopes: array(TokenScopeSchema)
105046
+ scopes: array(TokenScopeSchema),
105047
+ /** The instance the link was made for; absent = the default instance (D1047). */
105048
+ instanceId: string().optional()
104673
105049
  }).nullable();
104674
105050
  var LwaTokensCallbackBodySchema = object({
104675
105051
  lwaAccessToken: string().min(1),
104676
105052
  lwaRefreshToken: string().min(1),
104677
105053
  expiresAt: number$1().int().nonnegative()
104678
105054
  });
105055
+ /**
105056
+ * Refuse (403, logged with the reason) a caller whose token was linked to another instance.
105057
+ * True when the reply was sent; the caller must return.
105058
+ */
105059
+ function refusedForInstance(caller, reply, deps, label) {
105060
+ const verdict = deps.judgeInstance(caller);
105061
+ if (verdict.kind === "serves") return false;
105062
+ deps.logger.warn(`${label}: refused — ${verdict.reason}`, { meta: {
105063
+ instanceId: deps.instanceId,
105064
+ tokenInstanceId: caller.instanceId ?? null,
105065
+ userId: caller.userId
105066
+ } });
105067
+ reply.code(403).send({
105068
+ error: verdict.reason,
105069
+ message: describeTokenInstanceRefusal(verdict.reason)
105070
+ });
105071
+ return true;
105072
+ }
104679
105073
  async function handleLwaTokensCallback(request, reply, deps) {
104680
105074
  const parsed = LwaTokensCallbackBodySchema.safeParse(request.body);
104681
105075
  if (!parsed.success) {
@@ -104695,6 +105089,7 @@ async function handleLwaTokensCallback(request, reply, deps) {
104695
105089
  });
104696
105090
  return;
104697
105091
  }
105092
+ if (refusedForInstance(caller, reply, deps, "alexa lwa-tokens-callback")) return;
104698
105093
  const { userId, username } = caller;
104699
105094
  await deps.upsertToken({
104700
105095
  userId,
@@ -104721,10 +105116,14 @@ async function resolveCaller(request, deps) {
104721
105116
  if (!bearer) return null;
104722
105117
  const rawVerified = await deps.ctx.api.userManagement.oauthVerifyAccessToken.query({ token: bearer });
104723
105118
  const verifiedParse = OauthVerifiedResultSchema$1.safeParse(rawVerified);
104724
- if (verifiedParse.success && verifiedParse.data) return {
104725
- userId: verifiedParse.data.userId,
104726
- username: verifiedParse.data.username
104727
- };
105119
+ if (verifiedParse.success && verifiedParse.data) {
105120
+ const { userId, username, instanceId } = verifiedParse.data;
105121
+ return {
105122
+ userId,
105123
+ username,
105124
+ ...instanceId !== void 0 ? { instanceId } : {}
105125
+ };
105126
+ }
104728
105127
  deps.logger.debug("alexa lwa-tokens-callback: bearer present but did not verify");
104729
105128
  return null;
104730
105129
  }
@@ -104797,6 +105196,7 @@ async function handleBrokerLinkCallback(request, reply, deps) {
104797
105196
  });
104798
105197
  return;
104799
105198
  }
105199
+ if (refusedForInstance(caller, reply, deps, "alexa broker-link")) return;
104800
105200
  await deps.upsertToken({
104801
105201
  userId: caller.userId,
104802
105202
  accessToken: body.lwaAccessToken,
@@ -105077,12 +105477,16 @@ async function handleSnapshotFetch(req, reply, deps) {
105077
105477
  * we register via the `addon-routes` capability.
105078
105478
  *
105079
105479
  * Public URLs (assuming the hub is reachable as `https://<hub>`):
105080
- * POST /addon/export-alexa/directive[/:instanceId]
105081
- * POST /addon/export-alexa/oauth/broker-link[/:instanceId] (Lambda → hub, D753 broker link)
105082
- * POST /addon/export-alexa/oauth/lwa-tokens[/:instanceId] (Lambda → hub, legacy pre-D753)
105480
+ * POST /addon/export-alexa[/instances/:instanceId]/directive
105481
+ * POST /addon/export-alexa[/instances/:instanceId]/oauth/broker-link (Lambda → hub, D753)
105482
+ * POST /addon/export-alexa[/instances/:instanceId]/oauth/lwa-tokens (Lambda → hub, pre-D753)
105483
+ *
105484
+ * The three are `perInstance` routes (D1046): the hub reads the instance segment. Without one
105485
+ * the skill is found by its ingress token, then falls back to the default skill
105486
+ * (`instance-routing.ts`). The same three with a trailing `/:instanceId` are the addresses a
105487
+ * Lambda built with `HUB_INSTANCE_ID` before D1046 still calls (planning#422); they stay.
105083
105488
  *
105084
- * The path names the skill; without it the skill is found by its ingress token, then falls back
105085
- * to the first skill (`instance-routing.ts`).
105489
+ * A token linked to another instance is refused (`token-instance.ts`, D1047).
105086
105490
  *
105087
105491
  * OAuth account-linking is handled by the core `/oauth2/*` server
105088
105492
  * (integration=export-alexa). This addon registers an `oauth-integration`
@@ -105091,23 +105495,26 @@ async function handleSnapshotFetch(req, reply, deps) {
105091
105495
  var OauthVerifiedResultSchema = object({
105092
105496
  userId: string(),
105093
105497
  username: string(),
105094
- scopes: array(TokenScopeSchema)
105498
+ scopes: array(TokenScopeSchema),
105499
+ /** The instance the link was made for; absent = the default instance (D1047). */
105500
+ instanceId: string().optional()
105095
105501
  }).nullable();
105096
105502
  /** Header the D753 Lambda sends its broker origin on. */
105097
105503
  var BROKER_HEADER = "x-camstack-broker";
105098
105504
  function buildRoutes(deps) {
105099
105505
  const forSkill = (description, path, handler) => [{
105100
105506
  method: "POST",
105101
- path: `${path}/:instanceId`,
105507
+ path,
105102
105508
  access: "public",
105103
- description: `${description} (one skill, named in the path)`,
105104
- handler: (req, reply) => routeToSkill(req, reply, deps, req.params["instanceId"], handler)
105509
+ perInstance: true,
105510
+ description: `${description} (the skill named by the instance segment; without one, the skill that presents its ingress token, else the default skill)`,
105511
+ handler: (req, reply) => routeToSkill(req, reply, deps, explicitInstance(req.instanceId), handler)
105105
105512
  }, {
105106
105513
  method: "POST",
105107
- path,
105514
+ path: `${path}/:instanceId`,
105108
105515
  access: "public",
105109
- description: `${description} (the skill that presents its ingress token, else the first skill)`,
105110
- handler: (req, reply) => routeToSkill(req, reply, deps, void 0, handler)
105516
+ description: `${description} (one skill, named after the path: the address older Lambdas call)`,
105517
+ handler: (req, reply) => routeToSkill(req, reply, deps, req.params["instanceId"], handler)
105111
105518
  }];
105112
105519
  return [
105113
105520
  ...forSkill("Alexa Smart Home directive ingress (forwarded by the user-owned Lambda)", "/directive", (req, reply, skill) => handleDirective(req, reply, deps, skill)),
@@ -105128,6 +105535,14 @@ function buildRoutes(deps) {
105128
105535
  }
105129
105536
  ];
105130
105537
  }
105538
+ /**
105539
+ * The instance a per-instance request names for the resolver. The default instance (no segment,
105540
+ * or the addon id) names none: its address is shared with a Lambda that finds its skill by the
105541
+ * ingress header (planning#422), so the resolver keeps that lookup for it.
105542
+ */
105543
+ function explicitInstance(instanceId) {
105544
+ return instanceId === void 0 || instanceId === "export-alexa" ? void 0 : instanceId;
105545
+ }
105131
105546
  /** Resolve the request's skill, or answer that there is none. */
105132
105547
  async function routeToSkill(request, reply, deps, pathInstanceId, handler) {
105133
105548
  const skill = deps.resolveSkill({
@@ -105240,6 +105655,19 @@ async function handleDirective(request, reply, deps, skill) {
105240
105655
  reply.code(200).send(preParseErrorEnvelope("INVALID_AUTHORIZATION_CREDENTIAL", verdict.kind === "stale" ? "token was issued for another hub address; re-link the Alexa skill" : `hub has no public endpoint (${verdict.reason.code}); set it on the Network page`));
105241
105656
  return;
105242
105657
  }
105658
+ const instanceVerdict = judgeTokenInstance(verified, skill);
105659
+ if (instanceVerdict.kind === "refused") {
105660
+ deps.logger.warn(`alexa directive: refused — ${instanceVerdict.reason}`, {
105661
+ ...arrival.deviceId !== void 0 ? { tags: { deviceId: arrival.deviceId } } : {},
105662
+ meta: {
105663
+ instanceId: skill.id,
105664
+ tokenInstanceId: verified.instanceId ?? null,
105665
+ userId: verified.userId
105666
+ }
105667
+ });
105668
+ reply.code(200).send(preParseErrorEnvelope("INVALID_AUTHORIZATION_CREDENTIAL", describeTokenInstanceRefusal(instanceVerdict.reason)));
105669
+ return;
105670
+ }
105243
105671
  try {
105244
105672
  assertDeviceScope(verified.scopes);
105245
105673
  } catch {
@@ -106007,25 +106435,6 @@ var ADDON_MIGRATIONS = [
106007
106435
  //#endregion
106008
106436
  //#region src/oauth-integration.ts
106009
106437
  /**
106010
- * The `export-alexa` OAuth client — the descriptor behind
106011
- * `/api/oauth2/authorize?integration=export-alexa`.
106012
- *
106013
- * Shaped deliberately like
106014
- * `packages/addon-provider-homeassistant/src/ha-export/oauth-integration.ts`:
106015
- * one named `OauthIntegrationDescriptor` per integration, in its own module,
106016
- * registered from the addon's `onInitialize` through `oauthIntegrationCapability`
106017
- * ([D101](../../../docs/decisions/adr-0101.md)). The two integrations differ
106018
- * only in the FIELDS below, never in how they are declared — which is the whole
106019
- * claim being made: a third one is configuration, not framework work.
106020
- *
106021
- * Typed rather than inlined, and that is not cosmetic. As an untyped object
106022
- * literal this needed three `as const` assertions to satisfy the schema and was
106023
- * checked for the first time at `/authorize`, i.e. in front of an operator
106024
- * mid-link. The annotation moves that to compile time.
106025
- *
106026
- * @see docs/decisions/adr-0092.md — why `client_secret` is never checked here.
106027
- */
106028
- /**
106029
106438
  * Where Alexa lands after consent — Amazon's three regional account-linking
106030
106439
  * origins, fixed and public. Contrast Home Assistant, whose callback is on the
106031
106440
  * operator's own LAN and needs `allowedPrivateHostPaths`; that difference is
@@ -106061,7 +106470,7 @@ var ALEXA_REDIRECT_PREFIXES = [
106061
106470
  * no `requiresPkce` here. That is a property of the two clients, expressed
106062
106471
  * through the same descriptor field.
106063
106472
  */
106064
- function buildAlexaOauthIntegration(publicOrigin) {
106473
+ function buildAlexaOauthIntegration(publicOrigin, instances = []) {
106065
106474
  return {
106066
106475
  integrationId: "export-alexa",
106067
106476
  displayName: "Alexa Smart Home",
@@ -106098,7 +106507,8 @@ function buildAlexaOauthIntegration(publicOrigin) {
106098
106507
  * "Unlink Amazon account" button does; see `unlinkAlexaAccounts`.
106099
106508
  */
106100
106509
  refreshTokenTtlSec: "never",
106101
- ...publicOrigin ? { hubUrl: publicOrigin } : {}
106510
+ ...publicOrigin ? { hubUrl: publicOrigin } : {},
106511
+ ...instances.length > 0 ? { instances: [...instances] } : {}
106102
106512
  };
106103
106513
  }
106104
106514
  //#endregion
@@ -109841,15 +110251,22 @@ var SkillRuntime = class {
109841
110251
  }
109842
110252
  /** The routes' view of this skill: what a directive or a Lambda callback acts on. */
109843
110253
  routed() {
110254
+ const hasLinkedUser = (userId) => this.view.linkedAccounts.some((a) => a.userId === userId);
109844
110255
  return {
109845
110256
  id: this.instanceId,
109846
110257
  getSettings: () => this.effectiveSettings(),
109847
110258
  directiveDeps: this.directiveDeps(),
110259
+ hasLinkedUser,
109848
110260
  lwaTokensCallbackDeps: {
109849
110261
  ctx: this.ctx,
109850
110262
  logger: this.ctx.logger,
109851
110263
  upsertToken: (input) => this.upsertToken(input),
109852
- recordLinkedAccount: (input) => this.recordLinkedAccount(input)
110264
+ recordLinkedAccount: (input) => this.recordLinkedAccount(input),
110265
+ instanceId: this.instanceId,
110266
+ judgeInstance: (caller) => judgeTokenInstance(caller, {
110267
+ id: this.instanceId,
110268
+ hasLinkedUser
110269
+ })
109853
110270
  },
109854
110271
  onBrokerAdvertised: (raw) => this.rememberAdvertisedBroker(raw)
109855
110272
  };
@@ -111221,7 +111638,7 @@ var ExportAlexaAddon = class extends BaseAddon {
111221
111638
  const oauthIntegrationProvider = { getDescriptor: async () => {
111222
111639
  const endpoint = await this.publicEndpoint();
111223
111640
  if (!endpoint.ok) this.ctx.logger.warn(`export-alexa: linking without a routing claim — ${endpoint.reason.code}: ${endpoint.reason.message}`);
111224
- return buildAlexaOauthIntegration(endpoint.ok ? endpoint.origin : void 0);
111641
+ return buildAlexaOauthIntegration(endpoint.ok ? endpoint.origin : void 0, this.linkableInstances());
111225
111642
  } };
111226
111643
  const reaper = setInterval(() => {
111227
111644
  this.reapDeadEgressHandles();
@@ -111269,6 +111686,13 @@ var ExportAlexaAddon = class extends BaseAddon {
111269
111686
  async onConfigChanged() {
111270
111687
  for (const runtime of this.runtimes.values()) await runtime.applyShapeSwitches();
111271
111688
  }
111689
+ /** The running skills an account may be linked to with `instance=` (all but the default). */
111690
+ linkableInstances() {
111691
+ return [...this.runtimes.values()].filter((r) => !r.isDefault).map((r) => ({
111692
+ id: r.instanceId,
111693
+ displayName: r.skillName
111694
+ }));
111695
+ }
111272
111696
  /** Build and start the runtime of one skill. */
111273
111697
  async startRuntime(instanceId) {
111274
111698
  const runtime = new SkillRuntime(instanceId, this.host());